withdrawalRules.js 6.04 KB
// packageIndex/pages/integral/rule/rule.js
import {
  systemApi
} from '~/api/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showConfirmDialog: false,
    goodsList: [],
    taxRateObj: {},
    confirmButtons: [{
      text: '取消',
      extClass: 'btn_cancel'
    }, {
      text: '确认',
      extClass: 'btn_primary'
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.p.router.getRouterParams().then(params => {
      this.setData(params)
      this.getTaxRate()
      this.getGoodsList()
    })
  },
  simpleWanConvert(num) {
    if (num === null || num === undefined || isNaN(num)) {
      return '';
    }

    // 处理大于等于10000的数字
    if (Math.abs(num) >= 10000) {
      const wan = (num / 10000).toFixed(1);
      // 去掉末尾的.0
      return parseFloat(wan) == parseInt(wan) ? parseInt(wan) + '万' : wan + '万';
    }
    // 处理小于10000但大于等于1000的数字
    else if (Math.abs(num) >= 1000) {
      const qian = (num / 10000).toFixed(1);
      return qian + '万';
    }
    // 小于1000的数字直接返回
    else {
      return num.toString();
    }
  },
  // 获取商品数据
  getGoodsList() {

    let userInfo = wx.p.storage.get('userInfo')
    let params = {
      pageNum: 1,
      pageSize: 8,
      canExchange: 1,
      businessType: 1,
      staffPhone: userInfo?.phone,
      staffPlatform: userInfo?.channelSource,
      merchantNo: userInfo?.merchantId,
      storeEnd: this.data.sumbitScore
    }

    wx.p.api.homeApi.getGoodsStockroomList(params).then(res => {
      res?.list?.forEach((val, index) => {
        if (index == 0) val.goodsSource = 2
        else val.goodsSource = 1
      })
      this.setData({
        goodsList: res?.list
      })
    })
  },
  // 加入购物车
  handleAddToCart(e) {
    let value = e.detail
    // let { userInfo } = this.data
    // const PARAMS = {
    //   goodsId: value.id,
    //   sellQty: 1,
    //   goodsSource: value.goodsSource,
    //   scoreSource: userInfo?.channelSource,
    //   merchantId: userInfo?.merchantId
    // }
    // if (value.goodsSource == 1) {
    //   if (!value.goodsStock) return wx.p.wxApi.showToast('暂无库存')
    //   cartApi.addToCart(PARAMS).then(res => {
    //     wx.p.wxApi.showToast('加入购物车成功')
    //   })
    // } else {
    // 获取商品详情
    this.getDetail(value)
    // }
  },
  getDetail(options) {
    wx.p.api.homeApi.getGoodsDetailInfo({
      id: options.id,
      businessType: 1
    }).then(res => {
      // if (res && res.specificationResponses?.length) {
      //   this.toGetSpecString(res, res.startQty)
      // }
      if (res && res.platformGlGoodsSpecifications?.length) {
        let item = res.platformGlGoodsSpecifications[0] || {}
        res.goodsStock = item.stock
        res.specificationData = item.specificationData
        this.setData({
          activeSku: item.specificationData
        })
      }
      this.setData({
        detailInfo: res || {},
        showSku: true
      })
    })
  },
  getTaxRate() {
    const {
      phone,
      channelSource,
      merchantId
    } = wx.p.storage.get('userInfo'), {
      sumbitScore
    } = this.data;
    wx.p.api.withdrawalApi.getTaxRate({
      withdrawalScore: sumbitScore,
      staffPhone: phone,
      channelSource,
      merchantId
    }).then(res => {
      if (res.code == 0) {
        this.setData({
          taxRateObj: {
            ...res.data,
            baseIncome: this.simpleWanConvert(res.data.baseIncome)
          }
        })
      }
    }).catch(err => {
      wx.p.wxApi.showToast(JSON.stringify(err))
    })
  },
  goMall() {
    wx.p.router.reLaunch('/pages/tab/index/index')
  },
  async policyDetail() {
    let v = await systemApi.getImageVersion()
    wx.p.router.jumpH5(`https://img01.glsx.com.cn/weapp/resource/miniprogram/points-mall/html/policy.html?v=${v}`)
  },
  bindButton(e) {
    let {
      value
    } = e.detail;
    let dialogObj = {
      0: () => {
        this.dialogClose()
      },
      1: () => {
        this.dialogConfirm()
      }
    }
    dialogObj[value]()
  },
  dialogClose() {
    this.submit = false
    this.setData({
      showConfirmDialog: false,
    })
  },
  dialogConfirm() {
    let {
      sumbitScore,
      disclaimerAgreementUrl,
      bankId
    } = this.data, {
      phone,
      channelSource,
      merchantId,
      merchantName
    } = wx.p.storage.get('userInfo');
    if (this.submit) return
    this.submit = true
    wx.p.wxApi.showLoading('提交中')
    let params = {
      withdrawalScore: sumbitScore,
      disclaimerAgreementUrl,
      bankId,
      merchantId,
      merchantName,
      channelSource: channelSource,
      staffPhone: phone,
    }
    wx.p.api.withdrawalApi.saveWithdrawal(params).then(res => {
      wx.p.wxApi.hideLoading();
      if (res.code == 0) {
        wx.p.router.redirectTo('/packageIndex/pages/integral/withdrawalSuccess/withdrawalSuccess')
      } else {
        wx.p.wxApi.showToast(res.message)
        this.submit = false
        wx.p.sentry.reportError(`积分提现异常:${res.message}`, {
          ...params,
          res
        });
      }
    }).catch((err) => {
      this.submit = false
      wx.p.sentry.reportError(`积分提现异常:${err.message}`, {
        ...params,
        err
      });
      wx.p.wxApi.showToast(JSON.stringify(err))

    }).finally(() => {
      this.setData({
        showConfirmDialog: false
      })
    })

  },
  goContinue() {
    this.setData({
      showConfirmDialog: true
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})