var q=Object.defineProperty;var I=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var B=(u,s,r)=>s in u?q(u,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):u[s]=r,L=(u,s)=>{for(var r in s||(s={}))F.call(s,r)&&B(u,r,s[r]);if(I)for(var r of I(s))k.call(s,r)&&B(u,r,s[r]);return u};import{d as M,M as d,a4 as H,a5 as G,a6 as W,b as t,a3 as _,m as $,p as N,G as D,a0 as J,j as S,P as z,F as E,T as V}from"./vendor.2bcdc9cf.js";/* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css */import{c as o,f as K}from"./cart.2a3b730f.js";import{s as i}from"./index.module.3bc378ff.js";import{A as Q}from"./index.e7c25db6.js";import{r as y,m as A,C as X,s as x}from"./index.f45ba589.js";import{C as Y,P as Z}from"./index.b51c1990.js";import{U as ee,C as te,a as ae}from"./index.71215e22.js";import{a as O,r as oe}from"./address.6eabc372.js";import{C as re}from"./index.8f85fe36.js";/* empty css *//* empty css *//* empty css */import"./item.3ccc7112.js";import"./index.ebee95a8.js";var Ne=M({name:"cartConfirm",setup(){const u=d(!0),s=H(),r=d(),n=d({useBalance:!1,balance:0,couponId:""}),C=d([]);G(async()=>{if(u.value=!0,await T(),s.query.cartIds)try{const{code:e,data:a}=await y.post("/api-mall-portal/order/generateConfirmOrder",{params:{cartIds:s.query.cartIds}});e===200&&(o.calcAmount=a.calcAmount,o.cartPromotionItemList=a.cartPromotionItemList,o.memberReceiveAddressList=a.memberReceiveAddressList);const c=(await y.get("/api-student/sysConfig/queryByParamName",{params:{paramName:"payment_channel_action"}})).data.paranValue;C.value=c?JSON.parse(c):[]}catch{}if(u.value=!1,o.memberReceiveAddressList.length){const e=o.memberReceiveAddressList.find(a=>a.defaultStatus)||o.memberReceiveAddressList[0];e&&(r.value=e)}O.id&&(h(L({},O)||{}),oe())});const T=async()=>{try{const{data:e}=await y.get("/api-student/userCashAccount/get");n.value.balance=e.balance||0}catch{}},h=e=>{r.value=e},b=d(!1),p=d(!1),f=d(!1),g=d(),j=()=>{var a;if(!((a=r.value)==null?void 0:a.id)){V("\u8BF7\u9009\u62E9\u6536\u8D27\u5730\u5740");return}if(!b.value){V("\u8BF7\u5148\u9605\u8BFB\u5E76\u540C\u610F\u300A\u4EA7\u54C1\u53CA\u670D\u52A1\u534F\u8BAE\u300B");return}const e=x.user.data;if(!(e==null?void 0:e.student.realName)||!(e==null?void 0:e.student.idCardNo)){f.value=!0;return}R()},P=W(),R=async()=>{var c;const e=o.cartPromotionItemList.reduce((m,l)=>(m.push(l.id),m),[]),a=o.calcAmount.payAmount-o.calcAmount.promotionAmount,v={cartIds:e,memberReceiveAddressId:(c=r.value)==null?void 0:c.id,platformType:x.platformType,orderAmount:Number((a>=0?a:0).toFixed(2)),couponId:n.value.couponId,useBalance:n.value.useBalance};try{const{code:m,data:l}=await y.post("/api-mall-portal/order/generateOrder",{data:v});if(m===200){if(l.order.status===1){P.replace({path:"/shopTrade",query:{orderNo:l==null?void 0:l.order.orderSn,id:l==null?void 0:l.order.id}});return}p.value=!0,g.value=l==null?void 0:l.pay}}catch{}},U=()=>{f.value=!1,console.log(x.user.data),j()},w=()=>{const e=o.calcAmount.payAmount-o.calcAmount.promotionAmount;let a=Number((e>=0?e:0).toFixed(2));return console.log(a),n.value.useBalance&&(a=a-n.value.balance<=0?0:Number((a-n.value.balance).toFixed(2))),a};return()=>t(E,null,[t(re,null,null),u.value?null:t("div",null,[o.cartPromotionItemList.length?t("div",{class:i.cartConfirm},[t("div",{class:i.cartConfirmBox},[t(Q,{item:r.value,setAddress:h},null)]),t("div",{style:{marginTop:"20px"},class:[i.cartBox,i.cartConfirmBox]},[t("div",{class:i.shopBox},[o.cartPromotionItemList.map(e=>t("div",{class:[i.cartItem],style:{marginBottom:"10px"}},[t(_,{price:A(e.price),desc:K(e.productAttr),title:e.productName,thumb:e.productPic,num:e.quantity},null)]))]),t($,{border:!0},{default:()=>[t(ee,{useSystem:"MALL",typeDetail:"MALLCOUPON",orderAmount:o.calcAmount.totalAmount,onCouponSelect:e=>{console.log(e,"coupon");const a=e.map(c=>c.faceValue).reduce((c,m)=>c+m,0),v=e.map(c=>c.couponCodeId).join(",");o.calcAmount.promotionAmount=a,n.value.couponId=v,console.log(n,"coupon")}},null),t(N,{onClick:()=>{console.log(!0,"111"),n.value.useBalance=!n.value.useBalance}},{title:`\u4F59\u989D\u652F\u4ED8\uFF08\u5269\u4F59\uFF1A\uFFE5${A(n.value.balance)}\uFF09`,"right-icon":()=>t(D,{modelValue:n.value.useBalance},null)}),t(N,{border:!1,title:"\u603B\u989D",value:"\xA5 "+A(o.calcAmount.totalAmount)},null)]})]),t("div",{class:i.payProtocol},[t(Y,{showHeader:!0,modelValue:b.value,"onUpdate:modelValue":e=>b.value=e},null),t(J,{buttonText:`\u7ED3\u7B97(${o.cartPromotionItemList.length})`,buttonColor:"var(--van-primary)",disabled:o.cartPromotionItemList.length===0,onSubmit:()=>j()},{default:()=>[t("div",{class:i.confirmBottom},[S("\u5408\u8BA1")," ",t("span",{class:i["price-des"]},[S("\xA5"),A(w())])])]})]),t("div",{style:{height:"var(--van-submit-bar-height)"}},null),t(te,{modelValue:f.value,"onUpdate:modelValue":e=>f.value=e},{default:()=>[t(ae,{onSuccess:U},null)]}),t(z,{show:p.value,closeOnClickOverlay:!1,position:"bottom",round:!0,closeOnPopstate:!0,safeAreaInsetBottom:!0,style:{minHeight:"30%"}},{default:()=>[t(Z,{paymentWay:C.value,modelValue:p.value,"onUpdate:modelValue":e=>p.value=e,orderInfo:g.value,paymentType:"goodsPay",onBackOut:()=>p.value=!1},null)]})]):t(X,{buttonText:"\u53BB\u8D2D\u7269\u8F66",onClick:()=>{P.push({path:"/cart"})}},null)])])}});export{Ne as default};