// pages/welfareMall/order/orderCompletion.js import WelfareMall from '../../../api/welfareMall' import { parseTime } from '../../../utils/util' import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user' Page({ /** * 页面的初始数据 */ data: { page: 1, pageSize: 10, lock: false, noResult: false, noMore: false, orderDetail: null, orderSn: '', hidden: true, reason: '', }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; that.orderSn = options.ordersn this.setData({ orderSn: options.ordersn, }) this.getOrder(that.orderSn); this.data.orderSn = options.ordersn; }, /** * * 订单数据 */ getOrder: function(data) { WelfareMall.getOrder({ mobile: getMobileCache(), orderSn: data, }).then(res => { if (res.code == 200) { this.userOrderistView(res.data) } this.data.lock = false }).catch(_ => { console.log(_) this.data.lock = false }) }, userOrderistView: function(data) { if (!data) { console.log("订单详情数据为空"); return } //对象转换 this.data.orderDetail = data this.setData({ mobileTop:getMobileCache(), orderDetail: this.data.orderDetail }) }, /** * * 取消订单 */ toCancelOrder(e) { wx.showModal({ title: '取消订单', content: '', showCancel: true,//是否显示取消按钮 cancelText:"取消",//默认是“取消” cancelColor:'black',//取消文字的颜色 confirmText:"确定",//默认是“确定” confirmColor: 'black',//确定文字的颜色 success: res => {if (res.cancel) { //点击取消,默认隐藏弹框 } else { //点击确定 WelfareMall.cancelOrder({ mobile: getMobileCache(), orderSn: this.data.orderSn, }).then(res => { if (res.code == 200) { wx.showToast({ title: '取消订单成功', icon: 'none', duration: 1500 }); this.changeOrder(this.data.orderSn,4,'已取消'); } this.data.lock = false }).catch(_ => { console.log(_) this.data.lock = false }) } }, fail: function (res) { console.log(res) },//接口调用失败的回调函数 }) }, /** * 获取订单参数 */ async goPay() { var that = this; let result = await WelfareMall.getOrderParams(that.data.orderSn,wx.getStorageSync('loginInfo').openId); let res = result.data wx.requestPayment({ timeStamp: res.wxPrePayVo.timeStamp, package: res.wxPrePayVo.pack, nonceStr: res.wxPrePayVo.nonceStr, signType: res.wxPrePayVo.signType, paySign: res.wxPrePayVo.paySign, success: function (res) { //支付成功 console.log(res); that.changeOrder(that.data.orderSn,2,'已支付'); }, fail: function (res) { console.log(res); } }) }, /** * 申请退款 */ getMode: function(){ this.setData({ hidden: false, reason: '', }); }, /** * 取消 */ cancel: function(){ this.setData({ hidden: true, reason: '', }); }, /** * 提交 */ confirm: function(){ this.setData({ hidden: false }); var res = this.data.reason; console.log(res); if(res == null || res =='' || res == undefined){ wx.showToast({ title: '退款原因必填', icon: 'none', duration: 1500 }) } else { this.goRefund(res); } }, /** * 退款原因 */ getReason: function(e){ this.setData({ reason: e.detail.value }) }, /** * * 申请退款 */ goRefund: function(reason) { var that = this; WelfareMall.orderRefund({ mobile: getMobileCache(), orderSn: that.data.orderSn, reason: reason, }).then(res => { if (res.code == 200) { that.cancel(); that.onLoad(that.options); that.changeOrder(that.data.orderSn,3,'已退款'); const url = "../refund/refund?orderSn=" + that.data.orderSn wx.navigateTo({ url }) } }).catch(_ => { console.log(_) that.cancel(); }) }, changeOrder: function(orderSn,status,showText){ var page = getCurrentPages(); //获取上一个页面的页面栈 var lastPage = page[page.length-2]; console.log(lastPage.data) let oldOrderList = lastPage.data.orderList; for(var i = 0;i