import{d as t,e,f as i,g as u,h as l,k as s,l as a,C as n,p as o,P as d}from"./index-45b322f7.js";import{_ as m}from"./_plugin-vue_export-helper.1b428a4d.js";const c=m({name:"UniNumberBox",emits:["change","input","update:modelValue","blur","focus","canNotMinus","canNotPlus"],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}},data:()=>({inputValue:0}),watch:{value(t){this.inputValue=+t},modelValue(t){this.inputValue=+t}},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 void this.$emit("canNotMinus");i>this.max*e&&(i=this.max*e)}if("plus"===t){if(i+=u,i>this.max*e)return void this.$emit("canNotPlus");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,c,h,r,p,b){const V=n,f=o,_=d;return t(),e(f,{class:"uni-numbox"},{default:i((()=>[u(f,{onClick:c[0]||(c[0]=t=>b._calcValue("minus")),class:"uni-numbox__minus uni-numbox-btns",style:l({background:h.background})},{default:i((()=>[u(V,{class:s(["uni-numbox--text",{"uni-numbox--disabled":p.inputValue<=h.min||h.disabled}]),style:l({color:h.color})},{default:i((()=>[a("-")])),_:1},8,["class","style"])])),_:1},8,["style"]),u(_,{disabled:h.disabled,onFocus:b._onFocus,onBlur:b._onBlur,class:"uni-numbox__value",type:"number",modelValue:p.inputValue,"onUpdate:modelValue":c[1]||(c[1]=t=>p.inputValue=t),style:l({background:h.background,color:h.color})},null,8,["disabled","onFocus","onBlur","modelValue","style"]),u(f,{onClick:c[2]||(c[2]=t=>b._calcValue("plus")),class:"uni-numbox__plus uni-numbox-btns",style:l({background:h.background})},{default:i((()=>[u(V,{class:s(["uni-numbox--text",{"uni-numbox--disabled":p.inputValue>=h.max||h.disabled}]),style:l({color:h.color})},{default:i((()=>[a("+")])),_:1},8,["class","style"])])),_:1},8,["style"])])),_:1})}],["__scopeId","data-v-68c72360"]]);export{c as _};
