ludc
2023-04-20 f3c411d4ddc5d1ebf7414103b1bc0d09b929c413
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<template>
  <basic-container style="height: 350px;">
 
    <!-- 编码规则信息展示区域 -->
    <basic-container>
      <p style="margin-top: -12px; margin-bottom: 4px; font-weight: 570; font-size: 19px; color: #0e2d5f;">编码规则</p>
      <avue-crud :option="optionRule"
                :table-loading="loading"
                :data="data"
                :page.sync="page"
                :permission="permissionList"
                v-model="form"
                ref="crud"
                :before-open="beforeOpen"
                @cell-click="loadBasic"
                @row-update="rowUpdate"
                @row-save="rowSave"
                @search-change="searchChange"
                @search-reset="searchReset"
                @selection-change="selectionChange"
                @current-change="currentChange"
                @size-change="sizeChange"
                @refresh-change="refreshChange"
                @on-load="onLoad">
        <!-- 表格内操作按钮 -->
        <template slot="menu" slot-scope="scope">
          <el-button type="text"
                    size="small"
                    icon="el-icon-edit"
                    v-show="scope.row.lcStatus=='Editing' ? true:false"
                    plain
                    @click="openEdit(scope.row)">编 辑
          </el-button>
          <el-button type="text"
                    size="small"
                    icon="el-icon-position"
                    v-show="scope.row.lcStatus=='Editing' ? true:false"
                    plain
                    @click="enableOrDeactivatse(scope.row.oid,'release')">发 布
          </el-button>
          <el-button type="text"
                    size="small"
                    v-show="scope.row.lcStatus=='Released' ? true:false"
                    icon="el-icon-video-pause"
                    plain
                    @click="enableOrDeactivatse(scope.row.oid,'disable')">停 用
          </el-button>
          <el-button type="text"
                    size="small"
                    v-show="scope.row.lcStatus=='Disabled' ? true:false"
                    icon="el-icon-video-play"
                    plain
                    @click="enableOrDeactivatse(scope.row.oid,'enable')">启 用
          </el-button>
        </template>
        <!-- 表格左上方按钮区域 -->
        <template slot="menuLeft" slot-scope="scope">
          <el-button type="danger"
                    size="small"
                    icon="el-icon-delete"
                    plain
                    @click="handleDelete">删 除
          </el-button>
          <el-button size="small"
                    icon="icon-kelong"
                    plain
                    @click="cloneCodeSetting">克 隆
          </el-button>
          <el-button size="small"
                    icon="icon-lianjiekelong"
                    style="font-size: 12px;"
                    plain
                    @click="handleDelete">从其他规则中克隆码段
          </el-button>
          <el-button size="small"
                    icon="el-icon-s-help"
                    plain
                    @click="handleRange">使用范围
          </el-button>
          <el-button size="small"
                    icon="icon-qingkong"
                    plain
                    @click="handleDelete">清空码值
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
 
    <!-- 对话框 -->
    <el-dialog title="编码规则使用范围"
                append-to-body
                :visible.sync="codeRangeSettingBox"
                width="800px">
      <avue-crud
              :option="dialogeOption" 
              :table-loading="dialogLoading"
              :data="useRangeData"
              @refresh-change="refreshUseRangeChange"></avue-crud>
    </el-dialog>
    <!-- 克隆对话框 -->
    <el-dialog title="克隆编码规则"
                append-to-body
                :visible.sync="cloneSettingBox"
                width="800px">
      <clone-code></clone-code>
    </el-dialog>
 
    <!-- 基础码段展示区域 -->
    <basic-container>
        <p style="margin-top: -12px; margin-bottom: 4px; font-weight: 570; font-size: 19px; color: #0e2d5f;">码段管理</p>
        <avue-crud :option="optionBasic"
        :table-loading="loadingBasic"
        :data="basicData"
        :permission="permissionList"
        @selection-change="selectionBasicChange"
        @refresh-change="refreshChangeBasicSec">
 
        <!-- 基础码段表格内操作按钮 -->
        <template slot="menu" slot-scope="scope">
 
          <el-button type="text"
                    size="small"
                    icon="icon-shangyi"
                    v-show="scope.row.lcStatus != 'Editing' ? true:false"
                    plain
                    @click="openEdit(scope.row)">查 看
          </el-button>
 
          <el-button type="text"
                    size="small"
                    icon="icon-shangyi"
                    v-show="scope.row.lcStatus == 'Editing' ? true:false"
                    plain
                    @click="openEdit(scope.row)">编 辑
          </el-button>
 
          <el-button type="text"
                    size="small"
                    icon="icon-shangyi"
                    v-show="scope.row.secType == 'codeclassifysec' || scope.row.secType == 'codefixedsec' ? true:false"
                    plain
                    @click="openEdit(scope.row)">码值管理
          </el-button>
 
          <el-button type="text"
                    size="small"
                    icon="icon-shangyi"
                    v-show="scope.row.orderNum > 1 ? true:false"
                    plain
                    @click="upOrderNum(scope.row)">上 移
          </el-button>
          
          <el-button type="text"
                    size="small"
                    icon="icon-xiayi"
                    plain
                    @click="downOrderNum(scope.row)">下 移
          </el-button>
          
        </template>
 
        <!-- 基础码段表格左上方按钮区域 -->
        <template slot="menuLeft" slot-scope="scope">
          <el-button type="primary"
                    size="small"
                    icon="el-icon-plus"
                    @click="addBasicCodeSec">新 增
          </el-button>
          <el-button type="danger"
                    size="small"
                    icon="el-icon-delete"
                    plain
                    @click="deleteBasicCode(scope.row)">删 除
          </el-button>
        </template>
 
    </avue-crud>
    </basic-container>
 
     <!-- 基础编码规则对话框 @closed="closeRefresh"-->
     <el-dialog title="添加码段信息"
                    append-to-body
                    :visible.sync="addBasicCodeSettingBox"
                    width="780px"
                    style=" margin-top: -8vh;"
                    destroy-on-close>
        <add-basic-code ref='addBasicChild'></add-basic-code>
        <el-divider direction="horizontal"></el-divider>
        <div slot="footer" class="dialog-footer">
          <el-button @click="addBasicCodeSettingBox = false">取 消</el-button>
          <el-button type="primary" @click="saveBasicCode">保 存</el-button>
        </div>
      </el-dialog>
 
  </basic-container>
 
</template>
 
<script>
  import { gridCodeRule, getDetail, add, update, remove, listUseRange, updateStatus } from "@/api/code/mdmrule";
  import { gridCodeBasicSec, downOrderNum, upOrderNum, deleteData, editSave, getObjectByOid, listDataByOids, refDataGrid} from "@/api/code/codebasic";
  import optionBasic from "@/const/code/codebasic";
  import optionRule from "@/const/code/mdmrule";
  import {mapGetters} from "vuex";
 
export default {
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        currentCodeRuleOid: '',
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        //编码规则表格配置
        optionRule: optionRule,
 
        data: [],
 
        /*克隆按钮对话框控制*/
        cloneSettingBox: false,
        optionBasic: optionBasic,
 
        //基础码段展示
        basicData:[],
        loadingBasic: true,
        selectionBasicList: [],
        addBasicCodeSettingBox: false,
        
        /*使用范围对话框控制*/
        codeRangeSettingBox: false,
        useRangeData: [],
        dialogLoading: true,
        /*使用范围对话框*/
        dialogeOption: {
        height: 'auto',
        calcHeight: 30,
        tip: false,
        searchShow: false,
        searchMenuSpan: 6,
        border: true,
        index: true,
        disablePage:false,
        viewBtn: false,
        addBtn: false,
        menu: false,
        selection: false,
        dialogClickModal: false,
        align: 'center',
        dialogWidth: 400,
        column: [
          {
            label: "分类编号",
            prop: "id",
            span: 24
          },
          {
            label: "分类名称",
            prop: "name",
            span: 24,
          }
        ]
      },
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.codeRule_add, true),
          viewBtn: this.vaildData(this.permission.codeRule_view, false),
          delBtn: this.vaildData(this.permission.plCodeRule_delete, false),
          editBtn: this.vaildData(this.permission.codeRule_edit, true)
        };
      },
    },
    methods: {
 
      // 打开新增窗口
      addBasicCodeSec(){
        if(!this.tipsMessage(this.selectionList)){
          return;
        }
        if(this.selectionList[0].lcStatus != 'Editing'){
          this.$message.warning('编码规则状态不是"编辑中",不允许编辑码段!');
          return;
        }
        this.addBasicCodeSettingBox = true;
        this.$nextTick(() => {
          this.$refs.addBasicChild.loadCodeSecType();
        })
      },
      // 新增基础码段
      saveBasicCode(){
        if(this.selectionList[0].oid == null){
          this.$message.warning('缺失必要参数,请重新选择编码规则后重试!');
          return;
        }
        this.$refs.addBasicChild.addSave(this.selectionList[0].oid);
        // 关闭窗口
        this.addBasicCodeSettingBox = false
        // 点击新增基础码段之后关闭窗口之后触发重新加载
        this.loadBasic(this.selectionList[0]);
      },
      // 判断数据是否选择以及只能选择单条数据
      tipsMessage(list){
        if(list.length != 1){
          this.$message.warning("请选择一条编码规则数据!");
          return false;
        }
        return true;
      },
      // 基础码段删除
      deleteBasicCode(){
        if(!this.tipsMessage(this.selectionBasicList)){
          return;
        }
        let oid = this.selectionBasicList[0].oid;
        this.$confirm("是否删除这条数据?如果被引用将不能被删除!", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(() => {
          let ts = this.selectionBasicList[0].ts;
          return deleteData({"oid": oid,"ts": ts});
        })
        .then(() => {
          this.loadBasic({"oid":this.currentCodeRuleOid == null ? this.selectionList[0].oid:this.currentCodeRuleOid});
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          //this.$refs.crud.toggleSelection();
        });
      },
      // 点击触发加载基础码段信息
      loadBasic(row){
        this.loadingBasic = true;
        //console.log(row.oid);
        this.currentCodeRuleOid = row.oid;
        gridCodeBasicSec(1, -1, {"pkCodeRule":row.oid}).then(res => {
          const data = res.data.data;
          this.basicData = data.records;
          //console.log(this.basicData);
          this.loadingBasic = false;
        });
      },
      selectionBasicChange(list) {
        this.selectionBasicList = list;
        //console.log(this.selectionBasicList);
      },
      // 上移下移基础码段
      upOrderNum(row){
        //console.log(row.oid);
        if(!this.tipsMessage(this.selectionList)){
          return;
        }
        let codeRuleOid = this.selectionList[0].oid;
        if (this.selectionList[0].lcStatus != 'Editing') {
          this.$message.warning("只有编码规则的状态是 [编辑中] 的时候,才能调整码段顺序!");
          return; 
        }
        if(row.oid==null || row.oid==''){
          this.$message.warning("未获取到必填参数!");
          return;        
        }
        upOrderNum(row.oid).then(() => {
          this.loadBasic({"oid":codeRuleOid});
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        })
      },
      downOrderNum(row){
        //console.log(row.oid);
        if(!this.tipsMessage(this.selectionList)){
          return;
        }
        let codeRuleOid = this.selectionList[0].oid;
        //console.log(this.selectionList);
        if (this.selectionList[0].lcStatus != 'Editing') {
          this.$message.warning("只有编码规则的状态是 [编辑中] 的时候,才能调整码段顺序!");
          return; 
        }
        if(row.oid==null || row.oid==''){
          this.$message.warning("未获取到必填参数!");
          return;        
        }
        downOrderNum(row.oid).then(() => {
          this.loadBasic({"oid":codeRuleOid});
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        })
      },
      //基础码段查询
      refreshChangeBasicSec(){
        this.loadBasic({"oid":this.currentCodeRuleOid == null ? this.selectionList[0].oid:this.currentCodeRuleOid});
      },
      // 查询使用范围
      handleRange(){
        if(!this.tipsMessage(this.selectionList)){
          return;
        }
        this.codeRangeSettingBox = true;
        this.getRangeCodeList()
      },
      getRangeCodeList(){        
        this.dialogLoading = true;
        if(this.selectionList[0].oid==null){
          this.$message.error("未获取到参数!");
        }
 
        listUseRange(this.selectionList[0].oid).then(res => {
          this.useRangeData = res.data.data;
          //console.log(this.useRangeData);
          this.dialogLoading = false;
        });
      },
      refreshUseRangeChange(){
        this.getRangeCodeList();
      },
      // 启用与停用
      enableOrDeactivatse(oId,update){
        updateStatus({"oid":oId,"ts":new Date().getTime,"update":update}).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        }, error => {
          window.console.log(error);
        });
      },
      // 克隆
      cloneCodeSetting() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据!");
          return;
        }
        if (this.selectionList.length > 1) {
          this.$message.warning("每次只能选择一条数据!");
          return;
        }
        localStorage.setItem("cloneOid",this.selectionList[0].oid)
        this.cloneSettingBox = true;
      },
      // 添加
      rowSave(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      openEdit(row){
        this.$refs.crud.rowEdit(row,row.$index);
      },
      // 修改
      rowUpdate(row, index, done, loading) {
        row.ts = new Date().getTime;
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          console.log(error);
        });
      },
      // 删除
      handleDelete() {
        if(!this.tipsMessage(this.selectionList)){
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            // 只支持每次单条记录删除
            let oid = this.selectionList[0].oid;
            let ts = this.selectionList[0].ts;
            return remove({oid: oid,ts: ts});
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      // 打开修改
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.oid).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
        if(this.selectionList.length > 0){
          this.currentCodeRuleOid = this.selectionList [list.length-1];
          this.loadBasic(this.selectionList[list.length-1]);
        }
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        gridCodeRule(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          //console.log(res);
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.loadBasic(data.records[0])
          this.selectionClear();
        });
      }
    }
  };
</script>
 
<style>
 
  .el-divider--horizontal {
      margin-top: 19px !important;
      margin-bottom: -20px !important;
      height: 2px;
      margin: 0;
  }
 
 
</style>