u-number-box.js 8.5 KB
"use strict";const i=require("../../../../common/vendor.js"),o=require("./props.js"),h=require("../../libs/mixin/mpMixin.js"),a=require("../../libs/mixin/mixin.js");require("../../libs/config/props.js");require("../../libs/config/config.js");require("../../libs/config/props/actionSheet.js");require("../../libs/config/props/album.js");require("../../libs/config/props/alert.js");require("../../libs/config/props/avatar.js");require("../../libs/config/props/avatarGroup.js");require("../../libs/config/props/backtop.js");require("../../libs/config/props/badge.js");require("../../libs/config/props/button.js");require("../../libs/config/props/calendar.js");require("../../libs/config/props/carKeyboard.js");require("../../libs/config/props/cell.js");require("../../libs/config/props/cellGroup.js");require("../../libs/config/props/checkbox.js");require("../../libs/config/props/checkboxGroup.js");require("../../libs/config/props/circleProgress.js");require("../../libs/config/props/code.js");require("../../libs/config/props/codeInput.js");require("../../libs/config/props/col.js");require("../../libs/config/props/collapse.js");require("../../libs/config/props/collapseItem.js");require("../../libs/config/props/columnNotice.js");require("../../libs/config/props/countDown.js");require("../../libs/config/props/countTo.js");require("../../libs/config/props/datetimePicker.js");require("../../libs/config/props/divider.js");require("../../libs/config/props/empty.js");require("../../libs/config/props/form.js");require("../../libs/config/props/formItem.js");require("../../libs/config/props/gap.js");require("../../libs/config/props/grid.js");require("../../libs/config/props/gridItem.js");require("../../libs/config/props/icon.js");require("../../libs/config/props/image.js");require("../../libs/config/props/indexAnchor.js");require("../../libs/config/props/indexList.js");require("../../libs/config/props/input.js");require("../../libs/config/props/keyboard.js");require("../../libs/config/props/line.js");require("../../libs/config/props/lineProgress.js");require("../../libs/config/props/link.js");require("../../libs/config/props/list.js");require("../../libs/config/props/listItem.js");require("../../libs/config/props/loadingIcon.js");require("../../libs/config/props/loadingPage.js");require("../../libs/config/props/loadmore.js");require("../../libs/config/props/modal.js");require("../../libs/config/props/navbar.js");require("../../libs/config/color.js");require("../../libs/config/props/noNetwork.js");require("../../libs/config/props/noticeBar.js");require("../../libs/config/props/notify.js");require("../../libs/config/props/numberBox.js");require("../../libs/config/props/numberKeyboard.js");require("../../libs/config/props/overlay.js");require("../../libs/config/props/parse.js");require("../../libs/config/props/picker.js");require("../../libs/config/props/popup.js");require("../../libs/config/props/radio.js");require("../../libs/config/props/radioGroup.js");require("../../libs/config/props/rate.js");require("../../libs/config/props/readMore.js");require("../../libs/config/props/row.js");require("../../libs/config/props/rowNotice.js");require("../../libs/config/props/scrollList.js");require("../../libs/config/props/search.js");require("../../libs/config/props/section.js");require("../../libs/config/props/skeleton.js");require("../../libs/config/props/slider.js");require("../../libs/config/props/statusBar.js");require("../../libs/config/props/steps.js");require("../../libs/config/props/stepsItem.js");require("../../libs/config/props/sticky.js");require("../../libs/config/props/subsection.js");require("../../libs/config/props/swipeAction.js");require("../../libs/config/props/swipeActionItem.js");require("../../libs/config/props/swiper.js");require("../../libs/config/props/swipterIndicator.js");require("../../libs/config/props/switch.js");require("../../libs/config/props/tabbar.js");require("../../libs/config/props/tabbarItem.js");require("../../libs/config/props/tabs.js");require("../../libs/config/props/tag.js");require("../../libs/config/props/text.js");require("../../libs/config/props/textarea.js");require("../../libs/config/props/toast.js");require("../../libs/config/props/toolbar.js");require("../../libs/config/props/tooltip.js");require("../../libs/config/props/transition.js");require("../../libs/config/props/upload.js");require("../../libs/config/props/drawer.js");const c={name:"u-number-box",mixins:[h.mpMixin,a.mixin,o.props],data(){return{currentValue:"",longPressTimer:null}},watch:{watchChange(e){this.check()},modelValue(e){e!==this.currentValue&&(this.currentValue=this.format(this.modelValue))}},computed:{getCursorSpacing(){return i.index.$u.getPx(this.cursorSpacing)},buttonStyle(){return e=>{const s={backgroundColor:this.bgColor,height:i.index.$u.addUnit(this.buttonSize),color:this.color};return this.isDisabled(e)&&(s.backgroundColor="#f7f8fa"),s}},inputStyle(){return this.disabled||this.disabledInput,{color:this.color,backgroundColor:this.bgColor,height:i.index.$u.addUnit(this.buttonSize),width:i.index.$u.addUnit(this.inputWidth)}},watchChange(){return[this.integer,this.decimalLength,this.min,this.max]},isDisabled(){return e=>e==="plus"?this.disabled||this.disablePlus||this.currentValue>=this.max:this.disabled||this.disableMinus||this.currentValue<=this.min}},mounted(){this.init()},emits:["update:modelValue","focus","blur","overlimit","change","plus","minus"],methods:{init(){this.currentValue=this.format(this.modelValue)},format(e){return e=this.filter(e),e=e===""?0:+e,e=Math.max(Math.min(this.max,e),this.min),this.decimalLength!==null&&(e=e.toFixed(this.decimalLength)),e},filter(e){return e=String(e).replace(/[^0-9.-]/g,""),this.integer&&e.indexOf(".")!==-1&&(e=e.split(".")[0]),e},check(){const e=this.format(this.currentValue);e!==this.currentValue&&(this.currentValue=e)},onFocus(e){this.$emit("focus",{...e.detail,name:this.name})},onBlur(e){this.format(e.detail.value),this.$emit("blur",{...e.detail,name:this.name})},onInput(e){const{value:s=""}=e.detail||{};if(s==="")return;let t=this.filter(s);if(this.decimalLength!==null&&t.indexOf(".")!==-1){const n=t.split(".");t=`${n[0]}.${n[1].slice(0,this.decimalLength)}`}t=this.format(t),this.emitChange(t)},emitChange(e){this.asyncChange||this.$nextTick(()=>{this.$emit("update:modelValue",e),this.currentValue=e,this.$forceUpdate()}),this.$emit("change",{value:e,name:this.name})},onChange(){const{type:e}=this;if(this.isDisabled(e))return this.$emit("overlimit",e);const s=e==="minus"?-this.step:+this.step,t=this.format(this.add(+this.currentValue,s));this.emitChange(t),this.$emit(e)},add(e,s){const t=Math.pow(10,10);return Math.round((e+s)*t)/t},clickHandler(e){this.type=e,this.onChange()},longPressStep(){this.clearTimeout(),this.longPressTimer=setTimeout(()=>{this.onChange(),this.longPressStep()},250)},onTouchStart(e){this.longPress&&(this.clearTimeout(),this.type=e,this.longPressTimer=setTimeout(()=>{this.onChange(),this.longPressStep()},600))},onTouchEnd(){this.longPress&&this.clearTimeout()},clearTimeout(){clearTimeout(this.longPressTimer),this.longPressTimer=null}}};Array||i.resolveComponent("u-icon")();const m=()=>"../u-icon/u-icon.js";Math||m();function q(e,s,t,n,l,r){return i.e({a:e.showMinus&&e.$slots.minus},e.showMinus&&e.$slots.minus?{b:i.o(u=>r.clickHandler("minus")),c:i.o(u=>r.onTouchStart("minus")),d:i.o((...u)=>r.clearTimeout&&r.clearTimeout(...u))}:e.showMinus?{f:i.p({name:"minus",color:r.isDisabled("minus")?"#c8c9cc":"#323233",size:"15",bold:!0,customStyle:e.iconStyle}),g:i.o(u=>r.clickHandler("minus")),h:i.o(u=>r.onTouchStart("minus")),i:i.o((...u)=>r.clearTimeout&&r.clearTimeout(...u)),j:r.isDisabled("minus")?1:"",k:i.s(r.buttonStyle("minus"))}:{},{e:e.showMinus,l:e.disabledInput||e.disabled,m:r.getCursorSpacing,n:e.disabled||e.disabledInput?1:"",o:i.o((...u)=>r.onBlur&&r.onBlur(...u)),p:i.o((...u)=>r.onFocus&&r.onFocus(...u)),q:i.o([u=>l.currentValue=u.detail.value,(...u)=>r.onInput&&r.onInput(...u)]),r:i.s(r.inputStyle),s:l.currentValue,t:e.showPlus&&e.$slots.plus},e.showPlus&&e.$slots.plus?{v:i.o(u=>r.clickHandler("plus")),w:i.o(u=>r.onTouchStart("plus")),x:i.o((...u)=>r.clearTimeout&&r.clearTimeout(...u))}:e.showPlus?{z:i.p({name:"plus",color:r.isDisabled("plus")?"#c8c9cc":"#323233",size:"15",bold:!0,customStyle:e.iconStyle}),A:i.o(u=>r.clickHandler("plus")),B:i.o(u=>r.onTouchStart("plus")),C:i.o((...u)=>r.clearTimeout&&r.clearTimeout(...u)),D:r.isDisabled("plus")?1:"",E:i.s(r.buttonStyle("plus"))}:{},{y:e.showPlus})}const d=i._export_sfc(c,[["render",q],["__scopeId","data-v-eb6f6237"],["__file","D:/vue/大健康商城/healthMall/uni_modules/uview-plus/components/u-number-box/u-number-box.vue"]]);wx.createComponent(d);