longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<template>
    <flex-layout direction="row" no-bg>
        <my-card slot="header" title="站点状态列表" class="w300">
            <div slot="card-tools">
                <el-button class="card-tools" size="mini" type="primary"
                :disabled="!isCanEdit"
                icon="el-icon-plus" circle @click="showAddDialog"></el-button>
                <el-button class="card-tools" size="mini" type="primary"
                :disabled="aktive == -1 || !isCanEdit"
                icon="el-icon-edit" circle @click="showEditDialog"></el-button>
                <el-button class="card-tools" size="mini" type="danger"
                :disabled="aktive == -1 || !isCanEdit"
                icon="el-icon-delete" circle @click="confirmDelBaojiGroup"></el-button>
            </div>
            <li v-for="(item,i) in bzList" :key="i" @click="bzztOnclick(i,item)"><a class="bzList_box"  :class="{aktive:aktive == i}">{{ item.param }}</a></li>
        </my-card>
        <div class="flex-page-content">
            <el-tabs v-model="activeName" type="border-card" class="flex-layout ">
                    <el-transfer
                    v-model="user.value"
                    :titles="['未添加站点', '已添加站点']"
                    :button-texts="['移除', '添加']"
                    :data="user.data"
                    :filterable="true"
                    @change="userChange"
                    class="transfer-width320">
                    </el-transfer>
            </el-tabs>
        </div>
        <!-- 添加站点状态 -->
        <el-dialog
        title="添加站点状态"
        width="400px"
        :visible.sync="addBaojiGroup.show"
        :close-on-click-modal="false"
        top="0"
        class="dialog-center"
        :modal-append-to-body="false">
            <div class="params-container">
                <el-form 
                size="mini" 
                label-position="top"
                class="params-dialog">
                    <div class="table-layout">
                        <div class="table-row">
                            <div class="table-cell">
                                <el-form-item label="站点状态名称">
                                    <el-input v-model="addBaojiGroup.value"></el-input>
                                </el-form-item>
                            </div>
                        </div>
                    </div>
                    <div class="form-footer">
                        <three-btn @click="addBaojiGroupOk">确定</three-btn>
                    </div>
                </el-form>
            </div>
        </el-dialog>
        <!-- 编辑站点状态 -->
        <el-dialog
        title="编辑站点状态"
        width="400px"
        :visible.sync="editBaojiGroup.show"
        :close-on-click-modal="false"
        top="0"
        class="dialog-center"
        :modal-append-to-body="false">
            <div class="params-container">
                <el-form 
                size="mini" 
                label-position="top"
                class="params-dialog">
                    <div class="table-layout">
                        <div class="table-row">
                            <div class="table-cell">
                                <el-form-item label="站点状态名称">
                                    <el-input v-model="editBaojiGroup.value"></el-input>
                                </el-form-item>
                            </div>
                        </div>
                    </div>
                    <div class="form-footer">
                        <three-btn @click="editBaojiGroupOk">确定</three-btn>
                    </div>
                </el-form>
            </div>
        </el-dialog>
    </flex-layout>
</template>
 
<script>
import MyCard from '../../components/MyCard'
import {isHasPermit} from "@/assets/js/tools";
 
export default {
    components: {
        MyCard,
    },
    data() {
        let permits = this.$store.state.user.permits;
        let isCanEdit = isHasPermit('usr_edit_permit', permits);
        return {
            isCanEdit: isCanEdit,
            activeName: 'baoji-group-user',
            aktive:-1,
            bzList:[],
            user: {
                data: [],
                value: []
            },
            addBaojiGroup: {
                show: false,
                value: ''
            },
            editBaojiGroup: {
                show: false,
                value: ''
            },
        }
    },
    watch: {
        aktive(newVal, oldVal){
            let seft = this;
                seft.user.value = [];
                seft.user.data = [];
                seft.initStation();
        }
    },
    methods: {
        // 添加站点状态名称
        showAddDialog:function(){
            let seft =  this;
                seft.addBaojiGroup.show = true;
 
        },
        // 添加站点状态名称确定事件
        addBaojiGroupOk:function(){
            let seft = this;
            // console.log(seft.addBaojiGroup.value)
            if(seft.findingDuplicate(seft.addBaojiGroup.value)){
                seft.$message({
                    type: 'error',
                    message: seft.addBaojiGroup.value + '已存在',
                });
                return false;
            }
            // 添加站点状态名称
            seft.$axios({
                method:'post',
                url:'PageParamAction!add',
                data:'json='+ JSON.stringify({param:seft.addBaojiGroup.value,categoryId:4})
            }).then((res)=>{
                let result = JSON.parse(res.data.result);
                    if(result.code == 1){
                        // 提示信息
                        this.$message({
                            type: 'success',
                            message: '新增成功!',
                        });
                        seft.addBaojiGroup.value = '';
                        seft.addBaojiGroup.show = false;
                        seft.initData();
                    }
            })
            
        },
        // 编辑站点状态名称
        showEditDialog:function(){
            let seft = this;
                seft.editBaojiGroup.show = true;
                seft.editBaojiGroup.value = seft.bzList[seft.aktive].param;
        },
        // 编辑站点状态名称确定事件
        editBaojiGroupOk:function(){
            let seft = this;
            // console.log(seft.editBaojiGroup.value)
            if(seft.findingDuplicate(seft.editBaojiGroup.value)){
                this.$message({
                    type: 'error',
                    message: seft.editBaojiGroup.value + '已存在',
                });
                return false;
            }
            // 修改站点状态名称
            seft.$axios({
                method:'post',
                url:'PageParamAction!updateParamById',
                data:'json='+ JSON.stringify({param:seft.editBaojiGroup.value,id:seft.bzList[seft.aktive].id})
            }).then((res)=>{
                let result = JSON.parse(res.data.result);
                    if(result.code == 1){
                        // 提示信息
                        this.$message({
                            type: 'success',
                            message: '修改成功!',
                        });
                        seft.editBaojiGroup.show = false;
                        seft.initData();
                    }
            })
        },
        // 点击站点状态名称状态时效果
        bzztOnclick:function(index){
            let seft = this;
                seft.aktive = index;
        },
        // 初始化数据
        initData() {
            // 查询
            let seft =  this;
                seft.$axios({
                    method:'post',
                    url:'PageParamAction!findByCategoryId',
                    data:'json=' + JSON.stringify({categoryId:4})
                }).then((res)=>{
                    let result = JSON.parse(res.data.result);
                    // console.log(result)
                        if(result.code == 1 && result.data.length>0){
                            seft.bzList = result.data;
                        }else{
                            seft.bzList = [];
                        }
                })
        },
        // 初始化查询站点
        initStation:function(index){
            let seft = this;
                seft.$axios({
                    method:'post',
                    url:'BattInfAction!searchAllStation',
                    data:null
                }).then((res)=>{
                    let result = JSON.parse(res.data.result);
                        if(result.code == 1 && result.data.length>0){
                            
                            let params = [];
                            result.data.forEach(item=>{
                                    if(seft.aktive== -1){
                                        
                                        let obj = {
                                            key:item.StationId,
                                            label:item.StationName3,
                                            sortId:item.sortId,
                                            StationName:item.StationName
                                        }
                                        params.push(obj);
                                    }else{
                                        if(item.sortId == 0 || item.sortId == seft.bzList[seft.aktive].id){
                                            let obj = {
                                                key:item.StationId,
                                                label:item.StationName3,
                                                sortId:item.sortId,
                                                StationName:item.StationName
                                            }
                                            params.push(obj);
                                        }
                                    }
                                })
                                seft.user.data = params;
                                if(seft.aktive!= -1){
                                    seft.addedSite();
                                }
                                // console.log(params)
                        }
                })
        },
        // 已添加站点设置
        addedSite:function(){
            let seft = this;
                seft.user.value = [];
            seft.user.data.forEach(item => {
               if(item.sortId == seft.bzList[seft.aktive].id){
                   seft.user.value.push(item.key);
               }
           });
        },
        // 删除站点状态名称
        confirmDelBaojiGroup() {
            let seft =  this;
            let name  = seft.bzList[seft.aktive].param;
            this.$layer.confirm('确认删除'+name, {icon:3},index=>{
                // 关闭弹出框
                this.$layer.close(index);
                // 删除包机组
                seft.$axios({
                    method:'post',
                    url:'PageParamAction!delete',
                    data:'json=' + JSON.stringify({id:seft.bzList[seft.aktive].id})
                }).then((res)=>{
                    let result = JSON.parse(res.data.result);
                        if(result.code == 1){
                             // 提示信息
                                this.$message({
                                    type: 'success',
                                    message: '删除成功!',
                                });
                                seft.aktive = -1;
                                seft.initData();
                                
                        }
                })
            });
        },
        // 站点移动事件 list:已经添加的数组,tyoe:移动方向 values:当前移动的数据
        userChange(list, type, values) {
            // console.log(this.user)
            // var userList = this.getUserListByUIds(values);
            let seft = this;
                if(seft.aktive == -1){
                    seft.$message({
                        type: 'error',
                        message: '请先选择分类',
                    });
                    seft.user.value = [];
                    return false;
                }
            // 根据类型确定事件
            switch(type) {
                case 'left':
                    this.removeUser(values);
                break;
                case 'right':
                    this.addUser(values);
                break;
            }
        },
        // 向左边添加站点
        addUser(list) {
            // console.log(list)
            let seft = this;
                seft.addAndDelete(list,seft.bzList[seft.aktive].id,'站点添加分类成功!')
        },
        // 向右边添加站点
        removeUser(list) {
            // console.log(list)
            let seft = this;
            seft.addAndDelete(list,0,'站点移除分类成功!')
        },
        // 添加和删除站点
        addAndDelete:function(list,status,msg){
            let seft = this;
            let params = [];
                list.forEach(item => {
                    let obj = {
                        StationId:item,
                        sortId:status
                    }
                    params.push(obj)
                });
            seft.$axios({
                method:'post',
                url:'BattInfAction!updateSortId',
                data:'json=' + JSON.stringify(params)
            }).then((res)=>{
                let result = JSON.parse(res.data.result);
                    if(result.code == 1){
                        // 提示信息
                        this.$message({
                            type: 'success',
                            message: msg,
                        });
                        this.initStation();
                    }
            })
        },
        // 查重
        findingDuplicate:function(value){
            let seft = this;
            let status = false;
            seft.bzList.forEach(element => {
                if(element == value){
                    status = true;
                }
            });
            return status;
        },
    },
    mounted() {
        // 初始化查询站点分类名称
        this.initData();
        // 初始化查询站点
        this.initStation();
        // 查询包机组列表
        // this.searchBaojiGroupList();
    }
}
</script>
 
<style scoped>
.bzList_box{
    display: block;
    padding: 6px 8px;
    text-indent: 10px;
    text-decoration: none;
    color: #FFFFFF;
    font-size: 14px;
}
.aktive{
    background-color: #00fefe;
    color: #021a64;
}
.flex-page-content {
    padding: 0 8px;
}
</style>