inleft
2022-02-15 d734432a8bbbf863dc3de305f56e831c56ac767a
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
<template>
  <a-modal
    title="新增${functionName}"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
#foreach ($column in $tableField)
#if (${column.columnKey} != "PRI")
#if (${column.whetherAddUpdate} == "Y")
#if (${column.effectType} == 'select' || ${column.effectType} == 'radio' || ${column.effectType} == 'checkbox')
        <a-form-item
          label="${column.columnComment}"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
#else
        <a-form-item
          label="${column.columnComment}"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
#end
#if (${column.effectType} == "user")
#if (${column.whetherRequired} == "Y")
          <user-select placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" />
#else
          <user-select placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}']" />
#end
#end
#if (${column.effectType} == "depart")
#if (${column.whetherRequired} == "Y")
          <depart-select placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" />
#else
          <depart-select placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}']" />
#end
#end
#if (${column.effectType} == "input")
#if (${column.whetherRequired} == "Y")
          <a-input placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" />
#else
          <a-input placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}']" />
#end
#end
#if (${column.effectType} == "textarea")
#if (${column.whetherRequired} == "Y")
          <a-textarea placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" :auto-size="{ minRows: 3, maxRows: 6 }"/>
#else
          <a-textarea placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}']" :auto-size="{ minRows: 3, maxRows: 6 }"/>
#end
#end
#if (${column.effectType} == "inputnumber")
#if (${column.whetherRequired} == "Y")
          <a-input-number placeholder="请输入${column.columnComment}" style="width: 100%" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" />
#else
          <a-input-number placeholder="请输入${column.columnComment}" style="width: 100%" v-decorator="['${column.javaName}']" />
#end
#end
#if (${column.effectType} == "select")
#if (${column.whetherRequired} == "Y")
          <a-select style="width: 100%" placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{ required: true, message: '请选择${column.columnComment}!' }]}]">
            <a-select-option v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
#else
          <a-select style="width: 100%" placeholder="请选择${column.columnComment}">
            <a-select-option v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
#end
#end
#if (${column.effectType} == "radio")
#if (${column.whetherRequired} == "Y")
          <a-radio-group placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}',{rules: [{ required: true, message: '请选择${column.columnComment}!' }]}]" >
            <a-radio v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-radio>
          </a-radio-group>
#else
          <a-radio-group placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}']" >
            <a-radio v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-radio>
          </a-radio-group>
#end
#end
#if (${column.effectType} == "checkbox")
#if (${column.whetherRequired} == "Y")
          <a-checkbox-group placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}',{rules: [{ required: true, message: '请选择${column.columnComment}!' }]}]" >
            <a-checkbox v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-checkbox>
          </a-checkbox-group>
#else
          <a-checkbox-group placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}']" >
            <a-checkbox v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-checkbox>
          </a-checkbox-group>
#end
#end
#if (${column.effectType} == "datepicker")
#if (${column.whetherRequired} == "Y")
          <a-date-picker style="width: 100%" placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}',{rules: [{ required: true, message: '请选择${column.columnComment}!' }]}]" @change="${column.javaName}OnChange"/>
#else
          <a-date-picker style="width: 100%" placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}']" @change="${column.javaName}OnChange"/>
#end
#end
        </a-form-item>
#end
#end
#end
      </a-form>
    </a-spin>
  </a-modal>
</template>
 
<script>
  import { ${className}Add } from '@/api/modular/main/${busName}/${className}Manage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
#foreach ($column in $tableField)
#if (${column.whetherAddUpdate} == "Y")
#if (${column.dictTypeCode})
#if(${column.effectType} == 'select' || ${column.effectType} == 'radio' || ${column.effectType} == 'checkbox')
        ${column.javaName}Data: [],
#end
#end
#if (${column.effectType} == "datepicker")
        ${column.javaName}DateString: '',
#end
#end
#end
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
#foreach ($column in $tableField)
#if (${column.dictTypeCode})
#if(${column.effectType} == 'select' || ${column.effectType} == 'radio' || ${column.effectType} == 'checkbox')
        const ${column.javaName}Option = this.$options
        this.${column.javaName}Data = ${column.javaName}Option.filters['dictData']('${column.dictTypeCode}')
#end
#end
#end
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object' && values[key] != null) {
                values[key] = JSON.stringify(values[key])
              }
            }
#foreach ($column in $tableField)
#if (${column.whetherAddUpdate} == "Y")
#if (${column.effectType} == "datepicker")
            values.${column.javaName} = this.${column.javaName}DateString || null
#end
#end
#end
            ${className}Add(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败')// + res.message
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
#foreach ($column in $tableField)
#if (${column.whetherAddUpdate} == "Y")
#if (${column.effectType} == "datepicker")
      ${column.javaName}OnChange(date, dateString) {
        this.${column.javaName}DateString = dateString
      },
#end
#end
#end
      handleCancel () {
#foreach ($column in $tableField)
#if (${column.whetherAddUpdate} == "Y")
#if (${column.effectType} == "datepicker")
        this.${column.javaName}DateString =''
        this.form.getFieldDecorator('${column.javaName}', { initialValue: null })
#end
#end
#end
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>