1 |
- import eventUtil from"../core/utils/event-util";Component({externalClasses:["l-class","l-symbol-class","l-count-class","l-disabled-class"],properties:{count:{type:Number,value:1},max:{type:Number,value:9999},min:{type:Number,value:1},step:{type:Number,value:1},roundFloat:{type:Boolean,value:!1},disabled:Boolean,iconSize:String,iconColor:String},data:{focus:!1},observers:{count:function(t){eventUtil.emit(this,"linchange",{count:t})},"count,min,max":function(){this.valueRange(this.data.count,"parameter")}},methods:{doNothing(t){const{type:e}=t.currentTarget.dataset;eventUtil.emit(this,"linout",{type:e,way:"icon"})},onCount(){this.setData({focus:!0})},onBlur(t){let{value:e}=t.detail;setTimeout(()=>{this.blurCount(Number(e),()=>{eventUtil.emit(this,"lintap",{count:this.data.count,type:"blur"})})},50)},blurCount(t,e){void 0!==t&&this.valueRange(t),e&&e()},valueRange(t,e="input"){const{count:a,min:n,max:o}=this.data;"parameter"===e&&t>o&&console.error(`Counter 组件:初始值 ${a} 大于了最大值 ${o},请注意修正`),"parameter"===e&&t<n&&console.error(`Counter 组件:初始值 ${a} 小于了最小值 ${n},请注意修正`),t>o&&eventUtil.emit(this,"linout",{type:"overflow_max",way:e}),t<n&&eventUtil.emit(this,"linout",{type:"overflow_min",way:e}),t=(t=t>o?o:t)<n?n:t,this.data.roundFloat&&(t=Math.round(t)),t===this.data.count&&this.setData({focus:!1}),t!==this.data.count&&this.setData({count:t},()=>{this.setData({focus:!1})})},onTapChange(t){const e=t.currentTarget.dataset.changeType,{count:a,step:n,min:o,max:i}=this.data;let s;"add"===e?s=a+n>i?i:a+n:"reduce"===e&&(s=a-n<o?o:a-n),s=s.toFixed(2),s=parseFloat(s),this.setData({count:s}),eventUtil.emit(this,"lintap",{count:this.data.count,type:e})},onInput(t){eventUtil.emit(this,"lininput",t.detail)}}});
|