import{f as t,g as e,w as i,n as l,H as u,E as a,K as s,a5 as n,l as o}from"./index-007bf156.js";import{_ as d}from"./_plugin-vue_export-helper.1b428a4d.js";const p=d({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},activity:{type:String,default:"none"}},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,l=this.step*e;if("minus"===t){if(i-=l,i<this.min*e)return;i>this.max*e&&(i=this.max*e)}if("plus"===t){if(i+=l,i>this.max*e)return;i<this.min*e&&(i=this.min*e)}this.inputValue=(i/e).toFixed(String(e).length-1),this.$emit("change",+this.inputValue),this.$emit("input",+this.inputValue),this.$emit("update:modelValue",+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(!e)return;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("change",+this.inputValue),this.$emit("input",+this.inputValue)},_onFocus(t){this.$emit("focus",t)}}},[["render",function(d,p,c,m,r,h){const V=s,b=n,f=o;return t(),e(f,{class:"uni-numbox"},{default:i((()=>[l(V,{class:u(["cicon-move-round",{"uni-numbox--disabled":r.inputValue<=c.min||c.disabled,"groupon-btn":"groupon"===c.activity,"seckill-btn":"seckill"===c.activity}]),onClick:p[0]||(p[0]=t=>h._calcValue("minus"))},null,8,["class"]),l(b,{disabled:c.disabled,onFocus:h._onFocus,onBlur:h._onBlur,class:"uni-numbox__value",type:"number",modelValue:r.inputValue,"onUpdate:modelValue":p[1]||(p[1]=t=>r.inputValue=t),style:a({color:c.color})},null,8,["disabled","onFocus","onBlur","modelValue","style"]),l(V,{class:u(["cicon-add-round",{"uni-numbox--disabled":r.inputValue>=c.max||c.disabled,"groupon-btn":"groupon"===c.activity,"seckill-btn":"seckill"===c.activity}]),onClick:p[2]||(p[2]=t=>h._calcValue("plus"))},null,8,["class"])])),_:1})}],["__scopeId","data-v-e84e4879"]]);export{p as _};
