Newer
Older
smartKitchenFront / src / views / product / deviceList.vue
设备列表
<template>
  <div class="product_container">
    <div class="productData">
      <data-info-item
        :img="require('@/assets/kitchen/设备数.png')"
        :number="statistics.activeDeviceQuantity"
        :title="'累计激活设备数'"
        :unit="'个'"
      />
      <data-info-item
        :img="require('@/assets/kitchen/设备在线数.png')"
        :number="statistics.onlineDeviceQuantity"
        :title="'今日设备在线数'"
        :unit="'个'"
        class="middle"
      />
      <data-info-item
        :img="require('@/assets/kitchen/在线率.png')"
        :number="statistics.onlineDeviceRatio"
        :title="'今日设备在线率'"
        :unit="''"
      />
    </div>

    <div class="productFun">
      <div class="productInput">
        SN码
        <div class="inputBox" style="width: 120px">
          <el-input
            v-model="selectInfo.snCode"
            placeholder="请入SN码"
            clearable
            class="product-input"
          />
        </div>
        设备型号
        <div class="inputBox" style="width: 144px">
          <el-input
            v-model="selectInfo.productCode"
            placeholder="请入设备型号"
            clearable
            class="product-input"
          />
        </div>
        设备品类
        <div class="inputBox" style="width: 194px">
          <el-select v-model="selectInfo.brandName" filterable clearable placeholder="请输入或选则设备类型">
            <el-option
              v-for="item in categoryList"
              :key="item.id"
              :label="item.categoryName"
              :value="item.categoryName"
            />
          </el-select>
        </div>
        设备状态
        <div class="inputBox" style="width: 90px">
          <el-select v-model="selectInfo.deviceStatus" filterable clearable placeholder="请选择">
            <el-option
              v-for="item in DevState"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
        是否绑定用户
        <div class="inputBox" style="width: 90px">
          <el-select v-model="selectInfo.deviceBindUser" filterable clearable placeholder="请选择">
            <el-option
              v-for="item in userBind"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
      </div>
      <div class="productBtn">
        <el-button
          type="primary"
          icon="el-icon-search"
          class="btnItem"
          @click="selectData"
        >
          查询
        </el-button>
        <el-button
          type="primary"
          icon="el-icon-refresh-right"
          class="btnItem"
          @click="reset"
        >
          重置
        </el-button>

        <el-button
          type="danger"
          icon="el-icon-delete-solid"
          class="btnItem bgred"
          @click=" BatchDelete"
        >
          一键解绑
        </el-button>
        <el-button
          type="primary"
          icon="el-icon-folder-opened"
          class="btnItem"
          @click="exportToExcel"
        >
          导出
        </el-button>

        <el-button type="primary" icon="el-icon-refresh-right" @click="Upgrade">
          一键固件升级
        </el-button>
      </div>
    </div>
    <el-table
      ref="multipleTable"
      :data="tableData.rows"
      :row-class-name="tableRowClassName"
      :header-cell-style="{'text-align': 'center' ,background:'  #2483b3',color:'white'}"
      :row-style="{'text-align': 'center'}"
      style="width: 100%"
    >
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column prop="index" label="序号" />
      <!-- <el-table-column
      prop="id"
      label="序号"

     >
    </el-table-column> -->
      <el-table-column
        prop="snCode"
        label="SN码"
      />
      <el-table-column
        prop="brandName"
        label="设备品牌"
      />
      <el-table-column
        prop="productCode"
        label="设备型号"
      />
      <el-table-column
        prop="createTime"
        label="生产日期"
      />
      <el-table-column
        prop="deviceStatus"
        label="设备状态"
      >
        <template slot-scope="scope">
          <!-- {{scope.deviceStatus=='1'}} -->
          <!-- {{scope.row.deviceStatus=='1'}} -->
          {{ scope.row.deviceStatus=='1'?'在线':'离线' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="deviceActiveTime"
        label="激活时间"
      />
      <el-table-column
        prop="deviceActive"
        label="是否激活"
      >
        <template slot-scope="scope">
          {{ scope.row.deviceActive=='1'?'是':'否' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="deviceBindUser"
        label="是否用户绑定设备"
      >
        <template slot-scope="scope">
          {{ scope.row.deviceBindUser=='1'?'是':'否' }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showInfo(scope.row)">
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <group-page v-model="isFristPage" :limit="limit" :total="total" :offset="offset" :count="tableData.total" @setOffset="setOffset" @setLimit="setLimit" />
    <device-info-dialog :is-show-info="isShowInfo" :data-info="rowInfo" @close="closeInfo" />
  </div>
</template>

<script>
// 组件
import DataInfoItem from '../../components/mycomponent/DataInfoItem.vue'
import deviceInfoDialog from '../../components/mycomponent/dialog/deviceInfoDialog.vue'
import GroupPage from '../../components/mycomponent/groupPage.vue'
// 逻辑
import { tableRowClassName } from '../../utils/myUtils/changeTableTr'
import { d_listPage, d_statistics, d_unbind, d_firmwareUpgrade } from '../../api/product/device'
import { listMixin, elDataDialog } from '../../utils/myUtils/mixins/listPage'
import { C_list } from '../../api/product/category'
import { outToExcel } from '../../utils/myUtils/exportToExcel'
export default {
  components: {
    DataInfoItem,
    deviceInfoDialog,
    GroupPage
  },
  mixins: [listMixin, elDataDialog],
  data() {
    return {
      statistics: {},
      dataInfo: {}, // 新数据的chushixiang
      selectInfo: { // 搜索框中的数据的数据
        snCode: '',
        productCode: '',
        brandName: '',
        deviceStatus: '',
        deviceBindUser: ''
      },
      categoryList: [],
      DevState: [

        {
          label: '在线',
          value: '1'
        },
        {
          label: '离线',
          value: '0'
        }
      ],
      userBind: [
        {
          label: '是',
          value: '1'
        },
        {
          label: '否',
          value: '0'
        }
      ]

    }
  },
  mounted() {
    // 相关状态获取
    d_statistics().then(res => {
      this.statistics = res
    })
    C_list().then(res => {
      console.log(res)
      this.categoryList = res
    })
  },
  methods: {
    tableRowClassName: tableRowClassName,
    // handleClick(rowData){
    //   this.isShowInfo =true
    //   this.rowId = rowData.id
    // },
    // closeInfo(){
    //   this.isShowInfo =false
    // },
    // 获取指定页面
    getListPage(limit, offset) {
      d_listPage(`limit=${limit}&offset=${offset}`, this.queryInfo).then(res => {
      // 得到相关数据
        res.rows.forEach((item, index) => {
          item.index = (index + 1) + ((offset - 1) * 10)
        })
        this.tableData = res
      })
    },
    reset() {
      this.selectInfo = {
        snCode: '',
        productCode: '',
        brandName: '',
        deviceStatus: '',
        deviceBindUser: ''
      }
      this.queryInfo = { ...this.selectInfo }
    },
    // 批量删除
    BatchDelete() {
      //  得到选中行
      const dle_ary = this.$refs.multipleTable.selection
      const ids = []
      dle_ary.forEach(ele => {
        ids.push(ele.id)
      })
      d_unbind({ ids: ids }).then(res => {
        if (res != '') {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.refresh()
        }
      })
    },
    Upgrade() {
      //  得到选中行
      const dle_ary = this.$refs.multipleTable.selection
      const ids = []
      console.log(dle_ary)
      dle_ary.forEach(ele => {
        ids.push(ele.deviceId)
      })
      d_firmwareUpgrade({ deviceIds: ids }).then(res => {
        if (res != '') {
          this.$message({
            message: '升级成功',
            type: 'success'
          })
          this.refresh()
        }
      })
    },
    exportToExcel() {
      d_listPage('limit=1000000000&offset=1', {}).then(res => {
        outToExcel(res.rows)
      })
    }
  }
}
</script>

<style lang="scss" scoped>

.product_container {
  position: relative;
  width: 100%;
  // min-height: 600px;
  min-height: 700px;
  overflow: auto;
  .productData {
    // min-width:1725px;
    width: 100%;
    display: flex;
    justify-content: center;
    .middle {
      margin: 0 30px;
    }
  }
  .productFun {
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    .productInput {
      display: flex;
      align-items: center;
      .inputBox {
        margin: 0 8px;
      }
    }
    .productBtn {
      .btnItem {
        margin-right: 10px;
        border-radius: 5px;
        // height: 32px;
        // width: 84px;
        font-size: 16px;
      }

    }
  }
}
</style>