lincl před 3 roky
rodič
revize
9352cfa7d9
1 změnil soubory, kde provedl 61 přidání a 30 odebrání
  1. 61 30
      src/components/Form/index.vue

+ 61 - 30
src/components/Form/index.vue

@ -6,44 +6,61 @@
                    {{g.groupTitle}}
                    {{g.groupTitle}}
                </div>
                </div>
                <template v-for="(item, i) in g.children">
                <template v-for="(item, i) in g.children">
                    <slot v-if="$slots[item.id]" :name="item.id" :config="item" />
                    <van-field 
                        :class="{'has-tips': $slots[item.id+'-tips']}"
                        v-else-if="item.type=='text'||item.type=='textarea'"
                        :type="item.type"
                        :key="i"
                        v-model="form[item.id]" 
                        error-message-align="right" 
                        input-align="right" 
                        :rules="rules[item.id]"
                        v-bind="item.vanCfg||''"
                        v-on="item.vanEvts||''"
                        @click="item.onClick? item.onClick(item) : ''"
                        />
                    <template v-if="item.isHide!==true">
                        <slot v-if="$slots[item.id]" :name="item.id" :config="item" />
                        <van-field 
                            :class="{'has-tips': $slots[item.id+'-tips']}"
                            v-else-if="item.type=='text'||item.type=='textarea'"
                            :type="item.type"
                            :key="i"
                            v-model="form[item.id]" 
                            error-message-align="right" 
                            input-align="right" 
                            :rules="rules[item.id]"
                            v-bind="item.vanCfg||''"
                            v-on="item.vanEvts||''"
                            @click="item.onClick? item.onClick(item) : ''"
                            />
                    <van-field 
                        v-else-if="item.type=='select'||item.type=='date'||item.type=='datetime'"
                        :class="{'has-tips': $slots[item.id+'-tips']}"
                        :key="i"
                        v-model="form[item.id].name" 
                        error-message-align="right" 
                        input-align="right" 
                        :rules="rules[item.id]"
                        v-bind="item.vanCfg||''"
                        v-on="item.vanEvts||''"
                        readonly
                        is-link
                         @click="item.onClick? item.onClick(item) : onSelectShow(item)"
                        />
                        <van-field 
                            v-else-if="item.type=='select'||item.type=='date'||item.type=='datetime'"
                            :class="{'has-tips': $slots[item.id+'-tips']}"
                            :key="i"
                            v-model="form[item.id].name" 
                            error-message-align="right" 
                            input-align="right" 
                            :rules="rules[item.id]"
                            v-bind="item.vanCfg||''"
                            v-on="item.vanEvts||''"
                            readonly
                            is-link
                            @click="item.onClick? item.onClick(item) : onSelectShow(item)"
                            />
                        <van-field 
                            v-else-if="item.type=='photo'"
                            :class="{'has-tips': $slots[item.id+'-tips']}"
                            :key="i"
                            v-model="form[item.id].name" 
                            error-message-align="right" 
                            input-align="right"
                            :rules="rules[item.id]"
                            v-bind="item.vanCfg||''"
                            v-on="item.vanEvts||''" >
                            <template slot="input">
                                <CustomUpload :data.sync="form[item.id]"></CustomUpload>
                            </template>
                        </van-field>
                        <div :key="i" class="custom-form-tips" v-if="$slots[item.id+'-tips']">
                        <div :key="i" class="custom-form-tips" v-if="$slots[item.id+'-tips']">
                            <slot :name="item.id+ '-tips'" :config="item" />
                            <slot :name="item.id+ '-tips'" :config="item" />
                        </div>
                        </div>
                    </template>   
                </template>
                </template>
            </van-cell-group>
            </van-cell-group>
            <slot name="tips"></slot>
            <slot name="tips"></slot>
            <div class="plr30 ptb30">
            <div class="plr30 ptb30">
                <van-button native-type="submit" type="primary" round color="#17b3ec" block>{{comfirmBtnText}}</van-button>
                <van-button native-type="submit" type="primary" round :color="comfirmBtnColor" block>{{comfirmBtnText}}</van-button>
            </div>
            </div>
        </van-form>
        </van-form>
@ -85,12 +102,23 @@ export default {
        comfirmBtnText: {
        comfirmBtnText: {
            type: String,
            type: String,
            default: "保存"
            default: "保存"
        },
        comfirmBtnColor: {
            type: String,
            default: "#17b3ec"
        }
        }
    },
    },
    components: {
    components: {
        
        
    },
    },
    watch:{
    watch:{
        'form': {
            handler(n, o){
                this.$emit('input', this.form)
            },
            deep: true,
            immediate: true
        }
        // 'configs': {
        // 'configs': {
        //     handler(n, o){
        //     handler(n, o){
        //         if(n.fields[0].groupTitle){
        //         if(n.fields[0].groupTitle){
@ -142,6 +170,9 @@ export default {
		
		
    },
    },
    methods: {
    methods: {
        resetRule(item){
            this.rules[item.id] = this.setRule(item)
        },
        formatValue(v){
        formatValue(v){
            return v.value||v.value===0||v.value===false? v.value :  v.type=='select'||v.type=='date'||v.type=='datetime'? {name: "", id: ""} : ""
            return v.value||v.value===0||v.value===false? v.value :  v.type=='select'||v.type=='date'||v.type=='datetime'? {name: "", id: ""} : ""
        },
        },
@ -188,7 +219,7 @@ export default {
            var rules = item.rules || []
            var rules = item.rules || []
            var vanCfg = item.vanCfg
            var vanCfg = item.vanCfg
            if(vanCfg.required){
            if(vanCfg.required){
                rules = [{ required: true, message: '' }].concat(rules)
                rules = [{ required: true, message: item.type=='photo'? (item.requiredErrMsg || '请上传') : '' }].concat(rules)
            }
            }
			if(item.regularType && validateForm[item.regularType]){
			if(item.regularType && validateForm[item.regularType]){