田源
2024-09-06 bf70f3cf825f44c457dba2bebd26e7af73e4b2a8
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
<template>
  <el-dialog
    :close-on-click-modal="false"
    :visible.sync="cloneOtherCodeRuleSettingBox"
    append-to-body
    class="avue-dialog avue-dialog--top"
    style="height: 100vh"
    @close="closeCloneOtherBasicSecDialog"
    title="克隆编码规则的基础信息"
    top="-3%"
    width="800px">
    <div>
      <el-row>
        <p
          style="margin-top: -20px;
            margin-bottom: 4px;
            font-weight: 570;
            font-size: 19px;
            color: #0e2d5f;">
          编码规则
        </p>
        <avue-crud
          ref="crudCloneCodeRuleOther"
          :data="codeRuleData"
          :option="cloneCodeRuleOption"
          :page.sync="codeRulePage"
          :table-loading="codeRuleloading"
          class="other-clone-coderule-crud"
          @row-click="codeOtherCloneRuleRowClick"
          @selection-change="selectionOtherCloneCodeRuleChange"
          @search-change="searchOtherCloneChange"
          @search-reset="searchOtherCloneReset"
          @on-load="onLoad">
          <template #radio="{row}">
            <el-radio v-model="selectOtherCodeRuleRowIndex"
                :label="row.$index">&nbsp;</el-radio>
          </template>
        </avue-crud>
      </el-row>
      <el-row style="margin-top: 10px; border-top: 1px solid #ebeef5">
        <p
          style="
            margin-top: 10px;
            margin-bottom: 4px;
            font-weight: 570;
            font-size: 19px;
            color: #0e2d5f;
          "
        >
          码段信息
        </p>
        <avue-crud
          ref="crudCloneCodeBasicOther"
          :data="cloneBasicData"
          :option="cloneBasicOption"
          :table-loading="codeBasicloading"
          class="other-clone-codebasic-crud"
          @row-click="codeOtherCloneBasicRowClick"
          @selection-change="selectionOtherCloneCodeBasicChange">
        </avue-crud>
      </el-row>
    </div>
    <div slot="footer" class="dialog-footer" style="height: 50px">
      <el-button type="primary" @click="saveOtherCodeBasic" :loading="cloneSaveLoding">保 存</el-button>
      <el-button @click="cloneOtherCodeRuleSettingBox = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import cloneBasicOption from "@/const/code/cloneBasicDialogOption";
import cloneCodeRuleOption from "@/const/code/cloneCodeRuleDialogOption";
import {gridCodeRule} from "@/api/code/mdmrule";
import {gridCodeBasicSec,cloneCodeBasic} from "@/api/code/codebasic";
export default {
    name: "cloneRuleDialog",
    props: {
        // 对话框显示隐藏控制
        visible: {
            type: "Boolean",
            default: false,
        },
        // 被克隆的规则oid
        quiltCloneCodeRule:{
            type: "Object",
        }
    },
    data() {
        return {
            cloneOtherCodeRuleSettingBox: this.visible, 
            /*克隆编码规则对话框控制变量*/
            cloneBasicOption: cloneBasicOption,
            cloneCodeRuleOption: cloneCodeRuleOption,
            selectionOtherCloneCodeBasicList: [], // 此界面内当前选中的基础码段
            selectionOtherCloneCodeRuleList: {}, // 此界面内当前选中的编码规则
            selectOtherCodeRuleRowIndex: '',
            cloneOtherQuery: {}, // 查询条件对象
            codeRulePage: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            codeRuleloading: false,
            codeRuleData: [],
            codeBasicloading: false,
            cloneBasicData: [],
            cloneSaveLoding: false,
        };
    },
    watch: {
        // 监听父组件传的窗口显示隐藏的值,以及值的回填
        visible() {
            //console.log(this.visible);
            if(this.visible){
                //console.log(this.quiltCloneCodeRule);
                let conditionMap = {};
                conditionMap["conditionMap[oid_notequal]"] = this.quiltCloneCodeRule.oid.trim();
                this.cloneOtherQuery = conditionMap;
                this.onLoad(this.codeRulePage);
            }else{
                this.codeRuleData = [];
                this.cloneBasicData = [];
            }
            this.cloneOtherCodeRuleSettingBox = this.visible;
        },
        selectionOtherCloneCodeRuleList(){
            this.loadBasic(this.selectionOtherCloneCodeRuleList);
        },
    },
    methods: {
 
        //关闭窗口时触发
        closeCloneOtherBasicSecDialog(){
            this.$emit('update:visible',false);
        },
        /** 从其他编码规则中克隆码段对话框-单击编码规则实现行选择*/
        codeOtherCloneRuleRowClick(row) {
            this.selectOtherCodeRuleRowIndex = row.$index
            this.selectionOtherCloneCodeRuleList = row;
            this.loadBasic(row);
        },
        /** 从其他编码规则中克隆码段对话框-单击基础码段实现行选择*/
        codeOtherCloneBasicRowClick(row) {
            this.$refs.crudCloneCodeBasicOther.toggleSelection();
            this.selectionOtherCloneCodeBasicList = row;
            this.$refs.crudCloneCodeBasicOther.setCurrentRow(row);
            this.$refs.crudCloneCodeBasicOther.toggleRowSelection(row); //选中当前行
        },
        selectionOtherCloneCodeBasicChange(list) {
            this.selectionOtherCloneCodeBasicList = list;
            this.$refs.crudCloneCodeBasicOther.setCurrentRow(
                this.selectionOtherCloneCodeBasicList.slice(-1)[0]
            );
        },
        /** 从其他规则克隆码段界面重置搜索功能 */
        searchOtherCloneReset() {
            let conditionMap = {};
            conditionMap["conditionMap[oid_notequal]"] = this.quiltCloneCodeRule.oid.trim();
            this.cloneOtherQuery = conditionMap;
            this.onLoad(this.codeRulePage);
        },
        /** 从其他规则克隆码段界面搜索功能*/
        searchOtherCloneChange(params, done) {
            this.codeRulePage.currentPage = 1;
            // 多个conditionMap这样传参,快速查询默认采用模糊查询
            if (params) {
                Object.keys(params).forEach((key) => {
                    this.cloneOtherQuery["conditionMap" + "[" + key + "_like]"] =
                    params[key].trim();
                });
            }
            this.onLoad(this.codeRulePage,this.cloneOtherQuery);
            done();
        },
        /** 保存从其他编码规则中克隆码段信息*/
        async saveOtherCodeBasic() {
            let oid = this.quiltCloneCodeRule.oid;
            let fromDialogPkCodebasic = this.selectionOtherCloneCodeBasicList;
            if (fromDialogPkCodebasic.length <= 0) {
                this.$message.warning("请选择码段数据!");
                return;
            }
            this.cloneSaveLoding = true;
            let oidArr = [];
            fromDialogPkCodebasic.forEach((ele) => {
                oidArr.push(ele.oid);
            });
            let data = {
                pkCodeRule: oid,
                oidArr: oidArr.join(","),
            };
            //console.log(data);
            await cloneCodeBasic(data).then( () => {
                this.cloneOtherCodeRuleSettingBox = false;
                this.$message({
                    type: "success",
                    message: "操作成功!",
                });
                // 调用父组件方法重新加载码段表
                this.$emit('refreshRuleTable',{"currentPage":1,"pageSize":10});
            },(error) => {
                window.console.log(error);
            });
            this.cloneSaveLoding = false;
        },
        /** 点击触发加载基础码段信息*/
        loadBasic(row) {
            this.codeBasicloading = true;
            // console.log(row)
            if (row != "" && row != null && row !="undefined") {
                let conditionMap = {};
                conditionMap["conditionMap[pkCodeRule]"] = row.oid.trim();
                gridCodeBasicSec(1, -1, conditionMap).then((res) => {
                    const data = res.data.data;
                    this.cloneBasicData = data.records;
                    this.codeBasicloading = false;
                });
            }else {
                this.cloneBasicData = [];
                this.codeBasicloading = false;
            }
        },
        // 规则表格相关方法
        onLoad(page, params = {}) {
            this.codeRuleloading = true;
            gridCodeRule(page.currentPage, page.pageSize, Object.assign({},this.cloneOtherQuery, params)).then((res) => {
                // console.log(res.data);
                const data = res.data.data;
                this.codeRulePage.total = data.total;
                this.codeRuleData = data.records;
                this.codeRuleloading = false;
                if(this.codeRuleData.length > 0) {
                    this.$nextTick(() => {
                        this.selectOtherCodeRuleRowIndex = this.codeRuleData[0].$index
                        this.selectionOtherCloneCodeRuleList = this.codeRuleData[0];
                    });
                }else{
                    this.cloneBasicData = [];
                }
            });
        },
 
    }
};
</script>
 
<style>
</style>