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

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      order_no: options.order_no,
      way: options.StateWay,
    })
    //  console.log(this.data.way);
    // this.getMyOrderObligation()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMyOrderObligation()
  },
  async getMyOrderObligation() { // 获取 
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await
      request({
        url: 'api/my/orderDetail2',
        data: {
          order_no: that.data.order_no
        }
      })
      that.setData({
        OrderObligation: data,
        ConfirmAnOrder: data.good,
        car_type: data.car_type,
      })
      //  console.log(that.data.OrderObligation, "定睛购物");

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

  },
  async cancelOrder(e) { // 取消订单
    let that = this
    try {
      const {
        data
      } = await request({
        url: 'api/my/qvOrder',
        data: {
          order_no: that.data.order_no
        }
      })
      //  console.log(data, "取消订单");
      that.setData({
        msg: data.msg
      })
      that.popSuccessTest()

    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
      setTimeout(function () {
        wx.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 3000);
    }
  },
  async Abholung(e) { // 已自提
    let that = this
    try {
      const {
        data
      } = await request({
        url: 'api/my/qvOrder',
        data: {
          order_no: that.data.order_no
        }
      })
      //  console.log(data, "已自提");
      that.setData({
        msg: data.msg
      })
      that.popSuccessTest()
      setTimeout(function () {
        wx.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 3000);

    } 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: that.data.order_no
        }
      })
      //  console.log(data, "申请退款");
      that.setData({
        msg: data.msg
      })
      that.popSuccessTest()
      setTimeout(function () {
        wx.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 3000);
    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }

  },
  async kittyCar() { // 喜提爱车
    let that = this
    try {
      const {
        data
      } = await request({
        url: 'api/my/tiCar',
        data: {
          order_no: that.data.order_no
        }
      })
      //  console.log(data, "喜提爱车");
      that.setData({
        msg: data.msg
      })
      that.popSuccessTest()
      setTimeout(function () {
        wx.navigateTo({
          url: '/pages/MyOrder/MyOrder'
        })
      }, 3000);

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

  },
  gotopay() { // 订单支付
    let that = this
    request({
      url: 'api/my/liPay',
      data: {
        order_no: that.data.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) {
          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);
    })
  },

  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, //停留时间
    })
  },

})