index-1f8fa557.js 9.0 KB

1
  1. import{q as Q,V as P,v as H,t as j,d as G,l as W,i as tt,x as mt,T as gt,h as S,z as et,w as O,aq as pt,ar as St,aN as kt,o as at,at as wt,au as yt,ak as _t,al as xt,D as It,f as l,ap as U,n as it,Z as A,G as bt,H as N,K as ot,X as Ct,aO as Tt,g as $,m as Ot,B as Dt,L as Pt}from"./index-bd231973.js";import{u as At,S as Lt}from"./student-register-store-75dcb3d7.js";import{R as Et,a as Bt}from"./index-c94f3278.js";import{C as z}from"./index-220a3c7e.js";import{I as K}from"./index-79eb5f07.js";import{T as Rt}from"./index-a0bbe1f7.js";const[st,L]=Q("swipe"),jt={loop:P,width:H,height:H,vertical:Boolean,autoplay:j(0),duration:j(500),touchable:P,lazyRender:Boolean,initialSwipe:j(0),indicatorColor:String,showIndicators:P,stopPropagation:P},lt=Symbol(st);var Nt=G({name:st,props:jt,emits:["change","dragStart","dragEnd"],setup(t,{emit:i,slots:n}){const o=W(),u=W(),e=tt({rect:null,width:0,height:0,offset:0,active:0,swiping:!1});let k=!1;const m=mt(),{children:w,linkChildren:f}=gt(lt),s=S(()=>w.length),d=S(()=>e[t.vertical?"height":"width"]),g=S(()=>t.vertical?m.deltaY.value:m.deltaX.value),_=S(()=>e.rect?(t.vertical?e.rect.height:e.rect.width)-d.value*s.value:0),E=S(()=>d.value?Math.ceil(Math.abs(_.value)/d.value):s.value),B=S(()=>s.value*d.value),x=S(()=>(e.active+s.value)%s.value),M=S(()=>{const a=t.vertical?"vertical":"horizontal";return m.direction.value===a}),nt=S(()=>{const a={transitionDuration:`${e.swiping?0:t.duration}ms`,transform:`translate${t.vertical?"Y":"X"}(${e.offset}px)`};if(d.value){const r=t.vertical?"height":"width",c=t.vertical?"width":"height";a[r]=`${B.value}px`,a[c]=t[c]?`${t[c]}px`:""}return a}),ct=a=>{const{active:r}=e;return a?t.loop?N(r+a,-1,s.value):N(r+a,0,E.value):r},V=(a,r=0)=>{let c=a*d.value;t.loop||(c=Math.min(c,-_.value));let p=r-c;return t.loop||(p=N(p,_.value,0)),p},y=({pace:a=0,offset:r=0,emitChange:c})=>{if(s.value<=1)return;const{active:p}=e,h=ct(a),T=V(h,r);if(t.loop){if(w[0]&&T!==_.value){const R=T<_.value;w[0].setOffset(R?B.value:0)}if(w[s.value-1]&&T!==0){const R=T>0;w[s.value-1].setOffset(R?-B.value:0)}}e.active=h,e.offset=T,c&&h!==p&&i("change",x.value)},D=()=>{e.swiping=!0,e.active<=-1?y({pace:s.value}):e.active>=s.value&&y({pace:-s.value})},rt=()=>{D(),m.reset(),A(()=>{e.swiping=!1,y({pace:-1,emitChange:!0})})},J=()=>{D(),m.reset(),A(()=>{e.swiping=!1,y({pace:1,emitChange:!0})})};let q;const b=()=>clearTimeout(q),C=()=>{b(),+t.autoplay>0&&s.value>1&&(q=setTimeout(()=>{J(),C()},+t.autoplay))},I=(a=+t.initialSwipe)=>{if(!o.value)return;const r=()=>{var c,p;if(!U(o)){const h={width:o.value.offsetWidth,height:o.value.offsetHeight};e.rect=h,e.width=+((c=t.width)!=null?c:h.width),e.height=+((p=t.height)!=null?p:h.height)}s.value&&(a=Math.min(s.value-1,a),a===-1&&(a=s.value-1)),e.active=a,e.swiping=!0,e.offset=V(a),w.forEach(h=>{h.setOffset(0)}),C()};U(o)?it().then(r):r()},F=()=>I(e.active);let X;const ut=a=>{!t.touchable||a.touches.length>1||(m.start(a),k=!1,X=Date.now(),b(),D())},dt=a=>{t.touchable&&e.swiping&&(m.move(a),M.value&&(!t.loop&&(e.active===0&&g.value>0||e.active===s.value-1&&g.value<0)||(bt(a,t.stopPropagation),y({offset:g.value}),k||(i("dragStart",{index:x.value}),k=!0))))},Y=()=>{if(!t.touchable||!e.swiping)return;const a=Date.now()-X,r=g.value/a;if((Math.abs(r)>.25||Math.abs(g.value)>d.value/2)&&M.value){const p=t.vertical?m.offsetY.value:m.offsetX.value;let h=0;t.loop?h=p>0?g.value>0?-1:1:0:h=-Math[g.value>0?"ceil":"floor"](g.value/d.value),y({pace:h,emitChange:!0})}else g.value&&y({pace:0});k=!1,e.swiping=!1,i("dragEnd",{index:x.value}),C()},ft=(a,r={})=>{D(),m.reset(),A(()=>{let c;t.loop&&a===s.value?c=e.active===0?0:a:c=a%s.value,r.immediate?A(()=>{e.swiping=!1}):e.swiping=!1,y({pace:c-e.active,emitChange:!0})})},ht=(a,r)=>{const c=r===x.value,p=c?{backgroundColor:t.indicatorColor}:void 0;return l("i",{style:p,class:L("indicator",{active:c})},null)},vt=()=>{if(n.indicator)return n.indicator({active:x.value,total:s.value});if(t.showIndicators&&s.value>1)return l("div",{class:L("indicators",{vertical:t.vertical})},[Array(s.value).fill("").map(ht)])};return et({prev:rt,next:J,state:e,resize:F,swipeTo:ft}),f({size:d,props:t,count:s,activeIndicator:x}),O(()=>t.initialSwipe,a=>I(+a)),O(s,()=>I(e.active)),O(()=>t.autoplay,C),O([pt,St,()=>t.width,()=>t.height],F),O(kt(),a=>{a==="visible"?C():b()}),at(I),wt(()=>I(e.active)),yt(()=>I(e.active)),_t(b),xt(b),It("touchmove",dt,{target:u}),()=>{var a;return l("div",{ref:o,class:L()},[l("div",{ref:u,style:nt.value,class:L("track",{vertical:t.vertical}),onTouchstartPassive:ut,onTouchend:Y,onTouchcancel:Y},[(a=n.default)==null?void 0:a.call(n)]),vt()])}}});const oe=ot(Nt),[$t,zt]=Q("swipe-item");var Gt=G({name:$t,setup(t,{slots:i}){let n;const o=tt({offset:0,inited:!1,mounted:!1}),{parent:u,index:e}=Ct(lt);if(!u){console.error("[Vant] <SwipeItem> must be a child component of <Swipe>.");return}const k=S(()=>{const f={},{vertical:s}=u.props;return u.size.value&&(f[s?"height":"width"]=`${u.size.value}px`),o.offset&&(f.transform=`translate${s?"Y":"X"}(${o.offset}px)`),f}),m=S(()=>{const{loop:f,lazyRender:s}=u.props;if(!s||n)return!0;if(!o.mounted)return!1;const d=u.activeIndicator.value,g=u.count.value-1,_=d===0&&f?g:d-1,E=d===g&&f?0:d+1;return n=e.value===d||e.value===_||e.value===E,n}),w=f=>{o.offset=f};return at(()=>{it(()=>{o.mounted=!0})}),et({setOffset:w}),()=>{var f;return l("div",{class:zt(),style:k.value},[m.value?(f=i.default)==null?void 0:f.call(i):null])}}});const se=ot(Gt),Mt=""+new URL("icon-sell-out-437e8d6c.png",import.meta.url).href,Vt="_addGoodsCart_1x0mj_1",Jt="_addCartBtn_1x0mj_18",qt="_goodsSection_1x0mj_26",Ft="_sellOut_1x0mj_33",Xt="_goodsImg_1x0mj_45",Yt="_goodsPrice_1x0mj_51",Ht="_goodsStore_1x0mj_60",Wt="_title_1x0mj_65",Ut="_radio_1x0mj_70",v={addGoodsCart:Vt,addCartBtn:Jt,goodsSection:qt,sellOut:Ft,goodsImg:Xt,goodsPrice:Yt,goodsStore:Ht,title:Wt,"radio-group":"_radio-group_1x0mj_70",radio:Ut};function Kt(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!Pt(t)}const Z=At(),le=G({name:"add-goods-cart",props:{show:{type:Boolean,default:!1},item:{type:Object,default:{}},defaultRadio:{type:Number,default:0},showType:{type:String,default:"cart"},onClose:{type:Function,default:()=>{}}},watch:{show(t){t&&(this.totalData={},this.total=1,this.radio="",this.setList())}},data(){return{radio:"",total:1,totalData:{},skuStockList:[]}},computed:{selectItem(){const t=this.radio,i=this.skuStockList.find(n=>n.id==t);if(i){let n=i.stock-i.lockStock;return{...i,stock:n}}return{stock:0}}},mounted(){this.setList()},methods:{setList(){let t=[];const i=JSON.parse(JSON.stringify(this.item));if(Array.isArray(i.skuStockList)&&(t=i.skuStockList.map(o=>{if(o.pic=o.pic||i.pic,o.cartNum=0,o.spData){const u=JSON.parse(o.spData);let e="";u.forEach(k=>{e+=`${k.value}`}),o.spDataJson=e}else o.spDataJson="默认";return o.lockStock=o.lockStock>0?o.lockStock:0,{...o}})),!t.length)return t;let n=0;if(this.defaultRadio){let o=t.findIndex(u=>u.id==this.defaultRadio);n=o>-1?o:0}this.radio=t[n].id,this.skuStockList=t},async onAddCart(){const t=this.selectItem,i=this.item,n={pic:i.pic,name:i.name,brandName:i.brandName,productSn:i.productSn,price:t.price,originalPrice:i.originalPrice,productSkuId:t.id,stock:t.stock,quantity:this.total,productId:i.id,spDataJson:t.spDataJson,hidden:this.showType==="cart"?0:1,promoterId:this.$route.query.promoterId?this.$route.query.promoterId:void 0};try{let o=!1;Z.getGoods.forEach(u=>{u.id===n.productId&&u.productSkuId===n.productSkuId&&(o=!0,u.quantity+=n.quantity)}),o||Z.setGoods(n),Tt("添加成功"),this.onClose()}catch(o){}},setProductStock(t){for(let i=0;i<this.skuStockList.length;i++)this.skuStockList[i].id===this.radio&&(this.skuStockList[i].cartNum=t)}},render(){return l("div",{class:v.addGoodsCart},[l(z,{titleStyle:{paddingLeft:"12px"}},{icon:()=>l("div",{class:v.goodsSection},[l(K,{src:this.selectItem.pic,class:v.goodsImg,fit:"cover"},null),this.selectItem.stock<=0&&l("div",{class:v.sellOut},[l(K,{src:Mt,fit:"cover",class:v.sellOutImg},null)])]),title:()=>l("div",{class:v.goodsInfo},[l("p",{class:v.goodsPrice},[l("span",null,[$("¥")]),Ot(this.selectItem.price)]),l("p",{class:v.goodsStore},[$("库存:"),this.selectItem.stock])])}),l(z,null,{title:()=>l("div",{class:v.title},[$("规格")]),label:()=>{let t;return l(Et,{class:v["radio-group"],modelValue:this.radio},Kt(t=this.skuStockList.map(i=>{const n=i.id===this.radio,o=n?"primary":"default";return l(Bt,{class:v.radio,name:i.id,onClick:()=>{this.radio!=i.id&&(this.radio=i.id)}},{default:()=>[l(Rt,{size:"large",plain:n,type:o},{default:()=>[i.spDataJson]})]})}))?t:{default:()=>[t]})}}),l(z,{title:"购买数量",style:{margin:"12px 0"},border:!1,titleClass:v.title,center:!0},{default:()=>[l(Lt,{modelValue:this.total,"onUpdate:modelValue":t=>this.total=t,inputWidth:"50px",theme:"round",buttonSize:"24px",max:this.selectItem.stock>200?200:this.selectItem.stock,min:1,disabled:this.selectItem.stock<=0,integer:!0},null)]}),l("div",{class:["btnGroup"],style:{marginBottom:"8px"}},[l(Dt,{block:!0,type:"primary",text:"确定",class:v.addCartBtn,disabled:this.selectItem.stock<=0,onClick:()=>this.onAddCart()},null)])])}});export{le as A,oe as S,se as a,Mt as i};