index-daebdf8c.js 8.9 KB

1
  1. import{q as Z,V as P,v as H,t as j,d as G,l as W,i as tt,x as mt,X as gt,h as S,z as et,w as D,al as pt,am as St,aK as kt,o as at,ao as wt,ap as yt,af as _t,ag as xt,D as It,f as l,ak as K,n as it,az as A,G as bt,H as $,K as st,_ as Ct,aL as Tt,g as z,m as Dt,B as Ot,M as Pt}from"./index-4fdf58de.js";import{u as At,S as Lt}from"./student-register-store-7634c5ed.js";import{R as Et,a as Bt}from"./index-9b58a8fa.js";import{C as N}from"./index-c2b2e34a.js";import{I as U}from"./index-7fda46b5.js";import{T as Rt}from"./index-3e176cab.js";const[ot,L]=Z("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(ot);var $t=G({name:ot,props:jt,emits:["change","dragStart","dragEnd"],setup(t,{emit:i,slots:n}){const s=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),o=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*o.value:0),E=S(()=>d.value?Math.ceil(Math.abs(_.value)/d.value):o.value),B=S(()=>o.value*d.value),x=S(()=>(e.active+o.value)%o.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?$(r+a,-1,o.value):$(r+a,0,E.value):r},J=(a,r=0)=>{let c=a*d.value;t.loop||(c=Math.min(c,-_.value));let p=r-c;return t.loop||(p=$(p,_.value,0)),p},y=({pace:a=0,offset:r=0,emitChange:c})=>{if(o.value<=1)return;const{active:p}=e,h=ct(a),T=J(h,r);if(t.loop){if(w[0]&&T!==_.value){const R=T<_.value;w[0].setOffset(R?B.value:0)}if(w[o.value-1]&&T!==0){const R=T>0;w[o.value-1].setOffset(R?-B.value:0)}}e.active=h,e.offset=T,c&&h!==p&&i("change",x.value)},O=()=>{e.swiping=!0,e.active<=-1?y({pace:o.value}):e.active>=o.value&&y({pace:-o.value})},rt=()=>{O(),m.reset(),A(()=>{e.swiping=!1,y({pace:-1,emitChange:!0})})},V=()=>{O(),m.reset(),A(()=>{e.swiping=!1,y({pace:1,emitChange:!0})})};let F;const b=()=>clearTimeout(F),C=()=>{b(),+t.autoplay>0&&o.value>1&&(F=setTimeout(()=>{V(),C()},+t.autoplay))},I=(a=+t.initialSwipe)=>{if(!s.value)return;const r=()=>{var c,p;if(!K(s)){const h={width:s.value.offsetWidth,height:s.value.offsetHeight};e.rect=h,e.width=+((c=t.width)!=null?c:h.width),e.height=+((p=t.height)!=null?p:h.height)}o.value&&(a=Math.min(o.value-1,a),a===-1&&(a=o.value-1)),e.active=a,e.swiping=!0,e.offset=J(a),w.forEach(h=>{h.setOffset(0)}),C()};K(s)?it().then(r):r()},q=()=>I(e.active);let X;const ut=a=>{!t.touchable||a.touches.length>1||(m.start(a),k=!1,X=Date.now(),b(),O())},dt=a=>{t.touchable&&e.swiping&&(m.move(a),M.value&&(!t.loop&&(e.active===0&&g.value>0||e.active===o.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={})=>{O(),m.reset(),A(()=>{let c;t.loop&&a===o.value?c=e.active===0?0:a:c=a%o.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:o.value});if(t.showIndicators&&o.value>1)return l("div",{class:L("indicators",{vertical:t.vertical})},[Array(o.value).fill("").map(ht)])};return et({prev:rt,next:V,state:e,resize:q,swipeTo:ft}),f({size:d,props:t,count:o,activeIndicator:x}),D(()=>t.initialSwipe,a=>I(+a)),D(o,()=>I(e.active)),D(()=>t.autoplay,C),D([pt,St,()=>t.width,()=>t.height],q),D(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:s,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 se=st($t),[zt,Nt]=Z("swipe-item");var Gt=G({name:zt,setup(t,{slots:i}){let n;const s=tt({offset:0,inited:!1,mounted:!1}),{parent:u,index:e}=Ct(lt);if(!u)return;const k=S(()=>{const f={},{vertical:o}=u.props;return u.size.value&&(f[o?"height":"width"]=`${u.size.value}px`),s.offset&&(f.transform=`translate${o?"Y":"X"}(${s.offset}px)`),f}),m=S(()=>{const{loop:f,lazyRender:o}=u.props;if(!o||n)return!0;if(!s.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=>{s.offset=f};return at(()=>{it(()=>{s.mounted=!0})}),et({setOffset:w}),()=>{var f;return l("div",{class:Nt(),style:k.value},[m.value?(f=i.default)==null?void 0:f.call(i):null])}}});const oe=st(Gt),Mt=""+new URL("icon-sell-out-437e8d6c.png",import.meta.url).href,Jt="_addGoodsCart_1x0mj_1",Vt="_addCartBtn_1x0mj_18",Ft="_goodsSection_1x0mj_26",qt="_sellOut_1x0mj_33",Xt="_goodsImg_1x0mj_45",Yt="_goodsPrice_1x0mj_51",Ht="_goodsStore_1x0mj_60",Wt="_title_1x0mj_65",Kt="_radio_1x0mj_70",v={addGoodsCart:Jt,addCartBtn:Vt,goodsSection:Ft,sellOut:qt,goodsImg:Xt,goodsPrice:Yt,goodsStore:Ht,title:Wt,"radio-group":"_radio-group_1x0mj_70",radio:Kt};function Ut(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!Pt(t)}const Q=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(s=>{if(s.pic=s.pic||i.pic,s.cartNum=0,s.spData){const u=JSON.parse(s.spData);let e="";u.forEach(k=>{e+=`${k.value}`}),s.spDataJson=e}else s.spDataJson="默认";return s.lockStock=s.lockStock>0?s.lockStock:0,{...s}})),!t.length)return t;let n=0;if(this.defaultRadio){let s=t.findIndex(u=>u.id==this.defaultRadio);n=s>-1?s: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 s=!1;Q.getGoods.forEach(u=>{u.id===n.productId&&u.productSkuId===n.productSkuId&&(s=!0,u.quantity+=n.quantity)}),s||Q.setGoods(n),Tt("添加成功"),this.onClose()}catch(s){}},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(N,{titleStyle:{paddingLeft:"12px"}},{icon:()=>l("div",{class:v.goodsSection},[l(U,{src:this.selectItem.pic,class:v.goodsImg,fit:"cover"},null),this.selectItem.stock<=0&&l("div",{class:v.sellOut},[l(U,{src:Mt,fit:"cover",class:v.sellOutImg},null)])]),title:()=>l("div",{class:v.goodsInfo},[l("p",{class:v.goodsPrice},[l("span",null,[z("¥")]),Dt(this.selectItem.price)]),l("p",{class:v.goodsStore},[z("库存:"),this.selectItem.stock])])}),l(N,null,{title:()=>l("div",{class:v.title},[z("规格")]),label:()=>{let t;return l(Et,{class:v["radio-group"],modelValue:this.radio},Ut(t=this.skuStockList.map(i=>{const n=i.id===this.radio,s=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:s},{default:()=>[i.spDataJson]})]})}))?t:{default:()=>[t]})}}),l(N,{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(Ot,{block:!0,type:"primary",text:"确定",class:v.addCartBtn,disabled:this.selectItem.stock<=0,onClick:()=>this.onAddCart()},null)])])}});export{le as A,se as S,oe as a,Mt as i};