MaintenanceService.js 6.0 KB
import {
  request
} from '../../request/index.js'
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    count: 1,
    title: "保养项目",
    flag: true,
    _count: 1,
    active: 1,
    msg: '',
    order_no: '',
    publicList: [],
    serviceItem: [], //保养项目
    timeStamp: '',
    nonceStr: '',
    package: '',
    signType: 'MD5',
    paySign: '',
    way: 1

  },

  onLoad: function (options) {

  },

  onReady: function () {

  },

  onShow: function () {
    // wx.showToast({
    //   title: '加载中',
    //   icon: "loading",
    //   duration: 1000
    // })
    this.getPublicList()
  },
  async getPublicList() {
    let that = this
    wx.showLoading({
      mask: true
    })
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/my/myFw',
        method: 'GET',
        data: {
          way: that.data.way
        }
      })
      // //  console.log(data);

      // if (data.length != 0) {
      //    that.setData({
      //      it_cloosy: false
      //    })
      // }
      that.setData({
        publicList: data
      })
      wx.hideLoading()
    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },

  goShare(e) { // 切换标题
    this.setData({
      _count: e.currentTarget.dataset.count,
      way: e.currentTarget.dataset.count
    })
    this.getPublicList()
  },

  gotopayment(e) { // 支付尾款
    let order_no = e.currentTarget.dataset.order_no
    wx.navigateTo({
      url: '/pages/confirmOrder/confirmOrder?order_no=' + order_no + '&stay=' + 1
    })
  },
  gotopay(e) { // 订单支付
    let that = this
    request({
      url: 'api/my/baoPay',
      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 cancelOrder(e) { // 取消订单
    let that = this
    wx.showModal({
      title: '提示',
      content: '确认要取消吗?',
      async success(res) {
        if (res.confirm) {
          //  console.log('点击确认回调')
          try {
            const {
              data
            } = await request({
              url: 'api/my/qvOrderBao',
              data: {
                order_no: e.currentTarget.dataset.order_no
              }
            })
            //  console.log(data);
            that.setData({
              msg: data.msg
            })
            that.popSuccessTest()
            setTimeout(() => {
              that.getPublicList()
            }, 1000);
          } catch (err) {
            that.setData({
              msg: err.msg
            })
            that.popMaskTest()
          }

        } else {
          //  console.log('点击取消回调')
        }
      }
    })
  },
  delUpKeep(e) { // 删除
    let that = this
    try {
      wx.showModal({
        title: '提示',
        content: '确认要删除吗?',
        async success(res) {
          if (res.confirm) {
            //  console.log('点击确认回调')
            const {
              data
            } = await request({
              url: 'api/my/baoDel',
              data: {
                order_no: e.currentTarget.dataset.order_no
              }
            })
            //  console.log(data);
            that.setData({
              msg: data.msg
            })
            that.popSuccessTest()
            setTimeout(() => {
              that.getPublicList()
            }, 1000);
          } else {
            //  console.log('点击取消回调')
          }
        }
      })
    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }

  },
  hidePopup() { //隐藏弹框
    this.setData({
      flag: !this.data.flag
    })
  },
  async showPopup(e) { // 保养项目
    let that = this
    that.setData({
      flag: !this.data.flag
    })
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/my/baoList',
        method: 'GET',
        data: {
          order_no: e.currentTarget.dataset.order_no
        }
      })
      //  //  console.log(data, "保养项目");
      that.setData({
        serviceItem: data
      })
      wx.hideLoading()
    } catch (err) {
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }


  },
  popMaskTest() { // 消息提示
    wx.showToast({
      title: this.data.msg,
      duration: 1300,
      icon: 'none',
      mask: true //是否有透明蒙层,默认为false 
      //如果有透明蒙层,弹窗的期间不能点击文档内容 
    })
  },
  storeMaintainImg(e) { //  保养商品详情有图
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/storeMaintainImg/storeMaintainImg?id=' + id
    })
  },
  popSuccessTest() {
    wx.showToast({
      title: this.data.msg,
      icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
      duration: 1300, //停留时间
      mask: true
    })
  },


})