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-checkout-cashier-inde...

1 lines
6.2 KiB

import{$ as e,T as a,C as t,o,c as s,w as n,n as r,e as l,i as d,a as i,f as c,t as m,b as u,d as h,F as f,k as y,l as p,r as P,y as _}from"./index-4ddb689d.js";import{_ as I}from"./u-modal.9219359e.js";import{r as C}from"./uni-app.es.24af5d4f.js";import{P as S,p as T,a as g,e as b,b as v,c as w,d as x}from"./wechat.58479240.js";import{C as A}from"./index.994d85b2.js";import{P as E}from"./OrderType.16ab6c02.js";import{_ as D}from"./_plugin-vue_export-helper.1b428a4d.js";import"./u-loading.7bd69747.js";import"./u-popup.37b3343e.js";import"./u-icon.e981d1c2.js";const k="cashier/orderInfo",N="cashier/orderPay",U="cashier/tradeQuery";const M={[S.WECHAT.value]:"icon-wechat-pay",[S.ALIPAY.value]:"icon-alipay",[S.BALANCE.value]:"icon-balance-pay"},L={[S.WECHAT.value]:"微信",[S.ALIPAY.value]:"支付宝"};const j=D({components:{CountDown:A},data:()=>({isLoading:!0,disabled:!1,PayMethodEnum:S,PayMethodIconEnum:M,PayMethodClientNameEnum:L,curPaymentItem:null,orderId:null,order:{},personal:{balance:"0.00"},methods:[],showConfirmModal:!1,tempUnifyData:{outTradeNo:"",method:""}}),onLoad({orderId:e}){this.orderId=Number(e),this.getCashierInfo()},methods:{getCashierInfo(){const a=this;var t,o;a.isLoading=!0,(t=a.orderId,o={client:a.platform},e.get(k,{orderId:t,...o})).then((e=>{a.order=e.data.order,a.personal=e.data.personal,a.methods=e.data.paymentMethods,a.isLoading=!1,a.setDefaultPayType(),a.checkOrderPayStatus(),this.performance()}))},setDefaultPayType(){const e=this;if(e.disabled)return;const a=e.methods.findIndex((e=>1==e.is_default));a>-1&&e.handleSelectPayType(a)},checkOrderPayStatus(){const e=this;e.order.pay_status==E.SUCCESS.value&&(e.$toast("恭喜您,订单已付款成功"),e.onSuccessNav())},handleSelectPayType(e){this.curPaymentItem=this.methods[e]},performance(){const e=this;e.order.pay_status==E.PENDING.value&&(e.alipayPerformance(),e.wechatPerformance())},alipayPerformance(){const e=this;e.tempUnifyData=T(),e.tempUnifyData&&e.onTradeQuery(e.tempUnifyData.outTradeNo,e.tempUnifyData.method)},wechatPerformance(){const e=this;e.tempUnifyData=g(e.orderId),e.tempUnifyData&&(e.showConfirmModal=!0)},handleSubmit(){const a=this;var t,o;a.curPaymentItem?a.disabled||(a.disabled=!0,(t=a.orderId,o={method:a.curPaymentItem.method,client:a.platform,extra:a.getExtraAsUnify(a.curPaymentItem.method)},e.post(N,{orderId:t,...o})).then((e=>a.onSubmitCallback(e))).finally((e=>setTimeout((()=>a.disabled=!1),10)))):a.$toast("您还没有选择支付方式")},getExtraAsUnify:e=>e===S.ALIPAY.value?b():e===S.WECHAT.value?v():{},onSubmitCallback(e){const a=this,t=a.curPaymentItem.method,o=e.data.payment;t===S.BALANCE.value&&a.onShowSuccess(e),t===S.ALIPAY.value&&(console.log("paymentData",o),w(o).then((e=>a.onPaySuccess(e))).catch((e=>a.onPayFail(e)))),t===S.WECHAT.value&&(console.log("paymentData",o),x({orderKey:a.orderId,...o}).then((e=>a.onPaySuccess(e))).catch((e=>a.onPayFail(e))))},onPaySuccess({res:e,option:{isRequireQuery:a,outTradeNo:t,method:o}}){if(a)return this.onTradeQuery(t,o),!0;this.onShowSuccess(e)},onShowSuccess({message:e}){this.$toast(e||"订单支付成功"),this.onSuccessNav()},onPayFail(e){console.log("onPayFail",e);const a=e.message||"订单未支付";this.$error(a)},onTradeQuery(a,t){const o=this;var s;(s={outTradeNo:a,method:t,client:o.platform},e.get(U,s)).then((e=>e.data.isPay?o.onShowSuccess(e):o.onPayFail(e))).finally((()=>o.showConfirmModal=!1))},onSuccessNav(){uni.$emit("syncRefresh",!0);const e=a(),o=e.length<2?null:e[e.length-2],s=["pages/order/index","pages/order/detail"];setTimeout((()=>{o&&t(o.route,s)?uni.navigateBack():this.$navTo("pages/order/index",{},"redirectTo")}),1200)}}},[["render",function(e,a,t,S,T,g){const b=p,v=P("count-down"),w=d,x=C(_("u-modal"),I);return T.isLoading?l("",!0):(o(),s(w,{key:0,class:"container",style:r(e.appThemeStyle)},{default:n((()=>[i(w,{class:"order-info"},{default:n((()=>[T.order.showExpiration?(o(),s(w,{key:0,class:"order-countdown"},{default:n((()=>[i(b,{class:"m-r-6"},{default:n((()=>[c("剩余时间")])),_:1}),i(v,{date:T.order.expirationTime,separator:"zh",theme:"text"},null,8,["date"])])),_:1})):l("",!0),i(w,{class:"order-amount"},{default:n((()=>[i(b,{class:"unit"},{default:n((()=>[c("¥")])),_:1}),i(b,{class:"amount"},{default:n((()=>[c(m(T.order.pay_price),1)])),_:1})])),_:1})])),_:1}),i(w,{class:"payment-method"},{default:n((()=>[(o(!0),u(f,null,h(T.methods,((e,a)=>(o(),s(w,{key:a,class:"pay-item dis-flex flex-x-between",onClick:e=>g.handleSelectPayType(a)},{default:n((()=>[i(w,{class:"item-left dis-flex flex-y-center"},{default:n((()=>[i(w,{class:y(["item-left_icon",[e.method]])},{default:n((()=>[i(b,{class:y(["iconfont",[T.PayMethodIconEnum[e.method]]])},null,8,["class"])])),_:2},1032,["class"]),i(w,{class:"item-left_text"},{default:n((()=>[i(b,null,{default:n((()=>[c(m(T.PayMethodEnum[e.method].name),1)])),_:2},1024)])),_:2},1024),e.method===T.PayMethodEnum.BALANCE.value?(o(),s(w,{key:0,class:"user-balance"},{default:n((()=>[i(b,null,{default:n((()=>[c("(可用¥"+m(T.personal.balance)+"元)",1)])),_:1})])),_:1})):l("",!0)])),_:2},1024),T.curPaymentItem&&T.curPaymentItem.method==e.method?(o(),s(w,{key:0,class:"item-right col-m"},{default:n((()=>[i(b,{class:"iconfont icon-check"})])),_:1})):l("",!0)])),_:2},1032,["onClick"])))),128))])),_:1}),i(w,{class:"footer-fixed"},{default:n((()=>[i(w,{class:"btn-wrapper"},{default:n((()=>[i(w,{class:y(["btn-item btn-item-main",{disabled:T.disabled}]),onClick:a[0]||(a[0]=e=>g.handleSubmit())},{default:n((()=>[c("确认支付")])),_:1},8,["class"])])),_:1})])),_:1}),T.tempUnifyData?(o(),s(x,{key:0,modelValue:T.showConfirmModal,"onUpdate:modelValue":a[1]||(a[1]=e=>T.showConfirmModal=e),title:"支付确认","show-cancel-button":"","confirm-text":"已完成支付","confirm-color":e.appTheme.mainBg,"negative-top":"100",asyncClose:!0,onConfirm:a[2]||(a[2]=e=>g.onTradeQuery(T.tempUnifyData.outTradeNo,T.tempUnifyData.method))},{default:n((()=>[i(w,{class:"modal-content"},{default:n((()=>[i(b,null,{default:n((()=>[c("请在"+m(T.PayMethodClientNameEnum[T.tempUnifyData.method])+"内完成支付,如果您已经支付成功,请点击“已完成支付”按钮",1)])),_:1})])),_:1})])),_:1},8,["modelValue","confirm-color"])):l("",!0)])),_:1},8,["style"]))}],["__scopeId","data-v-8edcdc3e"]]);export{j as default};