干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2024-12-11 7c585586e9bea943161676bd9d127e81123891c3
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
<#include "/common/utils.ftl">
<#list subTables as sub>
<#if sub.foreignRelationType=='1'>
#segment#${sub.entityName}Form.vue
<#include "/common/utils.ftl">
<#assign need_category = false>
<#assign bpm_flag=false>
<#assign need_pca = false>
<#assign need_search = false>
<#assign need_dept_user = false>
<#assign need_switch = false>
<#assign need_dept = false>
<#assign need_multi = false>
<#assign need_popup = false>
<#assign need_select_tag = false>
<#assign need_select_tree = false>
<#assign need_time = false>
<#assign need_markdown = false>
<#assign need_upload = false>
<#assign need_image_upload = false>
<#assign need_editor = false>
<#assign need_checkbox = false>
<#assign form_span = 24>
<#if tableVo.fieldRowNum==2>
  <#assign form_span = 12>
<#elseif tableVo.fieldRowNum==3>
  <#assign form_span = 8>
<#elseif tableVo.fieldRowNum==4>
  <#assign form_span = 6>
</#if>
  <#assign hasOnlyValidate = false>
<template>
  <a-spin :spinning="loading">
    <a-form v-bind="formItemLayout">
      <a-row>
        <#list sub.colums as po>
          <#if po.isShow == 'Y' && po.fieldValidType?default("") == 'only'>
            <#assign hasOnlyValidate = true>
          </#if>
          <#if po.fieldDbName=='bpm_status'>
            <#assign bpm_flag=true>
          </#if>
          <#include "/common/form/native/vue3NativeForm.ftl">
        </#list>
      </a-row>
    </a-form>
  </a-spin>
</template>
 
<script lang="ts">
  import { defineComponent, ref, reactive, toRaw } from 'vue';
  import { query${sub.entityName}ListByMainId } from '../${entityName}.api';
<#include "/common/form/native/vue3NativeImport.ftl">
<#if hasOnlyValidate == true>
  import { duplicateValidate } from '/@/utils/helper/validator'
</#if>
  import { useMessage } from '/@/hooks/web/useMessage';
  import { Form } from 'ant-design-vue';
  const useForm = Form.useForm;
 
  export default defineComponent({
    name: '${sub.entityName}Form',
    components:{
    <#include "/common/form/native/vue3NativeComponents.ftl">
    },
    props:{
      disabled:{
        type: Boolean,
        default: false
      }
    },
    setup(){
      const { createMessage } = useMessage();
      const isForm = true;
      const loading = ref(false);
      const formData = reactive<Record<string, any>>({
        id: '',
    <#list sub.colums as po>
    <#if po.isShow == 'Y'>
        ${po.fieldName}: '',
    </#if>
    </#list>
      });
      //表单验证
      const validatorRules = reactive({
    <#list sub.colums as po>
    <#if po.isShow == 'Y' && poHasCheck(po)>
        ${po.fieldName}: [<#include "/common/validatorRulesTemplate/native/vue3CoreNative.ftl">],
    </#if>
    </#list>
      })
      const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, {immediate: true});
      const formItemLayout = {
        labelCol: { xs: { span: 24 }, sm: { span: 5 } },
        wrapperCol: { xs: { span: 24 }, sm: { span: 16 } },
      };
 
      async function initFormData(mainId) {
        resetFields();
        if(mainId){
          let list = await query${sub.entityName}ListByMainId(mainId);
          if(list && list.length>0){
            let temp = list[0];
            Object.keys(temp).map(k=>{
              formData[k] = temp[k];
            })
          }
        }
      }
 
      async function getFormData() {
        await validate();
        let subFormData = toRaw(formData);
        if(Object.keys(subFormData).length>0){
          return subFormData
        }
        return false;
      }
 
      function setFieldsValue(values) {
        if(values){
          Object.keys(values).map(k=>{
            formData[k] = values[k];
          });
        }
      }
 
      /**
       * 值改变事件触发-树控件回调
       * @param key
       * @param value
       */
      function handleFormChange(key, value) {
        formData[key] = value;
      }
 
    <#list sub.colums as po>
    <#if po.isShow == 'Y' && po.fieldValidType?default("") == 'only'>
      async function ${po.fieldName}Duplicatevalidate(_r, value) {
        return duplicateValidate('${sub.tableName}', '${po.fieldDbName}', value, formData.id || '')
      }
    </#if>
    </#list>
 
      return {
        loading,
        formData,
        formItemLayout,
        initFormData,
        getFormData,
        setFieldsValue,
        handleFormChange,
        isForm,
        validateInfos
      }
    }
  });
</script>
</#if>
</#list>