<template> <div class="app-container"> <div class="search-div"> <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container"> <el-row> <el-col :span="4"> <el-form-item class="selectForm-container-item" prop="markerId"> <el-input v-model.trim="listQuery.markerId" placeholder="标识器ID" clearable /> </el-form-item> </el-col> <el-col :span="4"> <el-form-item class="selectForm-container-item" prop="securityId"> <el-input v-model.trim="listQuery.securityId" placeholder="图片防伪ID" clearable /> </el-form-item> </el-col> <el-col :span="4"> <el-form-item class="selectForm-container-item" prop="deptName"> <el-input v-model.trim="listQuery.deptName" placeholder="用户信息" clearable /> </el-form-item> </el-col> <el-col :span="4"> <el-form-item class="selectForm-container-item" prop="productInfo"> <el-input v-model.trim="listQuery.productInfo" placeholder="产品信息" clearable /> </el-form-item> </el-col> <el-col :span="4"> <el-form-item class="selectForm-container-item" prop="batchNum"> <el-input v-model.trim="listQuery.batchNum" placeholder="批次号" clearable /> </el-form-item> </el-col> <el-col :span="4"> <el-form-item class="selectForm-container-item" prop="inspectionPeriod"> <el-input v-model.trim="listQuery.inspectionPeriod" placeholder="巡检周期" clearable /> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="4"> <el-form-item class="selectForm-container-item" prop="valid"> <el-select v-model.trim="listQuery.valid" placeholder="状态" clearable > <el-option key="1" label="正常" value="1"/> <el-option key="0" label="报废" value="0"/> <el-option key="2" label="维护中" value="2"/> </el-select> </el-form-item> </el-col> <el-form-item class="selectForm-container-item" prop="installDateBegin"> <el-date-picker v-model="installDateRange" type="daterange" range-separator="至" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="安装开始日期" end-placeholder="安装结束日期" /> </el-form-item> <el-form-item class="selectForm-container-item" prop="shelfLifeBegin"> <el-date-picker v-model="shelfLifeRange" type="daterange" range-separator="至" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="保质期开始日期" end-placeholder="保质期结束日期" /> </el-form-item> <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button> </el-row> </el-form> </div> <div> <el-row class="table-title"> <el-col :span="6"> <div class="title-header"> <i class="el-icon-menu" />数据列表 </div> </el-col> <el-col :span="12" :offset="6" class="edit_btns"> <download-template v-if="hasPerm('/marker/batchImport')" :filename="filename" /> <el-upload v-if="hasPerm('/marker/batchImport')" :limit="1" :show-file-list="false" :http-request="uploadFile" :file-list="fileList" action="string" accept=".xls, .xlsx" class="edit_btn" > <el-button slot="trigger" size="small">批量导入</el-button> </el-upload> <el-button v-if="hasPerm('/marker/delete')" class="edit_btn" size="small" @click="del">删除</el-button> </el-col> </el-row> <el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange" @row-click="showDetail" > <el-table-column align="center" type="selection" width="50" /> <el-table-column :index="indexMethod" align="center" type="index" /> <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :min-width="column.minwidth" :align="column.align" show-overflow-tooltip > <template slot-scope="scope"> <span v-if="column.type!='Button'" :class="column.class">{{ scope.row[column.value] }}</span> <el-button v-if="column.type=='Button'" type="text" @click="showWellDetail(scope.row)" >{{ scope.row[column.value] }}</el-button> </template> </el-table-column> <el-table-column label="操作" align="center" width="240"> <template slot-scope="scope"> <el-button type="text" @click="inpsectionlist(scope.row)">巡检记录列表</el-button> <el-button type="text" @click="maintainlist(scope.row)">维护记录列表</el-button> <el-button v-if="hasPerm('/marker/update')" type="text" @click="edit(scope.row)">编辑</el-button> </template> </el-table-column> </el-table> </div> <div class="pagination-container"> <el-pagination :current-page="listQuery.offset" :page-sizes="[5,10,20,30,50]" :page-size="listQuery.limit" :total="total" align="center" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange" /> </div> <edit-marker v-show="editShow" ref="editmarker" @watchChild="fetchData" /> <detail-marker v-show="detailShow" ref="detailMarker"/> <list-inspection ref="listInspection"/> <list-maintain ref="listMaintain"/> </div> </template> <script> import { getMarkerList, batchImportMarker, delMarker } from '@/api/marker' import DownloadTemplate from '@/components/DownloadTemplate' import editMarker from '@/views/markerManage/editMarker' import detailMarker from '@/views/markerManage/detailMarker' import listInspection from '@/views/markerManage/listInspection' import listMaintain from '@/views/markerManage/listMaintain' export default { name: 'ListMarker', components: { DownloadTemplate, editMarker, detailMarker, listInspection, listMaintain }, data() { return { listQuery: { markerId: '', securityId: '', deptName: '', inspectionPeriod: '', productInfo: '', installDateBegin: '', installDateEnd: '', shelfLifeBegin: '', shelfLifeEnd: '', batchNum: '', valid: '', offset: 1, limit: 5, sort: '', order: '' }, columns: [ { text: '标识器ID', value: 'markerId', align: 'center' }, { text: '图片防伪ID', value: 'securityId', align: 'center' }, { text: '用户信息', value: 'deptName', align: 'center' }, // { // text: '安装时间', // value: 'installDate', // align: 'center' // }, // { // text: '保质期', // value: 'shelfLife', // align: 'center' // }, { text: '产品信息', value: 'productInfo', align: 'center' }, { text: '批次号', value: 'batchNum', align: 'center' }, { text: '巡检周期(天)', value: 'inspectionPeriod', align: 'center', minwidth: 100 }, { text: '详细地址', value: 'position', align: 'center' }, { text: '状态', value: 'valid', align: 'center' } ], multipleSelection: [], // 多选选中项 list: [], // 列表数据 total: 0, // 数据总数 listLoading: false, // 加载动画 fullscreenLoading: false, // 全屏加载动画 editShow: false, // 是否显示编辑框 detailShow: false, // 是否显示详情框 filename: 'marker_template.xlsx', fileList: [], installDateRange: [], shelfLifeRange: [] } }, watch: { installDateRange(val) { if (val && val.length > 0) { this.listQuery.installDateBegin = val[0] this.listQuery.installDateEnd = val[1] } else { this.listQuery.installDateBegin = '' this.listQuery.installDateEnd = '' } }, shelfLifeRange(val) { if (val && val.length > 0) { this.listQuery.shelfLifeBegin = val[0] this.listQuery.shelfLifeEnd = val[1] } else { this.listQuery.shelfLifeBegin = '' this.listQuery.shelfLifeEnd = '' } } }, mounted() { this.fetchData() }, methods: { indexMethod(index) { return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1 }, fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } // console.log(this.listQuery) getMarkerList(this.listQuery).then(response => { this.list = response.data.rows this.total = parseInt(response.data.total) // 如果当前页码数据为空,重新请求末页 if (this.listQuery.offset > Math.ceil(this.total / this.listQuery.limit)) { this.listQuery.offset = Math.ceil(this.total / this.listQuery.limit) getMarkerList(this.listQuery).then(response => { this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false }) } this.listLoading = false // console.log(this.list) }) }, search() { this.fetchData(false) }, del() { if (this.checkSelection()) { const markerIds = [] this.multipleSelection.forEach(function(value, index) { markerIds.push(value.id) }) // wellNames = wellNames.slice(0, wellNames.length - 1) this.$confirm('确定要删除所选标识吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { delMarker(markerIds).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) } else { this.$message.error('至少选中一项') } }, // 检查选择情况 checkSelection() { if (this.multipleSelection.length === 0) { return false } else { return true } }, // 新增设备 // add() { // this.dialogFormVisible = true // this.editShow = true // this.$refs.editmarker.initDialog('create', this.dialogFormVisible) // }, // 编辑设备信息 edit(row) { event.stopPropagation() this.dialogFormVisible = true this.editShow = true this.$refs.editmarker.initDialog('update', this.dialogFormVisible, row) }, showDetail(row) { this.detailShow = true this.$refs.detailMarker.initDialog(true, row) }, inpsectionlist(row) { event.stopPropagation() this.$router.push({ name: 'Inspection', params: { markerId: row.markerId } }) }, maintainlist(row) { event.stopPropagation() this.$router.push({ name: 'Maintain', params: { markerId: row.markerId } }) }, // 批量导入集中器 uploadFile(param) { // 判断文件大小是否符合要求 const _file = param.file const isLt5M = _file.size / 1024 / 1024 < 5 if (!isLt5M) { this.$message.error('请上传5M以下的excel文件') return false } // 全屏加载动画 const loading = this.$loading({ lock: true, text: '导入中,请稍后...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) // 发起导入请求 batchImportMarker(_file) .then(res => { loading.close() // 关闭加载动画 if (res.code === 200) { this.$message.success('导入成功') this.fetchData(false) } else { this.$message.error(res.message) } }) .catch(error => { loading.close() // 关闭加载动画 this.$message.error(error.message) }) this.fileList = [] }, // 改变页容量 handleSizeChange(val) { this.listQuery.limit = val this.fetchData() }, // 改变当前页 handleCurrentChange(val) { this.listQuery.offset = val this.fetchData() }, // 多选触发方法 handleSelectionChange(val) { this.multipleSelection = val } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> $tableTitleHeight: 46px; .table { margin-bottom: 20px; } .pagination-container { margin-bottom: 50px; } .table-title { background-color: rgba(243, 243, 243, 1); height: $tableTitleHeight; .title-header { line-height: $tableTitleHeight; color: #606266; font-size: 15px i { margin-left: 5px; margin-right: 5px; } } } .edit_btns { .edit_btn { float: right; margin: 7px 3px; //为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2 } } </style>