<template> <app-container> <search-area :need-clear="true" :need-search-more="false" type="seperate" size="small" search-more-type="default" @search="fetchData" @clear="clearInput"> <!--一般查询条件--> <search-item> <el-input v-model.trim="listQuery.strategyName" size="small" placeholder="策略名称" clearable/> </search-item> <template slot="btns-seperate"> <el-button class="filter-item" type="primary" icon="el-icon-edit" size="small" @click="editthreshold">阈值设置</el-button> <el-button class="filter-item" type="primary" icon="el-icon-edit" size="small" @click="edittime">采集设置</el-button> </template> </search-area> <normal-table :data="list" :head="tableOption.head" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" :options="tableOption.options" :tools-option="tableOption.toolsOption" size="small" @selectionChange="handleSelectionChange" @change="changePage"> <template slot="btns"> <el-button class="edit_btn" size="small" @click="del">删除</el-button> <el-button class="edit_btn" size="small" @click="check">下发</el-button> <el-button class="edit_btn" size="small" @click="add">新增</el-button> </template> <template slot="columns"> <el-table-column label="操作" align="center" width="130"> <template slot-scope="scope"> <el-button type="text" size="small" @click="edit(scope.row)">编辑</el-button> <el-button type="text" size="small" @click="detail(scope.row)">详情</el-button> </template> </el-table-column> </template> </normal-table> <edit-strategy v-show="dialogFormVisible" ref="editstrategy" @watchChild="fetchData"/> <edit-threshold v-show="dialogFormVisible1" ref="editthreshold"/> <edit-time v-show="dialogFormVisible2" ref="edittime"/> </app-container> </template> <script> import { getStrategyList, batchDelete, batchIssue } from '@/api/system/strategy' import EditStrategy from './components/editStrategy' import EditThreshold from './components/editThreshold' import EditTime from './components/editTime' export default { name: 'ListStrategy', components: { EditThreshold, EditStrategy, EditTime }, data() { return { listQuery: { strategyName: '', offset: 1, limit: 20, sort: '', order: '' }, // 筛选条件 columns: [ { text: '策略名称', value: 'strategyName', align: 'center' }, { text: '关联设备类型', value: 'deviceTypeName', align: 'center' }, { text: '生效日期', value: 'startDate', align: 'center' }, { text: '失效日期', value: 'endDate', align: 'center' }, { text: '优先级', value: 'priorityName', align: 'center' }, { text: '创建时间', value: 'createTime', align: 'center' }, { text: '创建用户', value: 'createUserName', align: 'center' } ], total: 0, // 数据总数 list: [], // 报警列表 listLoading: true, // 列表加载 multipleSelection: [], // 多选选中项 dialogFormVisible: false, dialogFormVisible1: false, dialogFormVisible2: false, tableOption: { head: { show: true, // 是否需要标题栏, text: '数据列表' // 标题名称 }, options: { needIndex: true, // 是否需要序号列 needMultSelect: true }, toolsOption: { selectColumns: false, // 是否需要筛选列 refresh: false // 是否需要刷新按钮 } } // 表格属性 } }, created() { this.fetchData()// 获取数据 }, activated() { this.fetchData() }, methods: { // 多选触发方法 handleSelectionChange(val) { this.multipleSelection = val }, // 检查选择情况 checkSelection() { if (this.multipleSelection.length === 0) { return false } else { return true } }, check() { if (this.checkSelection()) { const devIds = [] this.multipleSelection.forEach(function(value, index) { devIds.push(value.id) }) this.$confirm( '确定要下发所选策略吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { batchIssue(devIds).then(response => { if (response.code === 200) { this.$message.success('下发成功') this.fetchData() } }) }) } else { this.$message.error('至少选中一项') } }, del() { if (this.checkSelection()) { const devIds = [] this.multipleSelection.forEach(function(value, index) { devIds.push(value.id) }) this.$confirm( '确定要删除所选策略吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { batchDelete(devIds).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) } else { this.$message.error('至少选中一项') } }, fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getStrategyList(this.listQuery).then(response => { if (response.code === 200) { this.list = response.data.rows this.total = parseInt(response.data.total) } else { this.$message.error(response.message) } this.listLoading = false }) }, // 查询数据 search() { this.fetchData(false) }, detail(row) { this.dialogFormVisible = true this.$refs.editstrategy.initDialog('detail', this.dialogFormVisible, row) }, edit(row) { this.dialogFormVisible = true this.$refs.editstrategy.initDialog('update', this.dialogFormVisible, row) }, add(row) { this.dialogFormVisible = true this.$refs.editstrategy.initDialog('create', this.dialogFormVisible, row) }, editthreshold() { this.dialogFormVisible1 = true this.$refs.editthreshold.initDialog('update', this.dialogFormVisible1, null) }, edittime() { this.dialogFormVisible2 = true this.$refs.edittime.initDialog('update', this.dialogFormVisible2, null) }, changePage(val) { if (val && val.size) { this.listQuery.limit = val.size } if (val && val.page) { this.listQuery.offset = val.page } this.fetchData() } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> $tableTitleHeight:46px; .app-container{ margin-bottom:20px } .table{ margin-bottom: 20px; } .small-row-class{ height: 15px; } .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> <style rel="stylesheet/scss" lang="scss"> .small-row-class td{ padding:2px 0px; } </style>