ludc
2023-09-13 13f2d9d9b067d571f37fc14fe8ea4399eaad2547
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
<template>
  <el-dialog
      :close-on-click-modal="false"
      :visible.sync="cloneSettingBox"
      append-to-body
      class="avue-dialog avue-dialog--top"
      style="height: 100vh"
      title="克隆编码规则"
      top="-3%"
      @close="closeCloneDialog"
      width="800px">
      <div>
        <el-row>
          <el-form ref="form" :inline="true" :model="form" label-width="80px">
            <el-form-item label="编号" required>
              <el-input v-model="cloneCodeRuleForm.id"></el-input>
            </el-form-item>
            <el-form-item label="名称" required>
              <el-input v-model="cloneCodeRuleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="依据" required>
              <el-input v-model="cloneCodeRuleForm.accordingTo"></el-input>
            </el-form-item>
            <el-form-item class="clone-input-textarea" label="描述">
              <el-input
                v-model="cloneCodeRuleForm.description"
                :autosize="{ minRows: 3, maxRows: 5 }"
                type="textarea"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-row>
        <el-row>
          <p
            style="
              margin: 0 0px 16px 50%;
              font-weight: 500;
              font-size: 20px;
              color: #000;">
            码段管理
          </p>
          <avue-crud
            :data="cloneData"
            :option="cloneOption"
            :table-loading="cloneTableLoading"
            class="clone-avue-crud">
            <template slot="menu" slot-scope="scope">
              <el-button
                v-show="scope.row.orderNum > 1"
                icon="el-icon-arrow-up"
                plain
                size="small"
                type="text"
                @click="upOrderNum(scope.row)"
                >上移
              </el-button>
              <el-button
                icon="el-icon-arrow-down"
                plain
                size="small"
                type="text"
                @click="downOrderNum(scope.row)"
                >下移
              </el-button>
            </template>
          </avue-crud>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveCloneCodeRule" :loading="cloneCodeRuleLoading">保 存</el-button>
        <el-button @click="cloneSettingBox = false">取 消</el-button>
      </div>
  </el-dialog>
</template>
 
<script>
import cloneOption from "@/const/code/cloneOption";
import {clone} from "@/api/code/mdmrule";
import {downOrderNum, upOrderNum, gridCodeBasicSec} from "@/api/code/codebasic";
export default {
    name: "cloneRuleDialog",
    props: {
        // 对话框显示隐藏控制
        visible: {
            type: "Boolean",
            default: false,
        },
        ruleData:{
            type: "Object",
        }
    },
    data() {
        return {
            cloneSettingBox: this.visible, 
            /*克隆编码规则对话框控制变量*/
            cloneTableLoading: false,
            cloneCodeRuleLoading: false,
            cloneOption: cloneOption,
            cloneData: [],
            cloneCodeRuleForm: {
                id: "",
                name: "",
                accordingTo: "",
                description: "",
            },
        };
    },
    watch: {
        // 监听父组件传的窗口显示隐藏的值,以及值的回填
        visible() {
            //console.log(this.visible);
            if(this.visible){
                this.loadBasic(this.ruleData);
                this.cloneCodeRuleForm.id = this.ruleData.id;
                this.cloneCodeRuleForm.name = this.ruleData.name;
                this.cloneCodeRuleForm.accordingTo = this.ruleData.accordingTo;
                this.cloneCodeRuleForm.description = this.ruleData.description;
            }
            this.cloneSettingBox = this.visible;
        },
    },
    methods: {
 
        //关闭对话框
        closeCloneDialog(){
            this.$emit('update:visible',false);
            this.cloneData = [];
        },    
        /** 上移下移基础码段*/
        async upOrderNum(row) {
            if (this.ruleData.lcStatus != "Editing") {
                this.$message.warning(
                "只有编码规则的状态是 [编辑中] 的时候,才能调整码段顺序!"
                );
                return;
            }
            if (row.oid == null || row.oid == "") {
                this.$message.warning("未获取到必填参数!");
                return;
            }
            await upOrderNum(row.oid).then(() => {
                this.loadBasic(this.ruleData);
                this.$message({
                type: "success",
                message: "操作成功!",
                });
            });
        },
        downOrderNum(row) {
            let codeRuleOid = this.ruleData.oid;
            if (this.ruleData.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: "操作成功!",
                });
            });
        },
        /** 点击触发加载基础码段信息*/
        loadBasic(row) {
            this.cloneTableLoading = true;
            if (row != "" || row != null) {
                let conditionMap = {};
                conditionMap["conditionMap[pkCodeRule]"] = row.oid.trim();
                gridCodeBasicSec(1, -1, conditionMap).then((res) => {
                    const data = res.data.data;
                    this.cloneData = data.records;
                    this.cloneTableLoading = false;
                });
            }
        },
         /** 克隆编码规则保存功能*/
        saveCloneCodeRule() {
            this.cloneCodeRuleLoading = true;
            let form = this.cloneCodeRuleForm;
            if (form.id.trim() == "") {
                this.$message.warning("编号不能为空!");
                return;
            }
            if (form.name.trim() == "") {
                this.$message.warning("码值不能为空!");
                return;
            }
            let data = Object.assign({}, form, {
                oid: "",
                createTime: new Date().getTime(),
                ts: new Date(this.ruleData.ts).getTime(),
                lcStatus: "Editing",
                elements: this.cloneData,
            });
            // console.log(data);
            this.cloneCodeRuleLoading = true;
            clone(data).then(() => {
                this.cloneSettingBox = false;
                // 调用父组件方法重新加载码段表
                this.$emit('refreshRuleTable',{"currentPage":1,"pageSize":10});
                this.$message({
                    type: "success",
                    message: "操作成功!",
                });
            },
            (error) => {
                window.console.log(error);
            });
        },
 
    }
}
</script>
 
<style>
 
</style>