"use strict";const e=require("../../../../common/vendor.js"),t={name:"uniFormsItem",props:{custom:{type:Boolean,default:!1},showMessage:{type:Boolean,default:!0},name:String,required:Boolean,validateTrigger:{type:String,default:""},leftIcon:String,iconColor:{type:String,default:"#606266"},label:String,labelWidth:{type:[Number,String],default:""},labelAlign:{type:String,default:""},labelPosition:{type:String,default:""},errorMessage:{type:[String,Boolean],default:""},rules:{type:Array,default:()=>[]}},data:()=>({errorTop:!1,errorBottom:!1,labelMarginBottom:"",errorWidth:"",errMsg:"",val:"",labelPos:"",labelWid:"",labelAli:"",showMsg:"undertext",border:!1,isFirstBorder:!1,isArray:!1,arrayField:""}),computed:{msg(){return this.errorMessage||this.errMsg},fieldStyle(){let e={};return"top"==this.labelPos&&(e.padding="0 0",this.labelMarginBottom="6px"),"left"==this.labelPos&&!1!==this.msg&&""!=this.msg?(e.paddingBottom="0px",this.errorBottom=!0,this.errorTop=!1):"top"==this.labelPos&&!1!==this.msg&&""!=this.msg?(this.errorBottom=!1,this.errorTop=!0):(this.errorTop=!1,this.errorBottom=!1),e},justifyContent(){return"left"===this.labelAli?"flex-start":"center"===this.labelAli?"center":"right"===this.labelAli?"flex-end":void 0},labelLeft(){return("left"===this.labelPos?parseInt(this.labelWid):0)+"rpx"}},watch:{validateTrigger(e){this.formTrigger=e}},created(){this.form=this.getForm(),this.group=this.getForm("uniGroup"),this.formRules=[],this.formTrigger=this.validateTrigger,this.name&&-1!==this.name.indexOf("[")&&-1!==this.name.indexOf("]")&&(this.isArray=!0,this.arrayField=this.name,this.form.formData[this.name]=this.form._getValue(this.name,""))},mounted(){this.form&&this.form.childrens.push(this),this.init()},unmounted(){this.__isUnmounted=!0,this.unInit()},methods:{init(){if(this.form){let{formRules:e,validator:t,formData:i,value:r,labelPosition:s,labelWidth:l,labelAlign:o,errShowType:a}=this.form;this.labelPos=this.labelPosition?this.labelPosition:s,this.label?this.labelWid=this.labelWidth?this.labelWidth:l||140:this.labelWid=this.labelWidth?this.labelWidth:l||"auto",this.labelWid&&"auto"!==this.labelWid&&(this.labelWid+="rpx"),this.labelAli=this.labelAlign?this.labelAlign:o,this.form.isFirstBorder||(this.form.isFirstBorder=!0,this.isFirstBorder=!0),this.group&&(this.group.isFirstBorder||(this.group.isFirstBorder=!0,this.isFirstBorder=!0)),this.border=this.form.border,this.showMsg=a;let h=this.isArray?this.arrayField:this.name;if(!h)return;e&&this.rules.length>0&&(e[h]||(e[h]={rules:this.rules}),t.updateSchema(e)),this.formRules=e[h]||{},this.validator=t}else this.labelPos=this.labelPosition||"left",this.labelWid=this.labelWidth||130,this.labelAli=this.labelAlign||"left"},unInit(){this.form&&this.form.childrens.forEach(((e,t)=>{e===this&&(this.form.childrens.splice(t,1),delete this.form.formData[e.name])}))},getForm(e="uniForms"){let t=this.$parent,i=t.$options.name;for(;i!==e;){if(t=t.$parent,!t)return!1;i=t.$options.name}return t},clearValidate(){this.errMsg=""},setValue(e){let t=this.isArray?this.arrayField:this.name;if(t){if(this.errMsg&&(this.errMsg=""),this.form.formData[t]=this.form._getValue(t,e),!this.formRules||(this.formRules,"{}"===JSON.stringify(this.formRules)))return;this.triggerCheck(this.form._getValue(this.name,e))}},async triggerCheck(t,i){if(this.errMsg="",!this.validator||0===Object.keys(this.formRules).length)return;const r=this.isRequired(this.formRules.rules||[]);let s=this.isTrigger(this.formRules.validateTrigger,this.validateTrigger,this.form.validateTrigger),l=null;if(s||i){let e=this.isArray?this.arrayField:this.name;l=await this.validator.validateUpdate({[e]:t},this.form.formData)}r||void 0!==t&&""!==t||(l=null);const o=this.form.inputChildrens.find((e=>e.rename===this.name));return(s||i)&&l&&l.errorMessage?(o&&(o.errMsg=l.errorMessage),"toast"===this.form.errShowType&&e.index.showToast({title:l.errorMessage||"校验错误",icon:"none"}),"modal"===this.form.errShowType&&e.index.showModal({title:"提示",content:l.errorMessage||"校验错误"})):o&&(o.errMsg=""),this.errMsg=l?l.errorMessage:"",this.form.validateCheck(l||null),l||null},isTrigger:(e,t,i)=>!("submit"===e||!e)||void 0===e&&("bind"===t||!t&&"bind"===i),isRequired(e){let t=!1;for(let i=0;i<e.length;i++){if(e[i].required){t=!0;break}}return t}}};if(!Array){e.resolveComponent("uni-icons")()}Math;const i=e._export_sfc(t,[["render",function(t,i,r,s,l,o){return e.e({a:r.required},(r.required,{}),{b:r.leftIcon},r.leftIcon?{c:e.p({size:"16",type:r.leftIcon,color:r.iconColor})}:{},{d:e.t(r.label),e:r.label},(r.label,{}),{f:l.labelWid,g:o.justifyContent,h:o.msg?1:"",i:e.n("is-direction-"+l.labelPos),j:o.msg},o.msg?{k:e.t("undertext"===l.showMsg?o.msg:""),l:l.border?1:"",m:o.labelLeft}:{},{n:l.border?1:"",o:l.border&&l.isFirstBorder?1:"",p:o.msg?1:""})}]]);wx.createComponent(i);
