[1-n]Form.vuei 8.0 KB
Newer Older
1 2 3 4 5 6
<#include "/common/utils.ftl">
<#list subTables as sub>
<#if sub.foreignRelationType=='1'>
#segment#${sub.entityName}Form.vue
<template>
  <j-form-container :disabled="disabled">
7
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
8
        <a-row>
9
<#assign form_popup = false>
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<#assign form_cat_tree = false>
<#assign form_cat_back = "">
<#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>
<#list sub.colums as po>
<#if po.isShow =='Y' && po.fieldName != 'id'>
<#assign form_field_dictCode="">
	<#if po.dictTable?default("")?trim?length gt 1 && po.dictText?default("")?trim?length gt 1 && po.dictField?default("")?trim?length gt 1>
		<#assign form_field_dictCode="${po.dictTable},${po.dictText},${po.dictField}">
	<#elseif po.dictField?default("")?trim?length gt 1>
		<#assign form_field_dictCode="${po.dictField}">
	</#if>
	<#if po.classType =='textarea'>
          <a-col :span="24">
30
            <a-form-model-item label="${po.filedComment}" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="${autoStringSuffixForModel(po)}">
31 32
	<#else>
          <a-col :span="${form_span}">
33
            <a-form-model-item label="${po.filedComment}" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="${autoStringSuffixForModel(po)}">
34 35
	</#if>
	<#if po.classType =='date'>
36
              <j-date placeholder="请选择${po.filedComment}" v-model="model.${po.fieldName}" style="width: 100%"/>
37
	<#elseif po.classType =='datetime'>
38
              <j-date placeholder="请选择${po.filedComment}" v-model="model.${po.fieldName}" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
39
	<#elseif po.classType =='time'>
40
              <j-time placeholder="请选择${po.filedComment}" v-model="model.${po.fieldName}" style="width: 100%" <#if po.readonly=='Y'>disabled</#if>/>
41
	<#elseif po.classType =='popup'>
42
	       <#assign form_popup=true>
43
              <j-popup
44 45
                v-model="model.${po.fieldName}"
                field="${po.fieldName}"
46 47 48
                org-fields="${po.dictField}"
                dest-fields="${Format.underlineToHump(po.dictText)}"
                code="${po.dictTable}"
49
                @input="popupCallback"/>
50
    <#elseif po.classType =='sel_depart'>
51
              <j-select-depart v-model="model.${po.fieldName}" multi/>
52
<#elseif po.classType =='switch'>
53
              <j-switch v-model="model.${po.fieldName}" <#if po.dictField!= 'is_open'>:options="${po.dictField}"</#if>></j-switch>
54
	<#elseif po.classType =='pca'>
55
		      <j-area-linkage type="cascader" v-model="model.${po.fieldName}" placeholder="请输入省市区"/>
56
	<#elseif po.classType =='markdown'>
57
	          <j-markdown-editor v-model="model.${autoStringSuffixForModel(po)}" id="${po.fieldName}"></j-markdown-editor>
58
    <#elseif po.classType =='password'>
59
	          <a-input-password v-model="model.${po.fieldName}" placeholder="请输入${po.filedComment}"/>
60
	<#elseif po.classType =='sel_user'>
61
              <j-select-user-by-dep v-model="model.${po.fieldName}"/>
62
	<#elseif po.classType =='textarea'>
63
              <a-textarea v-model="model.${autoStringSuffixForModel(po)}" rows="4" placeholder="请输入${po.filedComment}"/>
64
	<#elseif po.classType=='list' || po.classType=='radio'>
65
              <j-dict-select-tag type="${po.classType}" v-model="model.${po.fieldName}" dictCode="${form_field_dictCode}" placeholder="请选择${po.filedComment}"/>
66
	<#elseif po.classType=='list_multi' || po.classType=='checkbox'>
67
              <j-multi-select-tag type="${po.classType}" v-model="model.${po.fieldName}" dictCode="${form_field_dictCode}" placeholder="请选择${po.filedComment}"/>
68
	<#elseif po.classType=='sel_search'>
69
              <j-search-select-tag v-model="model.${po.fieldName}" dict="${form_field_dictCode}" />
70 71
    <#elseif po.classType=='cat_tree'>
    	<#assign form_cat_tree = true>
72
              <j-category-select v-model="model.${po.fieldName}" pcode="${po.dictField?default("")}" placeholder="请选择${po.filedComment}" <#if po.dictText?default("")?trim?length gt 1>back="${dashedToCamel(po.dictText)}" @change="handleCategoryChange"</#if>/>
73 74 75 76
    	<#if po.dictText?default("")?trim?length gt 1>
    	<#assign form_cat_back = "${po.dictText}">
    	</#if>
	<#elseif po.fieldDbType=='int' || po.fieldDbType=='double' || po.fieldDbType=='BigDecimal'>
77
              <a-input-number v-model="model.${po.fieldName}" placeholder="请输入${po.filedComment}" style="width: 100%"/>
78
	<#elseif po.classType=='file'>
79
              <j-upload v-model="model.${po.fieldName}"></j-upload>
80
	<#elseif po.classType=='image'>
81
              <j-image-upload isMultiple v-model="model.${po.fieldName}"></j-image-upload>
82
	<#elseif po.classType=='umeditor'>
83
              <j-editor v-model="model.${autoStringSuffixForModel(po)}"/>
84
	<#else>
85
              <a-input v-model="model.${autoStringSuffixForModel(po)}" placeholder="请输入${po.filedComment}"></a-input>
86
    </#if>
87
            </a-form-model-item>
88 89 90 91
          </a-col>
</#if>
</#list>
        </a-row>
92
      </a-form-model>
93 94 95 96 97 98
  </j-form-container>
</template>
<script>
  import { getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'
99
  import { VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

  export default {
    name: '${sub.entityName}Form',
    components: {
      JFormContainer
    },
    props:{
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
115 116 117
        model: {
        <#include "/common/init/initValueSub.ftl">
        },
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        <#include "/common/validatorRulesTemplate/sub.ftl">
        confirmLoading: false,
      }
    },
138 139 140 141
    created () {
     //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
142 143 144 145
    methods:{
      initFormData(url,id){
        this.clearFormData()
        if(!id){
146
         this.edit(this.modelDefault);
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
        }else{
          getAction(url,{id:id}).then(res=>{
            if(res.success){
              let records = res.result
              if(records && records.length>0){
                this.edit(records[0])
              }
            }
          })
        }
      },
      edit(record){
        this.model = Object.assign({}, record)
        console.log("${sub.entityName}Form-edit",this.model);
      },
      getFormData(){
        let formdata_arr = []
164 165
        this.$refs.form.validate(valid => {
          if (valid) {
166
            let isNullObj = true
167 168
            Object.keys(this.model).forEach(key=>{
              if( this.model[key]){
169 170 171 172
                isNullObj = false
              }
            })
            if(!isNullObj){
173
              formdata_arr.push(this.model)
174 175 176
            }
          }else{
            this.$emit("validateError","${sub.ftlDescription}表单校验未通过");
177
            return false
178 179 180 181
          }
        })
        return formdata_arr;
      },
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
      validate(index){
        return new Promise((resolve, reject) => {
          // 验证主表表单
         this.$refs.form.validate(valid => {
            !valid ? reject({ error: VALIDATE_NO_PASSED ,index}) : resolve()
          })
        }).then(values => {
          return Promise.resolve()
        }).catch(error => {
          return Promise.reject(error)
        })
      },
      <#if form_popup>
      popupCallback(value,row){
      this.model = Object.assign(this.model, row);
197
      },
198
       </#if>
199
      clearFormData(){
200
        this.$refs.form.clearValidate()
201 202 203
      },
      <#if form_cat_tree>
      handleCategoryChange(value,backObj){
204
        this.model = Object.assign(this.model,backObj);
205 206 207 208 209 210 211
      }
      </#if>
    }
  }
</script>
</#if>
</#list>