"use strict";const e=require("../../common/vendor.js"),t=require("../../util/index.js"),o=require("../../config/user.js"),s={data:()=>({depositAmount:"0.00",orderNo:"",records:[],orderId:""}),onLoad(){},onShow(){this.loadUserInfo()},methods:{async loadUserInfo(){try{const e=await t.getUserInfo();console.log("loadUserInfo",e),200===e.code&&(this.depositAmount=e.data.balanceAmount||"0.00",this.orderNo=e.data.latestOrderNo||"",this.orderId=e.data.latestOrderId||"",parseFloat(this.depositAmount)>0&&this.orderNo?this.records=[{type:"支付",time:this.formatDate(new Date),amount:this.depositAmount}]:this.records=[])}catch(o){console.error("获取用户信息失败：",o),e.index.showToast({title:"获取用户信息失败",icon:"none"})}},async handleWithdraw(){if(parseFloat(this.depositAmount)<=0)e.index.showToast({title:"无可提现余额",icon:"none"});else{if(0!=this.orderId.length||0!=this.orderNo.length){const e=await o.queryById(Number(this.orderId));console.log(e)}e.index.showModal({title:"确认提现",content:"押金将原路退回，预计0-7个工作日到账",success:async t=>{if(t.confirm){e.index.showLoading({title:"提现中..."});try{console.log("发起提现请求，订单号：",this.orderNo);const t=await o.withdrawDeposit(this.orderNo);if(console.log("提现响应：",t),200!==t.code)throw new Error(t.msg||"提现失败");e.index.hideLoading(),e.index.showToast({title:"提现申请已提交",icon:"success"}),this.depositAmount="0.00",this.records.push({type:"退还",time:this.formatDate(new Date),amount:this.depositAmount}),setTimeout((()=>{this.loadUserInfo()}),1500)}catch(s){console.error("提现失败：",s),e.index.hideLoading();let t="提现失败，请稍后再试";s.message&&(t=s.message.includes("尚未归还")?"当前订单尚未归还，请归还后再提现":s.message.includes("已退还")?"押金已退还，无需重复提现":s.message.includes("处理中")?"押金退还处理中，请耐心等待":s.message.includes("余额为0")?"账户余额为0，无法提现":s.message),e.index.showModal({title:"提现失败",content:t,showCancel:!1})}}}})}},formatDate: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")}`}};const r=e._export_sfc(s,[["render",function(t,o,s,r,n,i){return e.e({a:e.t(n.depositAmount),b:e.o(((...e)=>i.handleWithdraw&&i.handleWithdraw(...e))),c:n.depositAmount<=0,d:n.records.length>0},n.records.length>0?{e:e.f(n.records,((t,o,s)=>({a:e.t(t.type),b:e.t(t.time),c:e.t("退还"===t.type?"+":"-"),d:e.t(t.amount),e:e.n("退还"===t.type?"refund":""),f:o})))}:{})}],["__scopeId","data-v-8981ee42"]]);wx.createPage(r);
