"use strict";const e=require("../../common/vendor.js"),t=require("../../common/assets.js"),a=require("../../config/user.js"),s=require("../../config/url.js"),r={__name:"index",setup(r){const o=e.ref(0),n=e.ref([]),d=e.reactive({0:{text:"待支付",class:"status-waiting"},1:{text:"使用中",class:"status-using"},2:{text:"已完成",class:"status-finished"},3:{text:"已取消",class:"status-cancelled"},waiting_for_payment:{text:"待支付",class:"status-waiting"},in_used:{text:"使用中",class:"status-using"},used_done:{text:"已完成",class:"status-finished"},order_cancelled:{text:"已取消",class:"status-cancelled"}}),i=e.reactive([{text:"全部",status:[]},{text:"待付款",status:["waiting_for_payment"]},{text:"使用中",status:["in_used"]},{text:"已完成",status:["used_done"]},{text:"已取消",status:["order_cancelled"]}]);e.onLoad((async e=>{if(e&&e.orderId)try{const t=await a.queryById(e.orderId);if(200===t.code&&t.data){const e=t.data,a=e.startTime||e.createTime||"",s={orderNo:e.orderId,status:e.orderStatus,deviceId:e.deviceNo,payWay:e.payWay,startTime:a,endTime:e.endTime||"",amount:e.payAmount||e.actualDeviceAmount||"0.00"};n.value=[s,...n.value];const r=i.findIndex((t=>t.status.includes(e.orderStatus)));-1!==r&&c(r)}}catch(t){console.error("获取订单详情失败:",t)}await u()}));const c=async e=>{o.value=e;const t=i[e].status[0];await u(t)},u=async t=>{try{null!=t&&(t={orderStatus:t});const e=await a.getOrderList(t);200===e.code&&e.data&&e.data.records&&(n.value=e.data.records.map((e=>{const t=e.startTime||e.createTime||"";return{orderNo:e.orderNo,orderId:e.orderId,orderStatus:e.orderStatus,deviceId:e.deviceNo,payWay:e.payWay,startTime:t,endTime:e.endTime||"",amount:e.payAmount||e.actualDeviceAmount||"0.00"}})))}catch(s){console.error("获取订单列表失败:",s),e.index.showToast({title:"获取订单列表失败",icon:"none"})}};return(r,l)=>e.e({a:e.f(i,((t,a,s)=>({a:e.t(t.text),b:a,c:o.value===a?1:"",d:e.o((e=>c(a)),a)}))),b:0===n.value.length},(n.value.length,{}),{c:e.f(n.value,((r,n,c)=>{var l,y;return e.e({a:e.t(r.orderNo),b:e.t(null==(l=d[r.orderStatus])?void 0:l.text),c:e.n(null==(y=d[r.orderStatus])?void 0:y.class),d:e.t(r.deviceId),e:"wx_score_pay"==r.payWay},"wx_score_pay"==r.payWay?{f:t._imports_0$3}:("wx_member_pay"==r.payWay||r.payWay,{}),{g:"wx_member_pay"==r.payWay,h:"wx_pay"==r.payWay,i:e.t(r.startTime),j:e.t(r.endTime||"-"),k:e.t(r.amount),l:"waiting_for_payment"===r.status||"waiting_for_payment"===r.orderStatus},"waiting_for_payment"===r.status||"waiting_for_payment"===r.orderStatus?{m:e.o((t=>(async t=>{try{e.index.showLoading({title:"处理中"});const r=await e.index.request({url:`${s.URL||"http://127.0.0.1:8080"}/app/wx-payment/create/${t.orderNo}`,method:"GET",header:{Authorization:"Bearer "+e.index.getStorageSync("token"),Clientid:e.index.getStorageSync("client_id")}});if(200!==r.statusCode||200!==r.data.code)throw new Error(r.data.msg||"创建支付订单失败");{const s=r.data.data;await e.index.requestPayment({...s,success:async()=>{e.index.showToast({title:"支付成功",icon:"success"});try{await a.updateUserBalance(t.orderId||t.orderNo)}catch(s){console.warn("更新用户余额失败:",s)}await u(i[o.value].status)},fail:e=>{throw console.error("支付失败:",e),new Error("支付失败，请重试")}})}e.index.hideLoading()}catch(r){e.index.hideLoading(),e.index.showToast({title:r.message||"支付失败",icon:"none"})}})(r)),n)}:{},{n:"waiting_for_payment"===r.status||"waiting_for_payment"===r.orderStatus},"waiting_for_payment"===r.status||"waiting_for_payment"===r.orderStatus?{o:e.o((t=>(async t=>{try{e.index.showModal({title:"确认取消",content:"确定要取消此订单吗？",success:async s=>{if(s.confirm){e.index.showLoading({title:"处理中"});const s=await a.cancelOrder({orderId:t.orderNo});if(!s)throw new Error(s.msg||"取消订单失败");e.index.hideLoading(),e.index.showToast({title:"订单已取消",icon:"success"}),await u()}}})}catch(s){e.index.hideLoading(),e.index.showToast({title:s.message||"取消订单失败",icon:"none"})}})(r)),n)}:{},{p:"in_used"==r.status||"in_used"==r.orderStatus},"in_used"==r.status||"in_used"==r.orderStatus?{q:e.o((t=>{return a=r.deviceId,s=r.orderId,console.log(s),void e.index.navigateTo({url:`/pages/return/index?deviceId=${a}&orderId=${s}`});var a,s}),n)}:{},{r:e.o((t=>(t=>{e.index.navigateTo({url:`/pages/order/details?orderId=${t.orderId||t.orderNo}`})})(r)),n),s:n})}))})}},o=e._export_sfc(r,[["__scopeId","data-v-ccb8ba5b"]]);wx.createPage(o);
