<template xmlns:align=""> <div class="app-container"> <!--筛选条件--> <div class="search-div"> <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container"> <el-form-item class="selectForm-container-item" prop="keywords"> <el-input v-model.trim="listQuery.imei" placeholder="IEMI号" clearable/> </el-form-item> <el-form-item class="selectForm-container-item" prop="keywords"> <el-input v-model="listQuery.iot" placeholder="物联网卡号" clearable/> </el-form-item> <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">查 询</el-button> <el-button class="filter-item" type="primary" icon="el-icon-edit" @click="add">新 增</el-button> </el-form> </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"> <!--批量导入--> <el-upload :limit="1" :show-file-list="false" :http-request="uploadFile" :file-list="fileList" action="string" accept=".xls,.xlsx" class="edit_btn" style="margin-top: 0"> <el-button slot="trigger" class="edit_btn" size="small">批量导入</el-button> </el-upload> <download-template filename="deviceImportTemp.xlsx" class="edit_btn" btnname="模板下载"/> </el-col> </el-row> <!--查询结果Table显示--> <el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange"> <el-table-column :index="indexMethod" align="center" type="index" label="序号" width="55"/> <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :align="column.align" show-overflow-tooltip> <template slot-scope="scope"> <span :class="column.class">{{ scope.row[column.value] }}</span> </template> </el-table-column> <el-table-column label="操作" width="180" align="center"> <template slot-scope="scope"> <el-button type="primary" size="mini" @click="detail(scope.row)">详情</el-button> <el-button type="warning" size="mini" @click="edit(scope.row)">修改</el-button> <el-button type="danger" size="mini" @click="del(scope.row)">删除</el-button> </template> </el-table-column> </el-table> <!--分页--> <div class="pagination-container"> <el-pagination v-show="total>listQuery.limit" :current-page="listQuery.offset" :page-sizes="[15,20,30]" :page-size="listQuery.limit" :total="total" align="center" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange"/> </div> <!--编辑资源的对话框--> <edit-gps-device v-show="dialogFormVisible" ref="editGpsDevice" @watchChild="fetchData"/> </div> </template> <script> import editGpsDevice from '@/views/carinfo/editGpsDevice' import DownloadTemplate from '@/components/DownloadTemplate/index' import { getDeviceInfoList, delDeviceInfo, batchImport } from '@/api/device' export default { name: 'ListGpsDevice', components: { editGpsDevice, DownloadTemplate }, data() { return { fileList: [], // 上传文件列表 deptShow: true, listQuery: { imei: '', iot: '', carType: '', deptId: '', offset: 1, limit: 15 }, // 查询条件 columns: [ { text: 'IMEI', value: 'imei', align: 'center' }, { text: '物联网卡号', value: 'iot', align: 'center' }, { text: 'SIM卡号', value: 'sim', align: 'center' }, { text: '创建时间', value: 'createTime', align: 'center' } ], // 动态加载的表头 list: [], // 列表数据 total: 0, // 数据总数 listLoading: true, // 加载动画 fullscreenLoading: false, // 全屏加载动画 dialogFormVisible: false, // 是否显示编辑框 cartypelist: [], // 类型列表 deptlist: [] // 类型列表 } }, created() { this.fetchData() }, methods: { // 批量导入 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)' }) // 发起导入请求 batchImport(_file).then(res => { loading.close() // 关闭加载动画 if (res.code === 200) { this.$message.success('导入成功') this.fileList = [] this.fetchData(false) } }).catch(() => { loading.close() }) this.fileList = [] }, add() { this.dialogStatus = 'create' this.dialogFormVisible = true this.$refs.editGpsDevice.initDialog(this.dialogStatus, this.dialogFormVisible) }, edit(row) { this.dialogStatus = 'update' this.dialogFormVisible = true this.$refs.editGpsDevice.initDialog(this.dialogStatus, this.dialogFormVisible, row) }, detail(row) { this.dialogStatus = 'detail' this.dialogFormVisible = true this.$refs.editGpsDevice.initDialog(this.dialogStatus, this.dialogFormVisible, row) }, del(row) { this.$confirm( '确定要删除' + row.imei + '吗?', '确认删除', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delDeviceInfo(row.id).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) }, search() { this.fetchData(false) }, fetchData(isNowPage = true) { console.log('fetchData') this.listLoading = true if (!isNowPage) { this.listQuery.offset = 1 } getDeviceInfoList(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) getDeviceInfoList(this.listQuery).then(response => { this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false }) } this.listLoading = false }) }, indexMethod(index) { return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1 }, // 改变页容量 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:45px; .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{ padding-top: 8px; .edit_btn{ float:right; margin:0px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2 } } .el-table__header tr, .el-table__header th { padding: 0; height: 40px; background-color: #f8f8f8; } .table{ margin-bottom: 20px; } .pagination-container{ margin-bottom: 100px; } </style>