import{e as t,f as e,w as i,g as u,x as l,z as a,v as s,y as n,p as o,a1 as d}from"./index-DVkgSHpn.js";import{_ as m}from"./el-layout._U-vZTft.js";const h=m({name:"UniNumberBox",emits:["change","input","update:modelValue","blur","focus"],props:{value:{type:[Number,String],default:1},modelValue:{type:[Number,String],default:1},min:{type:Number,default:0},max:{type:Number,default:100},step:{type:Number,default:1},background:{type:String,default:"#f5f5f5"},color:{type:String,default:"#333"},disabled:{type:Boolean,default:!1},width:{type:Number,default:40}},data:()=>({inputValue:0}),watch:{value(t){this.inputValue=+t},modelValue(t){this.inputValue=+t}},computed:{widthWithPx(){return this.width+"px"}},created(){1===this.value&&(this.inputValue=+this.modelValue),1===this.modelValue&&(this.inputValue=+this.value)},methods:{_calcValue(t){if(this.disabled)return;const e=this._getDecimalScale();let i=this.inputValue*e,u=this.step*e;if("minus"===t){if(i-=u,i<this.min*e)return;i>this.max*e&&(i=this.max*e)}if("plus"===t){if(i+=u,i>this.max*e)return;i<this.min*e&&(i=this.min*e)}this.inputValue=(i/e).toFixed(String(e).length-1),this.$emit("input",+this.inputValue),this.$emit("update:modelValue",+this.inputValue),this.$emit("change",+this.inputValue)},_getDecimalScale(){let t=1;return~~this.step!==this.step&&(t=Math.pow(10,String(this.step).split(".")[1].length)),t},_onBlur(t){this.$emit("blur",t);let e=t.detail.value;if(isNaN(e))return void(this.inputValue=this.min);e=+e,e>this.max?e=this.max:e<this.min&&(e=this.min);const i=this._getDecimalScale();this.inputValue=e.toFixed(String(i).length-1),this.$emit("input",+this.inputValue),this.$emit("update:modelValue",+this.inputValue),this.$emit("change",+this.inputValue)},_onFocus(t){this.$emit("focus",t)}}},[["render",function(m,h,r,p,c,b){const V=n,f=o,x=d;return t(),e(f,{class:"uni-numbox"},{default:i((()=>[u(f,{onClick:h[0]||(h[0]=t=>b._calcValue("minus")),class:"uni-numbox__minus uni-numbox-btns",style:l({background:r.background})},{default:i((()=>[u(V,{class:a(["uni-numbox--text",{"uni-numbox--disabled":c.inputValue<=r.min||r.disabled}]),style:l({color:r.color})},{default:i((()=>[s("-")])),_:1},8,["class","style"])])),_:1},8,["style"]),u(x,{disabled:r.disabled,onFocus:b._onFocus,onBlur:b._onBlur,class:"uni-numbox__value",type:r.step<1?"digit":"number",modelValue:c.inputValue,"onUpdate:modelValue":h[1]||(h[1]=t=>c.inputValue=t),style:l({background:r.background,color:r.color,width:b.widthWithPx})},null,8,["disabled","onFocus","onBlur","type","modelValue","style"]),u(f,{onClick:h[2]||(h[2]=t=>b._calcValue("plus")),class:"uni-numbox__plus uni-numbox-btns",style:l({background:r.background})},{default:i((()=>[u(V,{class:a(["uni-numbox--text",{"uni-numbox--disabled":c.inputValue>=r.max||r.disabled}]),style:l({color:r.color})},{default:i((()=>[s("+")])),_:1},8,["class","style"])])),_:1},8,["style"])])),_:1})}],["__scopeId","data-v-821bf083"]]);export{h as _};
//# sourceMappingURL=uni-number-box.Dp7jG24a.js.map
