import{o as t,e,w as i,i as l,G as u,E as a,A as s,am as n,m as o}from"./index-520dfaee.js";import{_ as c}from"./_plugin-vue_export-helper.1b428a4d.js";const m=c({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(c,m,d,p,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<=d.min||d.disabled,"groupon-btn":"groupon"==d.activity,"seckill-btn":"seckill"==d.activity}]),onClick:m[0]||(m[0]=t=>h._calcValue("minus"))},null,8,["class"]),l(b,{disabled:d.disabled,onFocus:h._onFocus,onBlur:h._onBlur,class:"uni-numbox__value",type:"number",modelValue:r.inputValue,"onUpdate:modelValue":m[1]||(m[1]=t=>r.inputValue=t),style:a({color:d.color})},null,8,["disabled","onFocus","onBlur","modelValue","style"]),l(V,{class:u(["cicon-add-round",{"uni-numbox--disabled":r.inputValue>=d.max||d.disabled,"groupon-btn":"groupon"==d.activity,"seckill-btn":"seckill"==d.activity}]),onClick:m[2]||(m[2]=t=>h._calcValue("plus"))},null,8,["class"])])),_:1})}],["__scopeId","data-v-9bc014cc"]]);export{m as _};
