<!--设备列表--> <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" style="margin-top: 30px"> <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 brandList" :key="item.id" :label="item.brandName" :value="item.brandName" /> </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 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> </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" con="el-icon-delete-solid" lass="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" @click="Upgrade"> 一键固件升级 </el-button> </div> </div> <el-table ref="multipleTable" v-loading="loading" :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 type="index" width="55" label="编号" /> --> <el-table-column type="index" label="序号"> <template slot-scope="scope"> {{ (offset - 1) * limit + scope.$index + 1 }} </template> </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, d_listExport, } from "../../api/product/device"; import { listMixin, elDataDialog } from "../../utils/myUtils/mixins/listPage"; import { SelectList } from "../../api/product/brand"; import { exportFile } from "@/utils/exportutils"; import { export_json_to_excel } from "../../utils/Export2Excel"; 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: "", }, brandList: [], DevState: [ { label: "在线", value: "1", }, { label: "离线", value: "0", }, ], userBind: [ { label: "是", value: "1", }, { label: "否", value: "0", }, ], }; }, mounted() { // 相关状态获取 d_statistics().then((res) => { this.statistics = res; }); SelectList().then((res) => { this.brandList = res; }); }, methods: { tableRowClassName: tableRowClassName, // handleClick(rowData){ // this.isShowInfo =true // this.rowId = rowData.id // }, // closeInfo(){ // this.isShowInfo =false // }, // 获取指定页面 getListPage(limit, offset) { this.loading = true; 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; this.loading = false; }) .catch((_) => { this.loading = false; }); }, reset() { this.selectInfo = { snCode: "", productCode: "", brandName: "", deviceStatus: "", deviceBindUser: "", }; this.queryInfo = { ...this.selectInfo }; this.refresh(); }, // 批量删除 BatchDelete() { if (this.$refs.multipleTable.selection.length) { // 得到选中行 const dle_ary = this.$refs.multipleTable.selection; const ids = []; dle_ary.forEach((ele) => { ids.push(ele.id); }); d_unbind({ deviceIds: ids }) .then((res) => { this.$message({ message: res || "解绑成功", type: "success", }); this.refresh(); }) .catch((_) => {}); } else { this.$message.warning("请先选择需要解绑的设备"); } }, 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) => { this.$message({ message: res || "升级成功", type: "success", }); this.refresh(); }); }, exportToExcel() { // 全屏加载动画 const loading = this.$loading({ lock: true, text: "下载中,请稍后...", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", }); d_listPage(`limit=100000000&offset=1`, {}) .then((res) => { res.rows = res.rows.map((item, index) => { return { 序号: index + 1, SN码: item.snCode, 设备品牌: item.brandName, 设备型号: item.productCode, 生产日期: item.createTime, 设备状态: item.deviceStatus == "1" ? "在线" : "离线", 激活时间: item.deviceActiveTime, 是否激活: item.deviceActive == "1" ? "是" : "否", 是否用户绑定设备: item.deviceBindUser == "1" ? "是" : "否", }; }); outToExcel(res.rows, "设备列表"); loading.close(); // 关闭加载动画 this.$message({ message: "导出成功", type: "success", }) }) .catch((error) => { loading.close() // 关闭加载动画 this.$message({ message: error.message, type: "error", }); }) } } } </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: 0px 0px 30px; 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>