inleft
2022-03-02 34223b096cf6ad9d92c3702bb9529e764f523b11
commit | author | age
9bcb19 1 <template>
I 2   <a-modal
3     title="编辑${functionName}"
4     :width="900"
5     :visible="visible"
6     :confirmLoading="confirmLoading"
7     @ok="handleSubmit"
8     @cancel="handleCancel"
9   >
10     <a-spin :spinning="confirmLoading">
11       <a-form :form="form">
12 #foreach ($column in $tableField)
13 #if(${column.columnKey} == "PRI")
14         <a-form-item v-show="false"><a-input v-decorator="['${column.javaName}']" /></a-form-item>
15 #else
16 #if (${column.whetherAddUpdate} == "Y")
17 #if (${column.effectType} == 'select' || ${column.effectType} == 'radio' || ${column.effectType} == 'checkbox')
18         <a-form-item
19           label="${column.columnComment}"
20           :labelCol="labelCol"
21           :wrapperCol="wrapperCol"
22         >
23 #else
24         <a-form-item
25           label="${column.columnComment}"
26           :labelCol="labelCol"
27           :wrapperCol="wrapperCol"
28           has-feedback
29         >
30 #end
31 #if (${column.effectType} == "user")
32 #if (${column.whetherRequired} == "Y")
33           <user-select placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" />
34 #else
35           <user-select placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}']" />
36 #end
37 #end
38 #if (${column.effectType} == "depart")
39 #if (${column.whetherRequired} == "Y")
40           <depart-select placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" />
41 #else
42           <depart-select placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}']" />
43 #end
44 #end
45 #if (${column.effectType} == "input")
46 #if (${column.whetherRequired} == "Y")
47           <a-input placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" />
48 #else
49           <a-input placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}']" />
50 #end
51 #end
52 #if (${column.effectType} == "textarea")
53 #if (${column.whetherRequired} == "Y")
54           <a-textarea placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" :auto-size="{ minRows: 3, maxRows: 6 }"/>
55 #else
56           <a-textarea placeholder="请输入${column.columnComment}" v-decorator="['${column.javaName}']" :auto-size="{ minRows: 3, maxRows: 6 }"/>
57 #end
58 #end
59 #if (${column.effectType} == "inputnumber")
60 #if (${column.whetherRequired} == "Y")
61           <a-input-number placeholder="请输入${column.columnComment}" style="width: 100%" v-decorator="['${column.javaName}', {rules: [{required: true, message: '请输入${column.columnComment}!'}]}]" />
62 #else
63           <a-input-number placeholder="请输入${column.columnComment}" style="width: 100%" v-decorator="['${column.javaName}']" />
64 #end
65 #end
66 #if (${column.effectType} == "select")
67 #if (${column.whetherRequired} == "Y")
68           <a-select style="width: 100%" placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}', {rules: [{ required: true, message: '请选择${column.columnComment}!' }]}]">
69             <a-select-option v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
70           </a-select>
71 #else
72           <a-select style="width: 100%" placeholder="请选择${column.columnComment}">
73             <a-select-option v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
74           </a-select>
75 #end
76 #end
77 #if (${column.effectType} == "radio")
78 #if (${column.whetherRequired} == "Y")
79           <a-radio-group placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}',{rules: [{ required: true, message: '请选择${column.columnComment}!' }]}]" >
80             <a-radio v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-radio>
81           </a-radio-group>
82 #else
83           <a-radio-group placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}']" >
84             <a-radio v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-radio>
85           </a-radio-group>
86 #end
87 #end
88 #if (${column.effectType} == "checkbox")
89 #if (${column.whetherRequired} == "Y")
90           <a-checkbox-group placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}',{rules: [{ required: true, message: '请选择${column.columnComment}!' }]}]" >
91             <a-checkbox v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-checkbox>
92           </a-checkbox-group>
93 #else
94           <a-checkbox-group placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}']" >
95             <a-checkbox v-for="(item,index) in ${column.javaName}Data" :key="index" :value="item.code">{{ item.name }}</a-checkbox>
96           </a-checkbox-group>
97 #end
98 #end
99 #if (${column.effectType} == "datepicker")
100 #if (${column.whetherRequired} == "Y")
101           <a-date-picker style="width: 100%" placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}',{rules: [{ required: true, message: '请选择${column.columnComment}!' }]}]" @change="${column.javaName}OnChange"/>
102 #else
103           <a-date-picker style="width: 100%" placeholder="请选择${column.columnComment}" v-decorator="['${column.javaName}']" @change="${column.javaName}OnChange"/>
104 #end
105 #end
106         </a-form-item>
107 #end
108 #end
109 #end
110       </a-form>
111     </a-spin>
112   </a-modal>
113 </template>
114
115 <script>
116 #set ($editData = 0)
117 #foreach ($column in $tableField)
118 #if (${column.whetherAddUpdate} == "Y")
119 #if (${column.effectType} == "datepicker")
120 #set ($DateQuery="Y")
121 #end
122 #if(${column.columnKey} != "PRI")
123 #if(${column.effectType} != "datepicker")
124 #set ($editData = $editData+1)
125 #end
126 #end
127 #end
128 #end
129 #if($DateQuery == "Y")
130   import moment from 'moment'
131 #end
132   import { ${className}Edit } from '@/api/modular/main/${busName}/${className}Manage'
133   export default {
134     data () {
135       return {
136         labelCol: {
137           xs: { span: 24 },
138           sm: { span: 5 }
139         },
140         wrapperCol: {
141           xs: { span: 24 },
142           sm: { span: 15 }
143         },
144 #foreach ($column in $tableField)
145 #if (${column.whetherAddUpdate} == "Y")
146 #if (${column.dictTypeCode})
147 #if(${column.effectType} == 'select' || ${column.effectType} == 'radio' || ${column.effectType} == 'checkbox')
148         ${column.javaName}Data: [],
149 #end
150 #end
151 #if (${column.effectType} == "datepicker")
152         ${column.javaName}DateString: '',
153 #end
154 #end
155 #end
156         visible: false,
157         confirmLoading: false,
158         form: this.$form.createForm(this)
159       }
160     },
161     methods: {
162 #if($DateQuery == "Y")
163       moment,
164 #end
165       // 初始化方法
166       edit (record) {
167         this.visible = true
168 #foreach ($column in $tableField)
169 #if (${column.dictTypeCode})
170 #if(${column.effectType} == 'select' || ${column.effectType} == 'radio' || ${column.effectType} == 'checkbox')
171         const ${column.javaName}Option = this.$options
172         this.${column.javaName}Data = ${column.javaName}Option.filters['dictData']('${column.dictTypeCode}')
173 #end
174 #end
175 #end
176         setTimeout(() => {
177           this.form.setFieldsValue(
178             {
179 #set ($editDataColumn = 0)
180 #foreach ($column in $tableField)
181 #if(${column.columnKey} == "PRI")
182               ${column.javaName}: record.${column.javaName}#if($foreach.hasNext),
183 #end
184 #else
185 #if (${column.whetherAddUpdate} == "Y")
186 #if (${column.effectType} == "checkbox")
187 #set ($editDataColumn = $editDataColumn+1)
188               ${column.javaName}: JSON.parse(record.${column.javaName})#if($foreach.hasNext && ($editDataColumn != $editData)),
189 #else
190
191 #end
192 #elseif (${column.effectType} != "datepicker")
193 #set ($editDataColumn = $editDataColumn+1)
194               ${column.javaName}: record.${column.javaName}#if($foreach.hasNext && ($editDataColumn != $editData)),
195 #else
196
197 #end
198 #end
199 #end
200 #end
201 #end
202             }
203           )
204         }, 100)
205 #foreach ($column in $tableField)
206 #if (${column.whetherAddUpdate} == "Y")
207 #if (${column.effectType} == "datepicker")
208         // 时间单独处理
209         if (record.${column.javaName}) {
210             this.form.getFieldDecorator('${column.javaName}', { initialValue: moment(record.${column.javaName}, 'YYYY-MM-DD') })
211             this.${column.javaName}DateString = moment(record.${column.javaName}).format('YYYY-MM-DD')
212         }
213 #end
214 #end
215 #end
216       },
217       handleSubmit () {
218         const { form: { validateFields } } = this
219         this.confirmLoading = true
220         validateFields((errors, values) => {
221           if (!errors) {
222             for (const key in values) {
223               if (typeof (values[key]) === 'object' && values[key] != null) {
224                 values[key] = JSON.stringify(values[key])
225               }
226             }
227 #foreach ($column in $tableField)
228 #if (${column.whetherAddUpdate} == "Y")
229 #if (${column.effectType} == "datepicker")
230             values.${column.javaName} = this.${column.javaName}DateString || null
231 #end
232 #end
233 #end
234             ${className}Edit(values).then((res) => {
235               if (res.success) {
236                 this.$message.success('编辑成功')
237                 this.confirmLoading = false
238                 this.$emit('ok', values)
239                 this.handleCancel()
240               } else {
241                 this.$message.error('编辑失败')//  + res.message
242               }
243             }).finally((res) => {
244               this.confirmLoading = false
245             })
246           } else {
247             this.confirmLoading = false
248           }
249         })
250       },
251 #foreach ($column in $tableField)
252 #if (${column.whetherAddUpdate} == "Y")
253 #if (${column.effectType} == "datepicker")
254       ${column.javaName}OnChange(date, dateString) {
255         this.${column.javaName}DateString = dateString
256       },
257 #end
258 #end
259 #end
260       handleCancel () {
261 #foreach ($column in $tableField)
262 #if (${column.whetherAddUpdate} == "Y")
263 #if (${column.effectType} == "datepicker")
264         this.${column.javaName}DateString =''
265         this.form.getFieldDecorator('${column.javaName}', { initialValue: null })
266 #end
267 #end
268 #end
269         this.form.resetFields()
270         this.visible = false
271       }
272     }
273   }
274 </script>