"use strict";const e=require("../../common/vendor.js"),o=require("../../config/user.js"),r={data:()=>({orderId:"",orderInfo:{},isLoading:!0,deviceMessage:"正在准备您的设备，请稍候...",hasTriggeredDevice:!1}),onLoad(o){o&&o.orderId?(this.orderId=o.orderId,this.loadOrderInfo(),e.index.$once("orderSuccess:"+this.orderId,(()=>{console.log("已经触发过弹出逻辑，不再重复触发"),this.hasTriggeredDevice=!0}))):(e.index.showToast({title:"订单信息不存在",icon:"none"}),setTimeout((()=>{this.goToHome()}),1500))},methods:{async loadOrderInfo(){try{e.index.showLoading({title:"加载中"});const r=await o.queryById(this.orderId);if(200!==r.code||!r.data)throw new Error("获取订单信息失败");{const o=r.data;this.orderInfo={orderNo:o.orderNo||o.orderId,deviceNo:o.deviceNo,amount:o.payAmount||o.amount,payTime:o.payTime||this.formatTime(new Date)},"IN_USED"===o.orderStatus?(this.deviceMessage="设备已弹出，请取走您的风扇",this.isLoading=!1,this.hasTriggeredDevice||(e.index.$emit("orderSuccess:"+this.orderId),this.hasTriggeredDevice=!0)):this.triggerDeviceEject()}e.index.hideLoading()}catch(r){e.index.hideLoading(),e.index.showToast({title:r.message||"获取订单信息失败",icon:"none"})}},async triggerDeviceEject(){if(this.hasTriggeredDevice)console.log("已经触发过弹出风扇，不重复触发");else{this.hasTriggeredDevice=!0,e.index.$emit("orderSuccess:"+this.orderId),this.isLoading=!0,this.deviceMessage="正在准备您的设备，请稍候...";try{console.log(`准备触发弹出风扇，orderId: ${this.orderId}`);const r=await o.confirmPaymentAndRent(this.orderId);if(console.log("确认支付并弹出风扇结果:",JSON.stringify(r)),!r||200!==r.code)throw new Error(r&&r.msg||"弹出风扇失败");this.deviceMessage="设备已弹出，请取走您的风扇",e.index.showToast({title:"风扇已弹出",icon:"success"})}catch(r){console.error("弹出风扇错误:",r),this.deviceMessage="弹出设备失败，请联系客服",e.index.showToast({title:r.message||"弹出风扇失败，请联系客服",icon:"none"})}finally{this.isLoading=!1}}},formatTime:e=>`${e.getFullYear()}-${(e.getMonth()+1).toString().padStart(2,"0")}-${e.getDate().toString().padStart(2,"0")} ${e.getHours().toString().padStart(2,"0")}:${e.getMinutes().toString().padStart(2,"0")}:${e.getSeconds().toString().padStart(2,"0")}`,goToHome(){e.index.switchTab({url:"/pages/index/index"})},goToOrderList(){e.index.redirectTo({url:"/pages/order/index"})}}};const i=e._export_sfc(r,[["render",function(o,r,i,t,d,s){return e.e({a:e.t(d.orderInfo.orderNo||"-"),b:e.t(d.orderInfo.deviceNo||"-"),c:e.t(d.orderInfo.amount||"0.00"),d:e.t(d.orderInfo.payTime||"-"),e:e.t(d.deviceMessage),f:d.isLoading},(d.isLoading,{}),{g:e.o(((...e)=>s.goToHome&&s.goToHome(...e))),h:e.o(((...e)=>s.goToOrderList&&s.goToOrderList(...e)))})}],["__scopeId","data-v-333e92b6"]]);wx.createPage(i);
