"use strict";const c=require("./validate.js"),r=require("./utils.js"),p=require("../../../../common/vendor.js"),g={name:"uniForms",emits:["validate","submit"],options:{virtualHost:!0},props:{value:{type:Object,default(){return null}},modelValue:{type:Object,default(){return null}},model:{type:Object,default(){return null}},rules:{type:Object,default(){return{}}},errShowType:{type:String,default:"undertext"},validateTrigger:{type:String,default:"submit"},labelPosition:{type:String,default:"left"},labelWidth:{type:[String,Number],default:""},labelAlign:{type:String,default:"left"},border:{type:Boolean,default:!1}},provide(){return{uniForm:this}},data(){return{formData:{},formRules:{}}},computed:{localData(){const e=this.model||this.modelValue||this.value;return e?r.deepCopy(e):{}}},watch:{rules:{handler:function(e,i){this.setRules(e)},deep:!0,immediate:!0}},created(){getApp().$vm.$.appContext.config.globalProperties.binddata||(getApp().$vm.$.appContext.config.globalProperties.binddata=function(i,t,s){if(s)this.$refs[s].setValue(i,t);else{let a;for(let u in this.$refs){const l=this.$refs[u];if(l&&l.$options&&l.$options.name==="uniForms"){a=l;break}}if(!a)return console.error("当前 uni-froms 组件缺少 ref 属性");a.model&&(a.model[i]=t),a.modelValue&&(a.modelValue[i]=t),a.value&&(a.value[i]=t)}}),this.childrens=[],this.inputChildrens=[],this.setRules(this.rules)},methods:{setRules(e){this.formRules=Object.assign({},this.formRules,e),this.validator=new c.SchemaValidator(e)},setValue(e,i){let t=this.childrens.find(s=>s.name===e);return t?(this.formData[e]=r.getValue(e,i,this.formRules[e]&&this.formRules[e].rules||[]),t.onFieldChange(this.formData[e])):null},validate(e,i){return this.checkAll(this.formData,e,i)},validateField(e=[],i){e=[].concat(e);let t={};return this.childrens.forEach(s=>{const a=r.realName(s.name);e.indexOf(a)!==-1&&(t=Object.assign({},t,{[a]:this.formData[a]}))}),this.checkAll(t,[],i)},clearValidate(e=[]){e=[].concat(e),this.childrens.forEach(i=>{if(e.length===0)i.errMsg="";else{const t=r.realName(i.name);e.indexOf(t)!==-1&&(i.errMsg="")}})},submit(e,i,t){for(let s in this.dataValue)this.childrens.find(u=>u.name===s)&&this.formData[s]===void 0&&(this.formData[s]=this._getValue(s,this.dataValue[s]));return t||console.warn("submit 方法即将废弃，请使用validate方法代替！"),this.checkAll(this.formData,e,i,"submit")},async checkAll(e,i,t,s){if(!this.validator)return;let a=[];for(let f in e){const n=this.childrens.find(o=>r.realName(o.name)===f);n&&a.push(n)}!t&&typeof i=="function"&&(t=i);let u;!t&&typeof t!="function"&&Promise&&(u=new Promise((f,n)=>{t=function(o,m){o?n(o):f(m)}}));let l=[],d=JSON.parse(JSON.stringify(e));for(let f in a){const n=a[f];let o=r.realName(n.name);const m=await n.onFieldChange(d[o]);if(m&&(l.push(m),this.errShowType==="toast"||this.errShowType==="modal"))break}Array.isArray(l)&&l.length===0&&(l=null),Array.isArray(i)&&i.forEach(f=>{let n=r.realName(f),o=r.getDataValue(f,this.localData);o!==void 0&&(d[n]=o)}),s==="submit"?this.$emit("submit",{detail:{value:d,errors:l}}):this.$emit("validate",l);let h={};return h=r.rawData(d,this.name),t&&typeof t=="function"&&t(l,h),u&&t?u:null},validateCheck(e){this.$emit("validate",e)},_getValue:r.getValue,_isRequiredField:r.isRequiredField,_setDataValue:r.setDataValue,_getDataValue:r.getDataValue,_realName:r.realName,_isRealName:r.isRealName,_isEqual:r.isEqual}};function _(e,i,t,s,a,u){return{}}const V=p._export_sfc(g,[["render",_]]);wx.createComponent(V);
