myOrderObligation.js 7.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=非订车订单
  },

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

  },
  godetails(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/productdetailsImg/productdetailsImg?id='+id,
    })
    //  console.log(id);
  },
  async getMyOrderObligation() { // 获取 
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await
      request({
        url: 'api/my/orderDetail',
        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
      })
      //  console.log(that.data.OrderObligation, "定睛购物");

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

  onShow: function () {

  },
  async cancelOrder(e) { // 取消订单
    let that = this
    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(() => {
        that.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 2000);


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

    }
  },
  async Abholung(e) { // 已自提
    let that = this
    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(() => {
        that.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 2000);

    } 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(() => {
        that.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 2000);

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


  },
  async returnMoney(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()
    }

  },
  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(() => {
        that.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 2000);

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

})