houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-card shadow="never" class="aui-card--fill">
3     <div>
4       <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
5         <el-form-item>
6           <el-input v-model="dataForm.energytypename" placeholder="名称" clearable></el-input>
7         </el-form-item>
8         <el-form-item>
9           <el-button @click="searchDataList()">查询</el-button>
10           <el-button v-if="$hasPermission('mcs:store-type:add')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
11           <el-button v-if="$hasPermission('mcs:store-type:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
12         </el-form-item>
13       </el-form>
14       <el-table
15               :data="dataList"
16               border
17               v-loading="dataListLoading"
18               @selection-change="selectionChangeHandle"
19               style="width: 100%;">
20         <el-table-column
21                 type="selection"
22                 header-align="center"
23                 align="center"
24                 width="50">
25         </el-table-column>
26         <el-table-column
27                 type="index"
28                 align="center"
29                 width="50"
30                 label="序号"
31         >
32         </el-table-column>
33         <el-table-column
34                 prop="energytypename"
35                 header-align="center"
36                 align="center"
37                 label="名称">
38         </el-table-column>
39         <el-table-column
40                 v-if="$hasPermission('mcs:store-type:edit')"
41                 fixed="right"
42                 header-align="center"
43                 align="center"
44                 width="150"
45                 label="操作">
46           <template slot-scope="scope">
47             <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
48           </template>
49         </el-table-column>
50       </el-table>
51       <el-pagination
52               @size-change="sizeChangeHandle"
53               @current-change="currentChangeHandle"
54               :current-page="pageIndex"
55               :page-sizes="[10, 20, 50, 100]"
56               :page-size="pageSize"
57               :total="totalPage"
58               layout="total, sizes, prev, pager, next, jumper">
59       </el-pagination>
60       <!-- 弹窗, 新增 / 修改 -->
61       <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
62     </div>
63   </el-card>
64 </template>
65
66 <script>
67   import AddOrUpdate from './st-schedule-energy-type-add-or-update'
68
69   export default {
70     data () {
71       return {
72         dataForm: {
73           energytypename: ''
74         },
75         dataList: [],
76         pageIndex: 1,
77         pageSize: 10,
78         totalPage: 0,
79         dataListLoading: false,
80         dataListSelections: [],
81         addOrUpdateVisible: false
82       }
83     },
84     components: {
85       AddOrUpdate
86     },
87     activated () {
88       this.getDataList()
89     },
90     methods: {
91       searchDataList () {
92         this.pageIndex = 1
93         this.getDataList()
94       },
95       // 获取数据列表
96       getDataList () {
97         this.dataListLoading = true
98         this.$http({
99           url:'/iailab-ntt-model/mcs/schedule-energy-type/list',
100           method: 'get',
101           params: this.$http.adornParams({
102             'page': this.pageIndex,
103             'limit': this.pageSize,
104             'energytypename': this.dataForm.energytypename
105           })
106         }).then(({data}) => {
107           if (data && data.code === 0) {
108             this.dataList = data.page.list
109             this.totalPage = data.page.totalCount
110           } else {
111             this.dataList = []
112             this.totalPage = 0
113           }
114           this.dataListLoading = false
115         })
116       },
117       // 每页数
118       sizeChangeHandle (val) {
119         this.pageSize = val
120         this.pageIndex = 1
121         this.getDataList()
122       },
123       // 当前页
124       currentChangeHandle (val) {
125         this.pageIndex = val
126         this.getDataList()
127       },
128       // 多选
129       selectionChangeHandle (val) {
130         this.dataListSelections = val
131       },
132       // 新增 / 修改
133       addOrUpdateHandle (id) {
134         this.addOrUpdateVisible = true
135         this.$nextTick(() => {
136           this.$refs.addOrUpdate.init(id)
137         })
138       },
139       // 删除
140       deleteHandle (id) {
141         var ids = id ? [id] : this.dataListSelections.map(item => {
142           return item.id
143         })
144         this.$confirm(`确定删除选中的${ids.length}项数据?`, '提示', {
145           confirmButtonText: '确定',
146           cancelButtonText: '取消',
147           type: 'warning'
148         }).then(() => {
149           this.$http({
150             url: '/iailab-ntt-model/mcs/schedule-energy-type/delete',
151             method: 'post',
152             data: this.$http.adornData(ids, false)
153           }).then(({data}) => {
154             if (data && data.code === 0) {
155               this.$message({
156                 message: '操作成功',
157                 type: 'success',
158                 duration: 1500,
159                 onClose: () => {
160                   this.getDataList()
161                 }
162               })
163             } else {
164               this.$message.error(data.msg)
165             }
166           })
167         }).catch(() => {})
168       }
169     }
170   }
171 </script>