<template> <div class="app-container"> <!--筛选条件--> <!--<div class="search-div">--> <!--<el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">--> <!--<el-row>--> <!--<el-form-item class="selectForm-container-item" prop="keywords">--> <!--<el-input v-model.trim="listQuery.keywords" placeholder="厂商名称/编号" clearable/>--> <!--</el-form-item>--> <!--<el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button>--> <!--<el-button v-if="hasPerm('/manufacturer/add')" class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="add">新增</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="18" class="edit_btns"> <el-button v-if="hasPerm('/busManufacturer/batchDelete')" class="edit_btn" size="small" @click="batchDelete">批量删除</el-button> <el-button v-if="hasPerm('/busManufacturer/add')" class="edit_btn" size="small" @click="add">新增</el-button> </el-col> </el-row> <el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange"> <el-table-column align="center" type="selection" width="55"/> <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" :align="column.align" show-overflow-tooltip> <template slot-scope="scope"> <el-button v-if="column.type=='Button' && scope.row.deviceCount>0" type="text" @click="goDeviceList(scope.row)">{{ scope.row[column.value] }}</el-button> <span v-else :class="column.class">{{ scope.row[column.value] }}</span> </template> </el-table-column> <el-table-column v-if="showOperate" label="操作" align="center" width="140"> <template slot-scope="scope"> <el-button v-if="hasPerm('/busManufacturer/update')" type="text" size="mini" @click="edit(scope.row)">修改</el-button> <el-button v-if="hasPerm('/busManufacturer/delete')" type="text" size="mini" @click="del(scope.row)">删除</el-button> </template> </el-table-column> </el-table> </div> <!--分页--> <div class="pagination-container"> <el-pagination v-show="total>listQuery.limit" :current-page="listQuery.offset" :page-sizes="[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-manufacturer v-show="dialogFormVisible" ref="editmanufacturer" @watchChild="fetchData"/> </div> </template> <script> import { getManufacturerListPage, delManufacturer, delManufacturers } from '@/api/systemConfig/manufacturer' import EditManufacturer from './editManufacturer' export default { name: 'ListManufacturer', components: { EditManufacturer }, data() { return { listQuery: { keywords: '', offset: 1, limit: 20, sort: '', order: '' }, // 筛选条件 columns: [ { text: '厂商名称', value: 'NAME', align: 'center' }, { text: '联系人', value: 'CONTACT', align: 'center' }, { text: '联系电话', value: 'TEL', align: 'center' }, { text: '创建时间', value: 'createTime', align: 'center' }, { text: '更新时间', value: 'updateTime', align: 'center' } ], // 显示列 list: [], // 列表数据 total: 0, // 数据总数 listLoading: true, // 加载动画 fullscreenLoading: false, // 全屏加载动画 dialogFormVisible: false // 是否显示编辑框 } }, computed: { 'showOperate': function() { // 判断是否显示操作列,如果编辑和删除的权限都没有则不显示操作列 return this.hasPerm('/busManufacturer/update') || this.hasPerm('/busManufacturer/delete') } }, created() { this.fetchData()// 获取数据 }, activated() { this.fetchData()// 获取数据 }, methods: { // 打开详情对话框 detail(row) { this.$refs.detailwell.initDialog(true, row) }, // 新增厂商 add() { this.dialogFormVisible = true this.$refs.editmanufacturer.initDialog('create', this.dialogFormVisible) }, // 编辑厂商信息 edit(row) { this.dialogFormVisible = true this.editShow = true this.$refs.editmanufacturer.initDialog('update', this.dialogFormVisible, row) }, // 删除厂商 del(row) { this.$confirm( '确定要删除厂商吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delManufacturer(row.id).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) }, // 批量删除厂商 batchDelete() { if (this.checkSelection()) { const ids = [] this.multipleSelection.forEach(function(value, index) { ids.push(value.id) }) this.$confirm( '确定要删除所选厂商吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delManufacturers(ids).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) } else { this.$message.error('至少选中一项') } }, // 查询数据 search() { this.fetchData(false) }, // 获取厂商数据 fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getManufacturerListPage(this.listQuery).then(response => { this.list = response.data.rows this.total = parseInt(response.data.total) 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 }, checkSelection() { if (this.multipleSelection.length === 0) { return false } else { return true } } } } </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>