浏览代码

多选 兼容名称

lincl 1 年之前
父节点
当前提交
0e33531f72
共有 2 个文件被更改,包括 36 次插入4 次删除
  1. 25 4
      src/components/Form/form.vue
  2. 11 0
      src/components/Form/index.vue

+ 25 - 4
src/components/Form/form.vue

@ -144,10 +144,31 @@ export default {
		},
		onSelChange(value, item){
			if(item.onChange){
				var exist = _.filter(item.optionList, (v)=>{
					return v.value == value
				})
				item.onChange(exist)
				if(item.multiple){
					if(item.valueName.length < value.length){
						var exist = _.find(item.optionList, (v)=>{
							return v.value == value[value.length - 1]
						})
						item.valueName.push(exist.label)
					} else {
						if(value.length == 0){
							item.valueName = []
						} else {
							_.each(item._value_bak, (v, i)=>{
								if(value.indexOf(v) === -1){
									item.valueName.splice(i, 1)
								}
							})
						}
					}
					item._value_bak = _.assign([], value)
					item.onChange(value, item.valueName)
				} else {
					var exist = _.filter(item.optionList, (v)=>{
						return v.value == value
					})
					item.onChange(exist)
				}
			}
		},
		onCheckboxChange(values, item){

+ 11 - 0
src/components/Form/index.vue

@ -105,6 +105,9 @@ export default {
				form[v.id] = v.value||v.value===0||v.value===false? v.value :  v.type=='checkbox'? [] :""
				rules[v.id] = this.setRule(v)
			}
			if(v.type=='select' && v.multiple){
				v._value_bak = _.assign([], form[v.id])
			}
		});
		this.form = form
		this.rules = rules
@ -184,8 +187,16 @@ export default {
			})
		},
		setValues(model){
			var exist
			for(var k in model){
				this.form[k] = model[k]
				exist = _.find(this.configs.fields, v=>{
					return v.id == k
				})
				if(exist && exist.type=='select' && exist.multiple){
					exist._value_bak = _.assign([], this.form[exist.id])
				}
			}
		},
		setValue(id, value){