You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/public/assets/pages-cart-index.e8442086.js

1 lines
15 KiB

import{x as e,o as t,c as s,w as i,a,j as l,n,A as o,i as d,l as r,f as h,I as u,B as c,m as p,s as m,C as g,D as f,G as b,t as _,e as C,b as k,d as y,F as x,k as v,r as S,H as I,g as T}from"./index-ae8bbb19.js";import{_ as V}from"./u-icon.b463ad8a.js";import{r as F}from"./uni-app.es.ee1d5b08.js";import{_ as $}from"./_plugin-vue_export-helper.1b428a4d.js";import{E as z}from"./index.97c7afee.js";import{R as N}from"./index.b9e5c444.js";import{l as w,u as B,c as D}from"./cart.414ee15f.js";import"./index.c0835ba6.js";const L=$({name:"u-checkbox",emits:["update:modelValue","input","change"],props:{value:{type:Boolean,default:!1},modelValue:{type:Boolean,default:!1},name:{type:[String,Number],default:""},shape:{type:String,default:""},disabled:{type:[String,Boolean],default:""},labelDisabled:{type:[String,Boolean],default:""},activeColor:{type:String,default:""},iconSize:{type:[String,Number],default:""},labelSize:{type:[String,Number],default:""},size:{type:[String,Number],default:""}},data:()=>({parentDisabled:!1,newParams:{}}),created(){this.parent=this.$u.$parent.call(this,"u-checkbox-group"),this.parent&&this.parent.children.push(this)},computed:{valueCom(){return this.modelValue},isDisabled(){return""!==this.disabled?this.disabled:!!this.parent&&this.parent.disabled},isLabelDisabled(){return""!==this.labelDisabled?this.labelDisabled:!!this.parent&&this.parent.labelDisabled},checkboxSize(){return this.size?this.size:this.parent?this.parent.size:34},checkboxIconSize(){return this.iconSize?this.iconSize:this.parent?this.parent.iconSize:20},elActiveColor(){return this.activeColor?this.activeColor:this.parent?this.parent.activeColor:"primary"},elShape(){return this.shape?this.shape:this.parent?this.parent.shape:"square"},iconStyle(){let e={};return this.elActiveColor&&this.valueCom&&!this.isDisabled&&(e.borderColor=this.elActiveColor,e.backgroundColor=this.elActiveColor),e.width=this.$u.addUnit(this.checkboxSize),e.height=this.$u.addUnit(this.checkboxSize),e},iconColor(){return this.valueCom?"#ffffff":"transparent"},iconClass(){let e=[];return e.push("u-checkbox__icon-wrap--"+this.elShape),1==this.valueCom&&e.push("u-checkbox__icon-wrap--checked"),this.isDisabled&&e.push("u-checkbox__icon-wrap--disabled"),this.valueCom&&this.isDisabled&&e.push("u-checkbox__icon-wrap--disabled--checked"),e.join(" ")},checkboxStyle(){let e={};return this.parent&&this.parent.width&&(e.width=this.parent.width,e.flex=`0 0 ${this.parent.width}`),this.parent&&this.parent.wrap&&(e.width="100%",e.flex="0 0 100%"),e}},mounted(){this._emitEvent()},watch:{valueCom:{handler:function(e,t){this._emitEvent()}}},methods:{_emitEvent(){let e={value:this.valueCom,name:this.name};this.parent&&this.parent.emitEvent&&this.parent.emitEvent(e)},onClickLabel(){this.isLabelDisabled||this.isDisabled||this.setValue()},toggle(){this.isDisabled||this.setValue()},emitEvent(){let e={value:!this.valueCom,name:this.name};this.$emit("change",e),this.parent&&this.parent.emitEvent&&this.parent.emitEvent(e)},setValue(){let e=this.valueCom,t=0;if(this.parent&&this.parent.children&&this.parent.children.map((e=>{e.value&&t++})),1==e)this.emitEvent(),this.$emit("input",!e),this.$emit("update:modelValue",!e);else{if(this.parent&&t>=this.parent.max)return this.$u.toast(`最多可选${this.parent.max}`);this.emitEvent(),this.$emit("input",!e),this.$emit("update:modelValue",!e)}}}},[["render",function(r,h,u,c,p,m){const g=F(e("u-icon"),V),f=d;return t(),s(f,{class:"u-checkbox",style:n([m.checkboxStyle])},{default:i((()=>[a(f,{class:l(["u-checkbox__icon-wrap",[m.iconClass]]),onClick:m.toggle,style:n([m.iconStyle])},{default:i((()=>[a(g,{class:"u-checkbox__icon-wrap__icon",name:"checkbox-mark",size:m.checkboxIconSize,color:m.iconColor},null,8,["size","color"])])),_:1},8,["onClick","class","style"]),a(f,{class:"u-checkbox__label",onClick:m.onClickLabel,style:n({fontSize:r.$u.addUnit(u.labelSize)})},{default:i((()=>[o(r.$slots,"default",{},void 0,!0)])),_:3},8,["onClick","style"])])),_:3},8,["style"])}],["__scopeId","data-v-486055df"]]);const j=$({name:"u-numberbox",emits:["update:modelValue","input","change","blur","plus","minus"],props:{value:{type:Number,default:1},modelValue:{type:Number,default:1},bgColor:{type:String,default:"#F2F3F5"},min:{type:Number,default:0},max:{type:Number,default:99999},step:{type:Number,default:1},stepFirst:{type:Number,default:0},stepStrictly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},size:{type:[Number,String],default:26},color:{type:String,default:"#323233"},inputWidth:{type:[Number,String],default:80},inputHeight:{type:[Number,String],default:50},index:{type:[Number,String],default:""},disabledInput:{type:Boolean,default:!1},cursorSpacing:{type:[Number,String],default:100},longPress:{type:Boolean,default:!0},pressTime:{type:[Number,String],default:250},positiveInteger:{type:Boolean,default:!0}},watch:{valueCom(e,t){this.changeFromInner||(this.inputVal=e,this.$nextTick((function(){this.changeFromInner=!1})))},inputVal(e,t){if(""==e)return;let s=0;s=this.isNumber(e)&&e>=this.min&&e<=this.max?e:t,this.positiveInteger&&(e<0||-1!==String(e).indexOf("."))&&(s=t,this.$nextTick((()=>{this.inputVal=t}))),this.handleChange(s,"change")},min(e){void 0!==e&&""!=e&&this.valueCom<e&&this.$emit("input",e)},max(e){void 0!==e&&""!=e&&this.valueCom>e&&this.$emit("input",e)}},data:()=>({inputVal:1,timer:null,changeFromInner:!1,innerChangeTimer:null}),created(){this.inputVal=Number(this.valueCom)},mounted(){},computed:{getCursorSpacing(){return Number(uni.upx2px(this.cursorSpacing))},valueCom(){return this.modelValue}},methods:{btnTouchStart(e){this[e](),this.longPress&&(clearInterval(this.timer),this.timer=null,this.timer=setInterval((()=>{this[e]()}),this.pressTime))},clearTimer(){this.$nextTick((()=>{clearInterval(this.timer),this.timer=null}))},minus(){this.computeVal("minus")},plus(){this.computeVal("plus")},calcPlus(e,t){let s,i,a;try{i=e.toString().split(".")[1].length}catch(l){i=0}try{a=t.toString().split(".")[1].length}catch(l){a=0}return s=Math.pow(10,Math.max(i,a)),((e*s+t*s)/s).toFixed(i>=a?i:a)},calcMinus(e,t){let s,i,a;try{i=e.toString().split(".")[1].length}catch(l){i=0}try{a=t.toString().split(".")[1].length}catch(l){a=0}return s=Math.pow(10,Math.max(i,a)),((e*s-t*s)/s).toFixed(i>=a?i:a)},computeVal(e){if(uni.hideKeyboard(),this.disabled)return;let t=0;if("minus"===e?t=this.stepFirst>0&&this.inputVal==this.stepFirst?this.min:this.calcMinus(this.inputVal,this.step):"plus"===e&&(t=this.stepFirst>0&&this.inputVal<this.stepFirst?this.stepFirst:this.calcPlus(this.inputVal,this.step)),this.stepStrictly){let s=t%this.step;s>0&&(t-=s),this.stepFirst>0&&t>0&&t<this.stepFirst&&("minus"===e?t=0:"plus"===e&&(t=this.stepFirst+(this.step-this.stepFirst%this.step)))}t>this.max?t=this.max:t<this.min&&(t=this.min),this.inputVal=t,this.handleChange(t,e)},onBlur(e){let t=0,s=e.detail.value;if(/(^\d+$)/.test(s)&&0!=s[0]||(t=this.min),t=+s,this.stepFirst>0&&this.inputVal<this.stepFirst&&this.inputVal>0&&(t=this.stepFirst),this.stepStrictly){let e=t%this.step;e>0&&(t-=e),this.stepFirst>0&&t>0&&t<this.stepFirst&&(t=this.stepFirst+(this.step-this.stepFirst%this.step))}t>this.max?t=this.max:t<this.min&&(t=this.min),this.$nextTick((()=>{this.inputVal=t})),this.handleChange(t,"blur")},handleChange(e,t){this.disabled||(this.innerChangeTimer&&(clearTimeout(this.innerChangeTimer),this.innerChangeTimer=null),this.changeFromInner=!0,this.innerChangeTimer=setTimeout((()=>{this.changeFromInner=!1}),150),this.$emit("input",Number(e)),this.$emit("update:modelValue",Number(e)),this.$emit(t,{value:Number(e),index:this.index}))},isNumber:e=>/^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(e)}},[["render",function(e,o,c,p,m,g){const f=d,b=u;return t(),s(f,{class:"u-numberbox"},{default:i((()=>[a(f,{class:l(["u-icon-minus",{"u-icon-disabled":c.disabled||m.inputVal<=c.min}]),onTouchstart:o[0]||(o[0]=r((e=>g.btnTouchStart("minus")),["prevent"])),onTouchend:r(g.clearTimer,["stop","prevent"]),style:n({background:c.bgColor,height:c.inputHeight+"rpx",color:c.color,fontSize:c.size+"rpx",minHeight:"1.4em"})},{default:i((()=>[a(f,{style:n("font-size:"+(Number(c.size)+10)+"rpx"),class:"num-btn"},{default:i((()=>[h("-")])),_:1},8,["style"])])),_:1},8,["onTouchend","class","style"]),a(b,{disabled:c.disabledInput||c.disabled,"cursor-spacing":g.getCursorSpacing,class:l([{"u-input-disabled":c.disabled},"u-number-input"]),modelValue:m.inputVal,"onUpdate:modelValue":o[1]||(o[1]=e=>m.inputVal=e),onBlur:g.onBlur,type:"number",style:n({color:c.color,fontSize:c.size+"rpx",background:c.bgColor,height:c.inputHeight+"rpx",width:c.inputWidth+"rpx"})},null,8,["disabled","cursor-spacing","class","modelValue","onBlur","style"]),a(f,{class:l(["u-icon-plus",{"u-icon-disabled":c.disabled||m.inputVal>=c.max}]),onTouchstart:o[2]||(o[2]=r((e=>g.btnTouchStart("plus")),["prevent"])),onTouchend:r(g.clearTimer,["stop","prevent"]),style:n({background:c.bgColor,height:c.inputHeight+"rpx",color:c.color,fontSize:c.size+"rpx",minHeight:"1.4em"})},{default:i((()=>[a(f,{style:n("font-size:"+(Number(c.size)+10)+"rpx"),class:"num-btn"},{default:i((()=>[h("+")])),_:1},8,["style"])])),_:1},8,["onTouchend","class","style"])])),_:1})}],["__scopeId","data-v-06eb1e00"]]);const E=$({components:{Empty:z,Recommended:N},data:()=>({inArray:c,isLoading:!0,mode:"normal",list:[],total:null,checkedIds:[],totalPrice:"0.00"}),watch:{checkedIds:{handler(e){this.onCalcTotalPrice(),uni.setStorageSync("CartIds",e)},deep:!0,immediate:!1},total(e){p(e),m()}},onShow(e){this.checkedIds=uni.getStorageSync("CartIds"),g()?this.getCartList():this.isLoading=!1},methods:{onCalcTotalPrice(){const e=this,t=e.list.filter((t=>c(t.id,e.checkedIds)));let s=0;t.forEach((e=>{const t=100*e.goods.skuInfo.goods_price;s+=t*e.goods_num})),e.totalPrice=(s/100).toFixed(2)},getCartList(){const e=this;e.isLoading=!0,w().then((t=>{e.list=t.data.list,e.total=t.data.cartTotal,e.onClearInvalidId()})).finally((()=>e.isLoading=!1))},onClearInvalidId(){const e=this,t=e.list.map((e=>e.id));e.checkedIds=f(t,e.checkedIds)},handleToggleMode(){this.mode="normal"==this.mode?"edit":"normal"},onChangeStepper({value:e},t){t.goods_num!=e&&(t.debounceHandle||(t.oldValue=t.goods_num,t.debounceHandle=b(this.onUpdateCartNum,500)),t.goods_num=e,t.debounceHandle(t,t.oldValue,e))},onUpdateCartNum(e,t,s){const i=this;B(e.goods_id,e.goods_sku_id,s).then((t=>{i.total=t.data.cartTotal,i.onCalcTotalPrice(),e.debounceHandle=null})).catch((s=>{e.goods_num=t,setTimeout((()=>i.$toast(s.errMsg)),10)}))},onTargetGoods(e){this.$navTo("pages/goods/detail",{goodsId:e})},onTargetIndex(){this.$navTo("pages/index/index")},handleCheckItem(e){const{checkedIds:t}=this,s=t.findIndex((t=>t===e));s<0?t.push(e):t.splice(s,1)},handleCheckAll(){const{checkedIds:e,list:t}=this;this.checkedIds=e.length===t.length?[]:t.map((e=>e.id))},handleOrder(){const e=this;if(e.checkedIds.length){const t=e.checkedIds.join();e.$navTo("pages/checkout/index",{mode:"cart",cartIds:t})}},handleDelete(){const e=this;if(!e.checkedIds.length)return!1;uni.showModal({title:"友情提示",content:"您确定要删除该商品吗?",showCancel:!0,success({confirm:t}){t&&e.onClearCart()}})},onClearCart(){const e=this;D(e.checkedIds).then((t=>{e.getCartList(),e.handleToggleMode()}))}}},[["render",function(o,u,c,p,m,g){const f=v,b=d,V=F(e("u-checkbox"),L),$=I,z=T,N=F(e("u-number-box"),j),w=S("empty"),B=S("recommended");return t(),s(b,{class:"container",style:n(o.appThemeStyle)},{default:i((()=>[m.list.length?(t(),s(b,{key:0,class:"head-info"},{default:i((()=>[a(b,{class:"cart-total"},{default:i((()=>[a(f,null,{default:i((()=>[h("共")])),_:1}),a(f,{class:"active"},{default:i((()=>[h(_(m.total),1)])),_:1}),a(f,null,{default:i((()=>[h("件商品")])),_:1})])),_:1}),a(b,{class:"cart-edit",onClick:u[0]||(u[0]=e=>g.handleToggleMode())},{default:i((()=>["normal"==m.mode?(t(),s(b,{key:0,class:"normal"},{default:i((()=>[a(f,{class:"icon iconfont icon-bianji"}),a(f,null,{default:i((()=>[h("编辑")])),_:1})])),_:1})):C("",!0),"edit"==m.mode?(t(),s(b,{key:1,class:"edit"},{default:i((()=>[a(f,null,{default:i((()=>[h("完成")])),_:1})])),_:1})):C("",!0)])),_:1})])),_:1})):C("",!0),m.list.length?(t(),s(b,{key:1,class:"cart-list"},{default:i((()=>[(t(!0),k(x,null,y(m.list,((e,l)=>(t(),s(b,{class:"cart-item",key:l},{default:i((()=>[a($,{class:"item-radio",onClick:r((t=>g.handleCheckItem(e.id)),["stop"])},{default:i((()=>[a(V,{modelValue:m.inArray(e.id,m.checkedIds),shape:"circle",activeColor:o.appTheme.mainBg},null,8,["modelValue","activeColor"])])),_:2},1032,["onClick"]),a(b,{class:"goods-image",onClick:t=>g.onTargetGoods(e.goods_id)},{default:i((()=>[a(z,{class:"image",src:e.goods.goods_image,mode:"scaleToFill"},null,8,["src"])])),_:2},1032,["onClick"]),a(b,{class:"item-content"},{default:i((()=>[a(b,{class:"goods-title",onClick:t=>g.onTargetGoods(e.goods_id)},{default:i((()=>[a(f,{class:"twoline-hide"},{default:i((()=>[h(_(e.goods.goods_name),1)])),_:2},1024)])),_:2},1032,["onClick"]),a(b,{class:"goods-props clearfix"},{default:i((()=>[(t(!0),k(x,null,y(e.goods.skuInfo.goods_props,((e,l)=>(t(),s(b,{class:"goods-props-item",key:l},{default:i((()=>[a(f,null,{default:i((()=>[h(_(e.value.name),1)])),_:2},1024)])),_:2},1024)))),128))])),_:2},1024),a(b,{class:"item-foot"},{default:i((()=>[a(b,{class:"goods-price"},{default:i((()=>[a(f,{class:"unit"},{default:i((()=>[h("¥")])),_:1}),a(f,{class:"value"},{default:i((()=>[h(_(e.goods.skuInfo.goods_price),1)])),_:2},1024)])),_:2},1024),a(b,{class:"stepper"},{default:i((()=>[a(N,{min:1,modelValue:e.goods_num,step:1,onChange:t=>g.onChangeStepper(t,e)},null,8,["modelValue","onChange"])])),_:2},1024)])),_:2},1024)])),_:2},1024)])),_:2},1024)))),128))])),_:1})):C("",!0),m.list.length?C("",!0):(t(),s(w,{key:2,isLoading:m.isLoading,"custom-style":{padding:"180rpx 50rpx"},tips:"您的购物车是空的, 快去逛逛吧"},{slot:i((()=>[a(b,{class:"empty-ipt",onClick:u[1]||(u[1]=e=>g.onTargetIndex())},{default:i((()=>[a(f,null,{default:i((()=>[h("去逛逛")])),_:1})])),_:1})])),_:1},8,["isLoading"])),a(B),m.list.length?(t(),s(b,{key:3,class:"footer-fixed"},{default:i((()=>[a(b,{class:"all-radio"},{default:i((()=>[a(V,{modelValue:m.checkedIds.length>0&&m.checkedIds.length===m.list.length,shape:"circle",activeColor:o.appTheme.mainBg,onChange:u[2]||(u[2]=e=>g.handleCheckAll())},{default:i((()=>[h("全选")])),_:1},8,["modelValue","activeColor"])])),_:1}),a(b,{class:"total-info"},{default:i((()=>[a(f,null,{default:i((()=>[h("合计:")])),_:1}),a(b,{class:"goods-price"},{default:i((()=>[a(f,{class:"unit"},{default:i((()=>[h("¥")])),_:1}),a(f,{class:"value"},{default:i((()=>[h(_(m.totalPrice),1)])),_:1})])),_:1})])),_:1}),a(b,{class:"cart-action"},{default:i((()=>[a(b,{class:"btn-wrapper"},{default:i((()=>["normal"==m.mode?(t(),s(b,{key:0,class:l(["btn-item btn-main",{disabled:""==m.checkedIds.join()}]),onClick:u[3]||(u[3]=e=>g.handleOrder())},{default:i((()=>[a(f,null,{default:i((()=>[h("去结算 "+_(m.checkedIds.length>0?`(${m.total})`:""),1)])),_:1})])),_:1},8,["class"])):C("",!0),"edit"==m.mode?(t(),s(b,{key:1,class:l(["btn-item btn-main",{disabled:!m.checkedIds.length}]),onClick:u[4]||(u[4]=e=>g.handleDelete())},{default:i((()=>[a(f,null,{default:i((()=>[h("删除")])),_:1})])),_:1},8,["class"])):C("",!0)])),_:1})])),_:1})])),_:1})):C("",!0)])),_:1},8,["style"])}],["__scopeId","data-v-90f98acc"]]);export{E as default};