VtuanOrderDetail.js 9.0 KB
// pages/4SConfirmAnOrder/4SConfirmAnOrder.js
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    img: false,
    status: 1,
    way: '', // 1 代表待付款  2 待自提 3 待发货 4 待收货 5 普通待评价 6 4S店待评价  7 已完成 8 退款中 9 已退款 用way 来判断是4S店还是普通商店
    OrderObligation: [],
    ConfirmAnOrder: [],
    address: '',
    all_pay: '',
    pathed: 3, // 跳转的路径
    order_no: '',
    is_car: '', //  1=定车订单;0=非订车订单
    area: '',
    address_detail: '',
  },

  onLoad: function (options) {
    //  console.log(options);
    this.setData({
      order_no: options.order_no,
      way: options.StateWay,
    })
    this.getMyOrderObligation()

  },
  async getMyOrderObligation() { // 获取 
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await
      request({
        url: 'api/my2/tuanOrderDetail',
        data: {
          order_no: that.data.order_no
        }
      })
      that.setData({
        OrderObligation: data,
        ConfirmAnOrder: data.good,
        address: data.address,
        all_pay: data.all_pay,
        order_no: data.order_no,
        area: data.area,
        address_detail: data.address_detail,
      })
      //  console.log(that.data.OrderObligation, "定睛购物");

    } catch (err) {
      //  console.log(err);
    }
  },

  onShow: function () {

  },
  // 返回商品详情
  returnGoods() {
    let id = this.data.ConfirmAnOrder.id
    wx.navigateTo({
      url: '/pages/VtuanDetail/VtuanDetail?id=' + id,
    })
  },
  cancelOrder(e) { // 取消订单
    let that = this
    wx.showModal({
      title: '提示',
      content: '确认要取消该订单嘛?',
      success: async function (res) {
        if (res.confirm) {
          try {
            const {
              data
            } = await request({
              url: 'api/my/qvOrder',
              data: {
                order_no: e.currentTarget.dataset.order_no
              }
            })
            //  console.log(data, "取消订单");
            that.setData({
              msg: data.msg
            })
            that.popSuccessTest()
            setTimeout(() => {
              wx.navigateTo({
                url: '/pages/MyOrder/MyOrder'
              })
            }, 1300);


          } catch (err) {
            that.setData({
              msg: err.msg
            })
            that.popMaskTest()

          }
        }
      }

    })
  },
  async abholung(e) { // 已自提
    let that = this
    try {
      const {
        data
      } = await request({
        url: 'api/my2/ziti',
        data: {
          order_no: e.currentTarget.dataset.order_no
        }
      })
      //  console.log(data, "已自提");
      a.popSuccessTest(data.msg)
      setTimeout(() => {
        wx.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 1000);

    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }

  },
  async returnStore(e) { // 申请退货
    let that = this
    try {
      const {
        data
      } = await request({
        url: 'api/my/tuiOrder',
        data: {
          order_no: e.currentTarget.dataset.order_no
        }
      })
      //  console.log(data, "申请退货");
      that.setData({
        msg: data.msg
      })
      that.popSuccessTest()
      setTimeout(() => {
        wx.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 2000);

    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }


  },
  async returnMoney(e) { // 申请退款
    let that = this
    that.Subscribe()
    let order_no = e.currentTarget.dataset.order_no
    wx.showModal({
      title: '提示',
      content: '确认要申请退款嘛?',
      success: async function (res) {
        if (res.confirm) {
          try {
            const {
              data
            } = await request({
              url: 'api/my/tuiOrder',
              data: {
                order_no: order_no
              }
            })
            //  console.log(data, "申请退款");
            that.setData({
              msg: data.msg
            })
            that.popSuccessTest()
            setTimeout(() => {
              wx.navigateBack()
            }, 800);

          } catch (err) {
            that.setData({
              msg: err.msg
            })
            that.popMaskTest()
          }
        }
      }
    })

  },
  //调起订阅消息 /退款通知
  Subscribe() {
    return new Promise((resolve, reject) => {
      wx.requestSubscribeMessage({
        tmplIds: ["dLkIUNEHhOTyzKeh5qWDgecUT8KR11MsC6vZfin8s2o"],
        success: (res) => {
          if (res['dLkIUNEHhOTyzKeh5qWDgecUT8KR11MsC6vZfin8s2o'] === 'accept') {
            // wx.showToast({
            //   title: '订阅OK!',
            //   duration: 1000,
            //   success(data) {
            //     //成功
            //     resolve()
            //   }
            // })
          }
        },
        fail(err) {
          //失败
          console.error(err);
          reject()
        }
      })
    })
  },
  Immediate(e) { // 立即评价
    //  console.log(e);
    let order_no = e.currentTarget.dataset.order_no
    let token = wx.getStorageSync("token")
    if (token) {
      wx.navigateTo({
        url: '/pages/appraise/appraise?order_no=' + order_no
      })
    } else {
      this.setData({
        msg: '请登录后操作'
      })
      this.popMaskTest()
    }


  },
  async CancelRefund(e) { //取消退款
    let that = this
    try {
      const {
        data
      } = await request({
        url: 'api/my/qvTui',
        data: {
          order_no: e.currentTarget.dataset.order_no
        }
      })
      //  console.log(data, "取消退款");
      that.setData({
        msg: data.msg
      })
      that.popSuccessTest()
      setTimeout(() => {
        wx.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 2000);

    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },
  gotopay(e) { // 订单支付
    let that = this
    request({
      url: 'api/my/liPay',
      data: {
        order_no: e.currentTarget.dataset.order_no
      }
    }).then(res => {
      //  console.log(res, "订单支付");
      that.setData({
        timeStamp: res.data.data.timeStamp,
        nonceStr: res.data.data.nonceStr,
        package: res.data.data.package,
        signType: 'MD5',
        paySign: res.data.data.paySign,
      })
      wx.requestPayment({
        timeStamp: that.data.timeStamp,
        nonceStr: that.data.nonceStr,
        package: that.data.package,
        signType: 'MD5',
        paySign: that.data.paySign,
        success(res) {
          //  console.log(res);
          wx.redirectTo({
            url: '/pages/MyOrder/MyOrder?order_no=' + that.data.order_no,
          })
        },
        fail(res) {
          //  console.log(res)
          wx.redirectTo({
            url: '/pages/MyOrder/MyOrder?order_no=' + that.data.order_no,
          })
        }
      })
    }).catch(err => {
      that.setData({
        msg: err.msg
      })
      this.popMaskTest()
      //  console.log(err);
    })
  },
  async sureShouOrder(e) { //确认收货
    let that = this
    try {
      const {
        data
      } = await request({
        url: 'api/my/shouOrder',
        data: {
          order_no: e.currentTarget.dataset.order_no
        }
      })
      //  console.log(data, "确认收货");
      that.setData({
        msg: data.msg
      })
      that.popSuccessTest()
      setTimeout(() => {
        wx.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 2000);

    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },

  onShareAppMessage(options) {
    //  console.log(options);
    let that = this;
    let good_id = options.target.dataset.good_id
    let good_name = options.target.dataset.good_name
    let imgShare = options.target.dataset.imgshare
    let shareObj = {
      title: good_name || "同放团购分享", // 默认是小程序的名称(可以写slogan等)
      path: '/pages/VtuanDetail/VtuanDetail?id=' + good_id, // 默认是当前页面,必须是以‘/’开头的完整路径
      imageUrl: imgShare, //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
    };
    // 返回shareObj
    return shareObj;

  },
  popMaskTest() {
    wx.showToast({
      title: this.data.msg,
      duration: 1300,
      icon: 'none',
      mask: true //是否有透明蒙层,默认为false 
      //如果有透明蒙层,弹窗的期间不能点击文档内容 
    })
  },
  popSuccessTest() {
    wx.showToast({
      title: this.data.msg,
      icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
      duration: 1300, //停留时间
    })
  },

})