fujunling
2023-06-15 bf241556867635a57f5849ba19cd0135e90e8e81
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
<template>
  <el-dialog
    :visible.sync="dialogVisible"
    v-if="dialogVisible"
    v-dialogDrag
    top="0vh"
    :title="title"
    class="avue-dialog avue-dialog--top"
    :width="width"
    append-to-body
    @opened="openDialog"
  >
    <FormTempalte
      v-bind="$attrs"
      :visible="visible"
      :type="type"
      :rowOid="rowOid"
      :templateOid="templateOid"
      ref="FormTempalte"
      @getFormData="getFormData"
    ></FormTempalte>
 
    <div
      class="tab_box"
      v-if="
        type !== 'detail' &&
        dialogVisible &&
        (showCodeApply || showResembleQuery) &&
        type !== 'preview'
      "
    >
      <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
        <el-tab-pane label="码值申请" name="codeApply" v-if="showCodeApply">
          <FormTempalte
            v-bind="$attrs"
            :type="type"
            :selfColumnType="selfColumnType"
            :selfColumnConfig="selfColumnConfig"
            ref="CodeApply"
            @getFormData="getFormData"
          ></FormTempalte>
        </el-tab-pane>
        <el-tab-pane
          label="相似项查询"
          name="resembleQuery"
          v-if="showResembleQuery"
        >
          <ResembleQuery
            v-bind="$attrs"
            ref="resembleQueryRef"
            :hasResemble="this.hasResemble"
            :column="this.resembleTableColumn"
            :codeClassifyOid="codeClassifyOid"
            :form="this.form"
            :templateOid="templateOid"
          ></ResembleQuery>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="avue-dialog__footer" v-if="type !== 'detail'">
      <el-button @click="close()">取 消</el-button>
      <el-button @click="submit()" type="primary" :loading="submitBtnLoading"
        >{{ submitText }}</el-button
      >
      <el-button
        @click="resembleQuerySubmit"
        type="primary"
        v-if="showResembleQuery"
        >相似像查询</el-button
      >
    </div>
  </el-dialog>
</template>
 
<script>
import { getCodeRule, getFormTemplate } from "@/api/formTemplate.js";
import FormTempalte from "./FormTempalte";
import ResembleQuery from "./ResembleQuery";
export default {
  name: "FormTemplateDialog",
  components: { ResembleQuery, FormTempalte },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: "add",
    },
    title: {
      type: String,
      default: "编码申请",
    },
    width: {
      type: String,
      default: "80%",
    },
    rowOid: "",
    codeClassifyOid: {
      type: String,
      default: "",
    },
    templateOid: {
      type: String,
      default: "",
    },
    submitText: {
      type: String,
      default: '确 定'
    }
  },
  data() {
    return {
      loading: false,
      submitBtnLoading: false,
      hasResemble: false,
      resembleTableColumn: [],
      secVOList: [],
      form: {},
      activeName: "codeApply",
      showCodeApply: true,
      showResembleQuery: true,
      selfColumnType: {
        codefixedsec: "combox",
        codeclassifysec: "refer",
        codevariablesec: "text",
        coderefersec: "refer",
      },
      selfColumnConfig: {
        function: {
          required: this.isRequired,
          dicData: this.getOptionList,
          type: this.getType,
        },
        exchange: {
          text: "name",
          field: "oid",
          prop: "oid",
          showField: "name",
          parentClassifySecOid: "parentClassifySecOid",
          label: "name",
          maxlength: "codeSecLength",
          data: "fixedValueVOList",
        },
        directVoluation: {
          search: true,
          props: {
            label: "id",
            value: "id",
          },
        },
      },
    };
  },
  created() {},
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("update:visible", val);
      },
    },
  },
  methods: {
    openDialog() {
      this.getFormTemplate();
      if (this.type === 'add') {
        this.getCodeRule();
      }
    },
    close() {
      this.dialogVisible = false;
    },
    // 接口获取表单数据
    getFormTemplate() {
      getFormTemplate({
        templateOid: this.templateOid,
        codeClassifyOid: this.codeClassifyOid,
      })
        .then((res) => {
          if (res.status === 200) {
            this.hasResemble =
              res.data.resembleTableVO &&
              res.data.resembleTableVO.cols &&
              res.data.resembleTableVO.cols.length > 0;
            this.resembleTableColumn = res.data.resembleTableVO.cols || [];
            if (this.hasResemble) {
              this.activeName = 'resembleQuery'
              this.showResembleQuery = true
            }
            this.$refs.FormTempalte.templateRender(res.data.formDefineVO.items);
          }
        })
        .catch((err) => {
          this.loading = false;
          console.log(err);
        });
    },
    // 获取码值申请数据
    getCodeRule() {
      getCodeRule({ codeClassifyOid: this.codeClassifyOid }).then((res) => {
        if (res.data && res.data.code === 200) {
          const typeList = [
            "codefixedsec",
            "codeclassifysec",
            "codevariablesec",
            "coderefersec",
          ];
          this.secVOList = (res.data.data.secVOList || []).filter((item) =>
            typeList.includes(item)
          );
          this.$nextTick(() => {
            if (this.secVOList.length > 0 && this.type === 'add') {
              this.showCodeApply = true
              this.activeName = 'codeApply'
              this.$refs.CodeApply.templateRender(this.secVOList);
            } else {
              this.showCodeApply = false
            }
          });
        }
      });
    },
    getFormData(form) {
      this.form = form;
    },
    resembleQuerySubmit() {
      this.activeName = "resembleQuery";
      this.$refs.resembleQueryRef.resembleQuery(this.form);
    },
    handleClick() {
      if (this.activeName === "resembleQuery") {
        this.resembleQuerySubmit();
      }
    },
    async submit() {
      // 进行表单校验
      const formValidate = await this.$refs.FormTempalte.validate();
      if (!formValidate) return;
      let codeValidate = true;
      // 进行码值申请校验
      if (this.showCodeApply) {
        codeValidate = await this.$refs.codeApply.validate();
        if (!codeValidate) return;
      }
      // 进行相似项查询
      const resembleQueryList = await this.$refs.resembleQueryRef.resembleQuery(
        this.form
      );
      if (resembleQueryList.length === 0) {
        this.$emit("submit", this.form);
      } else {
        this.$confirm(
          `该物料已有${resembleQueryList.length}条相似数据,是否继续保存?`,
          "需要您确认",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(() => {
            this.$emit("submit", this.form);
          })
          .catch(() => {});
      }
    },
    getType(item) {
      return this.selfColumnType[item.sectype];
    },
    isRequired(item) {
      return item.nullableFlag != "true";
    },
    getOptionList(item) {
      if (
        Array.isArray(item.fixedValueVOList) &&
        item.fixedValueVOList.length > 0
      ) {
        const configAttr = {
          key: "id",
          value: "id",
        };
        const optionList = item.fixedValueVOList.map((item) => {
          for (const key in configAttr) {
            if (Object.hasOwnProperty.call(configAttr, key)) {
              const element = configAttr[key];
              item[key] = item[element];
            }
          }
          return item;
        });
        return optionList;
      } else {
        return [];
      }
    },
  },
};
</script>
 
<style lang="scss" scoped>
.key_attr_icon {
  font-size: 24px;
  position: relative;
  top: 2px;
  color: red;
}
// 解决swich组件不垂直居中的问题
/deep/ .el-switch {
  vertical-align: baseline;
}
</style>