Files
JayuCloud/docs/product/Frontend/assets/CartView-Cc_j9pPN.js
T

2 lines
12 KiB
JavaScript
Raw Normal View History

2026-03-21 17:08:36 +08:00
import{d as be,w as Te,o as Se,i as c,b as v,e as n,c as i,f as d,s as Y,m as B,g as b,y as K,z as Q,u as xe,r as m,h as T,a2 as L,ah as Ae,B as De,ai as Me,Q as $e,M as Pe,j as u,Y as Ye,l as $,t as r,R as se,aj as Be,_ as Ne,ak as Ve,n as Oe,al as qe,V as He,C as Ue,am as ze,a1 as Fe,G as Ee}from"./index-bPsB4P3d.js";import{c as je}from"./coupon-CKLfJaZ0.js";import{o as Re}from"./order-h2S2n1cW.js";import{s as Ke}from"./shop-DXUqoVUd.js";import{u as Qe}from"./user-BRXmSDmz.js";const Le={class:"page"},Ge={class:"header"},Je={class:"content"},We={class:"item-row"},Xe=["onClick"],Ze=["src","alt"],et={key:1},tt={class:"item-main"},at=["onClick"],nt={class:"price"},ot=["onClick"],st={class:"value"},lt=["onClick"],ut={class:"value"},it={key:0,class:"duration"},rt={class:"actions"},dt={class:"qty"},ct={class:"coupon-row"},pt={key:0,class:"coupon-discount"},vt={class:"summary-row"},mt={class:"summary-row"},ft={key:0,class:"summary-row"},yt={class:"summary-row total"},_t={key:0,class:"footer"},gt={class:"modal-section"},kt={key:0,class:"artist-list"},Ct=["onClick"],ht=["src","alt"],wt={class:"modal-section"},It={class:"helper"},f="NONE",bt=be({__name:"CartView",setup(Tt){const H=xe(),z=Fe("updateCartCount",async()=>{}),y=m([]),F=m({}),S=m([]),l=m(null),p=m(f),N=m(!1),V=m(!1),U=m(!1),_=m(null),O=m([]),x=m(),A=m(""),P=m(""),D=T(()=>y.value.filter(t=>t.selected)),G=T(()=>D.value.length),le=T(()=>D.value.reduce((t,e)=>t+e.quantity,0)),M=T(()=>D.value.reduce((t,e)=>t+e.price*e.quantity,0)),E=T(()=>j(l.value,M.value)),J=T(()=>Math.max(0,M.value-E.value)),ue=T(()=>_.value?"为 "+_.value.productTitle+" 选择预约信息":"选择预约信息"),ie=T(()=>{const t=[];return P.value&&t.push("门店营业时间:"+P.value),_.value?.approximateDuration&&t.push("预计时长:"+_.value.approximateDuration),t.join(" · ")||"请选择至少晚于当前 5 分钟的预约时间"}),W=()=>{const t=new Date;return t.setSeconds(0,0),t.setMinutes(t.getMinutes()+5),t},re=t=>{const e=new Date(t);return e.setHours(0,0,0,0),e.getTime()},w=t=>`${t.sourceType||"USER_COUPON"}:${t.id}`,j=(t,e)=>{if(!t||e<=0)return 0;if(t.couponType===1){const o=Number(t.discountValue||0);return o?e-e*o/10:0}return t.couponType===2?Number(t.reduceAmount||0):0},X=t=>{const e=t.sourceType==="SYSTEM_VIP"?"[VIP 自动券]":"[用户券]",o=t.couponType===1?`${t.discountValue}折`:`满${t.minAmount}减${t.reduceAmount}`;return`${e} ${t.couponName} ${o}`},de=t=>t.filter(e=>e.sourceType==="SYSTEM_VIP").sort((e,o)=>j(o,M.value)-j(e,M.value))[0]||null,Z=t=>{H.push("/product/"+t.productId)},ee=async()=>{const t=await L.getCartList();y.value=t.map(e=>({...e,selected:!0,originalProductImage:e.productImage,productImage:"",appointmentTime:e.appointmentTime})),N.value=!1,p.value=f,l.value=null,await Promise.all([ce(),q()])},ce=async()=>{for(const t of y.value){if(!t.originalProductImage)continue;const e=t.originalProductImage.replace(/<[^>]*>/g,"").match(/\/api\/file\/get\/(\d+)/);if(!e?.[1])continue;const o=e[1];try{F.value[o]||(F.value[o]=await Ae.getSignedUrl(Number(o))),t.productImage=F.value[o]||""}catch{t.productImage=""}}},q=async()=>{const t=l.value?w(l.value):p.value,e=D.value[0]?.shopId;if(!D.value.length||M.value<=0){S.value=[],l.value=null,p.value=f;return}try{const o=new Set;D.value.forEach(g=>{g.tagNames?.split(",").map(C=>C.trim()).forEach(C=>{C&&o.add(C)})});const s=await je.getAvailableCoupons(Array.from(o).join(","),M.value,e);S.value=Array.isArray(s)?s:[];const k=S.value.find(g=>w(g)===t)||null;if(k){l.value=k,p.value=w(k);return}if(N.value&&t===f){l.value=null,p.value=f;return}N.value=!1;const I=de(S.value);I?(l.value=I,p.value=w(I)):(l.value=null,p.value=f)}catch(o){console.error("获取可用优惠券失败:",o),S.value=[],l.value=null,p.value=f}},te=async(t,e)=>{const o=t.quantity+e;if(!(o<1||o>99)){t.quantity=o;try{await L.updateCartQuantity({productId:t.productId,quantity:o}),await Promise.all([q(),z()])}catch{t.quantity-=e,c.error("更新数量失败")}}},pe=async t=>{try{await L.removeFromCart(t.productId),y.value=y.value.filter(e=>e.id!==t.id),await Promise.all(