123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- // pages/welfareMall/order/orderCompletion.js
- import WelfareMall from '../../../api/welfareMall'
- 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: '',
- inputValue: '',
- repeat: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- 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
- })
- },
- /**
- *
- * 订单数据--查询
- */
- selectOrder: async function(orderSn) {
- let res = await WelfareMall.getOrder({
- mobile: getMobileCache(),
- orderSn: orderSn,
- })
- await this.changeOrder(res.data.orderSn,res.data.status.value,res.data.status.showText);
- },
- userOrderistView: function(data) {
- if (!data) {
- console.log("订单详情数据为空");
- return
- }
- // 构建券包传参参数
- const couponList = []
- if (data.goodsList && Array.isArray(data.goodsList)) {
- data.goodsList.forEach(v => {
- const coupons = v.couponList
- if (coupons && coupons.length > 0) {
- coupons.forEach(coupon => {
- coupon.isSn = true
- couponList.push(coupon)
- })
- }
- })
- }
- //对象转换
- this.data.orderDetail = data
- this.setData({
- mobileTop:getMobileCache(),
- orderDetail: this.data.orderDetail,
- couponList,
- })
- },
- /**
- *
- * 取消订单
- */
- toCancelOrder(e) {
- var that = this;
- wx.showModal({
- title: '取消订单',
- content: '',
- showCancel: true,//是否显示取消按钮
- cancelText:"取消",//默认是“取消”
- cancelColor:'#00000',//取消文字的颜色
- confirmText:"确定",//默认是“确定”
- confirmColor: '#00000',//确定文字的颜色
- success: res => {if (res.cancel) {
- //点击取消,默认隐藏弹框
- } else {
- //点击确定
- WelfareMall.cancelOrder({
- mobile: getMobileCache(),
- orderSn: that.data.orderSn,
- }).then(res => {
- if (res.code == 200) {
- wx.showToast({
- title: '取消订单成功',
- icon: 'none',
- duration: 1500
- });
- that.selectOrder(that.data.orderSn);
- }
- }).catch(_ => {
- console.log(_)
- })
- }
- },
- fail: function (res) {
- console.log(res)
- },//接口调用失败的回调函数
- })
-
- },
- /**
- * 获取订单参数
- */
- async goPay() {
- var that = this;
- if(that.data.repeat){
- return;
- }
- that.data.repeat = true;
- 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.selectOrder(that.data.orderSn);
- that.data.repeat = false;
- },
- fail: function (res) {
- console.log(res);
- that.data.repeat = false;
- },
- complete: function (res) {
- console.log(res);
- that.data.repeat = false;
- }
- })
- },
- /**
- * 申请退款
- */
- getMode: function(){
- this.setData({
- hidden: false,
- inputValue: '',
- reason: '',
- });
- },
- /**
- * 取消
- */
- cancel: function(){
- this.setData({
- hidden: true,
- inputValue: '',
- reason: '',
- });
- },
- /**
- * 提交
- */
- confirm: function(){
- let that = this;
- var res = this.data.reason;
- console.log(res);
- if(res == null || res =='' || res == undefined){
- wx.showToast({
- title: '退款原因必填',
- icon: 'none',
- duration: 1500
- })
- } else {
- this.setData({
- hidden: true
- });
- wx.showToast({
- title: '申请退款已提交',
- icon: 'none',
- duration: 2000,
- success: function(){
- that.goRefund(res);
- }
- });
- }
- },
- /**
- * 退款原因
- */
- getReason: function(e){
- this.setData({
- reason: e.detail.value
- })
- },
- /**
- *
- * 申请退款
- */
- goRefund: async function(reason) {
- var that = this;
- await WelfareMall.orderRefund({
- mobile: getMobileCache(),
- orderSn: that.data.orderSn,
- reason: reason,
- });
- await that.cancel();
- // await that.onLoad(that.options);
- await that.selectOrder(that.data.orderSn);
- // await wx.navigateTo({
- // url: "../refund/refund?orderSn=" + that.data.orderSn
- // })
-
- },
- 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<oldOrderList.length;i++){
- if(orderSn == oldOrderList[i].orderSn){
- oldOrderList[i].status.value = status
- oldOrderList[i].status.showText = showText
- }
-
- }
- wx.navigateBack({
- delta: 1,
- success:function(){
- lastPage.setData({
- orderList:oldOrderList
- })
- }
- })
- return ;
- },
- extendCouponWrap() {
- this.data.isExtend = !this.data.isExtend
- this.setData({
- isExtend: this.data.isExtend
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|