homeNologin.js 3.3 KB
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    swiperList: {},
    id: '',
    way: 2
  },
  onShow: function () {},
  onLoad: function (options) {
    //  console.log(options);
    this.setData({
      id: options.id
    })
    this.getStoreList()
  },
  async getStoreList() {
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/active/orderDetail',
        data: {
          id: that.data.id
        }
      })
      //  console.log(data);
      that.setData({
        swiperList: data,
      })

    } catch (err) {
      //  console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },

  cancelRefund(e) { // 取消退款
    let that = this
    wx.showModal({
      title: '提示',
      content: '确定要取消退款吗?',
      success: async function (res) {
        if (res.confirm) {
          try {
            const {
              data
            } = await request({
              url: 'api/active/qvTui',
              data: {
                order_no: e.currentTarget.dataset.order_no
              }
            })
            //  console.log(data, "取消退款");
            if (data.code == 1) {
              a.popSuccessTest(data.msg)
              setTimeout(() => {
                // that.getMyorder()
                wx.navigateBack()
              }, 800);
            }
          } catch (err) {
            a.popTest(err.msg)
          }
        } else {

        }
      }

    })
  },
  async cancelOrder(e) {
    let that = this
    let id = e.currentTarget.dataset.id
    that.Subscribe()
    try {
      const {
        data
      } = await request({
        url: 'api/active/tuiOrder',
        data: {
          id: id
        }
      })
      //  console.log(data);
      that.setData({
        msg: data.msg
      })
      that.popSuccessTest()
      // setTimeout(() => {
      //   wx.navigateBack()
      // }, 1500);
    } catch (err) {
      //  console.log(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()
              },
            })
          }
         wx.navigateBack() 
        },
        fail(err) {
          //失败
          console.error(err);
          wx.navigateBack()
          reject()

        }
      })
    })
  },

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

})