withdrawal.js 6.64 KB
// packageIndex/pages/integral/toCash/toCash.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navStyle: "background-color: transparent;",
    agree: false,
    showAuthDialog: false,
    showConfirmDialog: false,
    sumbitScore: '',
    buttons: [{
      text: '取消'
    }, {
      text: '同意',
      extClass: 'btn_primary'
    }],
    confirmButtons: [{
      text: '取消'
    }, {
      text: '确认',
      extClass: 'btn_primary'
    }],
    bankInfo: {
      "id": 34,
      "staffId": 16550,
      "bankUserName": "望周知",
      "bankName": "中国邮政储蓄银行",
      "bankNumber": "6555555555555555555",
      "bankNum": "6555555588888*****5555",
      "bankPhone": "18955555555",
      "idCardNo": "341181199508252222",
      "idCardFront": null,
      "idCardBack": null,
      "state": 1
    },
    bankList: [{
        "id": 34,
        "staffId": 16550,
        "bankUserName": "望周知",
        "bankName": "中国邮政储蓄银行",
        "bankNumber": "6555555555555555555",
        "bankPhone": "18955555555",
        "idCardNo": "341181199508252222",
        "idCardFront": null,
        "idCardBack": null,
        "state": 1
      },
      {
        "id": 33,
        "staffId": 16550,
        "bankUserName": "望周知",
        "bankName": "招商银行卡",
        "bankNumber": "6555555555555555555",
        "bankPhone": "18955555555",
        "idCardNo": "341181199508253332",
        "idCardFront": null,
        "idCardBack": null,
        "state": 1
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  bindPickerChange(e) {
    console.log(e.detail)
    const {
      value
    } = e.detail
    let bankInfo = this.data.bankList[value]
    bankInfo.bankNum = bankInfo.bankNumber.replace(/^(?:\d+)(.{4})$/, '**** **** **** $1')
    this.setData({
      bankInfo
    })
  },
  toSumbitData() {
    
    if (this.submit) return
    const checkAgree = this.checkAgree()
    if (checkAgree) return false
    wx.p.router.go('/packageIndex/pages/integral/withdrawalSuccess/withdrawalSuccess')
    //  wx.p.wxApi.showToast('有一笔兑换正在进行')
    // let {
    //   sumbitScore,
    //   score: {
    //     existWechatMotivationWithdrawal
    //   }
    // } = this.data
    // let withDrawType = 3
    // const money = this.accSub(Number(sumbitScore), 0)

    // if (money <= 0) return  wx.p.wxApi.showToast(`您的积分不足,请确认后重新申请兑换`)
    // // this.comfirmSumbit(sumbitScore, withDrawType)
    // this.setData({
    //   showConfirmDialog: true
    // })
  },
  // 提现确认模块
  comfirmSumbit(sumbitScore, withDrawType, rateQuery = {}, sourceFrom) {
    let {
      tabIndex,
      tabData,
    } = this.data;
    Dialog.confirm({
      title: '提示',
      message: `请确认是否将${sumbitScore}积分进行兑换`,
    }).then(() => {
      if (this.submit) return
      this.submit = true
      wx.p.api.showLoading('提交中')
      MineApi.WithdrawalApi({
        withdrawalScore: sumbitScore,
        withDrawType,
        sourceFrom,
        wechatAppId: appId,
        withdrawalSource: 3,
        ...rateQuery
      }).then(res => {
        wx.hideLoading();
        if (res.code == 0) {
          wx.p.eventbus.off('REFRESH_WITHDRALWAL')
          wx.p.router.redirectTo('/packageStoreAssistant/packageMine/pages/withdrawalSuccess/withdrawalSuccess', {
            title: tabData[tabIndex]
          })
        } else {
           wx.p.wxApi.showToast(res.message)
          this.submit = false
        }
      }).catch((err) => {
         wx.p.wxApi.showToast(JSON.stringify(err))
        this.submit = false
      })
    }).catch(() => {
      this.submit = false
    });
  },
  accSub(arg1, arg2) {
    let r1, r2, m, n;
    try {
      r1 = arg1.toString().split(".")[1].length;
    } catch (e) {
      r1 = 0;
    }
    try {
      r2 = arg2.toString().split(".")[1].length;
    } catch (e) {
      r2 = 0;
    }
    m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度
    n = (r1 >= r2) ? r1 : r2;
    return ((arg1 * m - arg2 * m) / m).toFixed(n);
  },
  toTixianAll() {
    let {
      score: {
        existBankWithdrawal,
        bankWithdrawalScore,
        wechatWithdrawalScore
      }
    } = this.data,
      withdrawalScore = wechatWithdrawalScore
    this.setData({
      sumbitScore: withdrawalScore
    })
  },
  handleInput(e) {
    var value = e.detail.value
    sumbitScore = this.priceVerify(value, withdrawalScore)
    this.setData({
      sumbitScore: value
    })
  },
  // 价格输入校验规则(提现积分值:最小值需大于0)
  priceVerify(price, max, min = 0) {
    let result = 0
    // 1.限制小数点为2位
    price = price.replace(/[^\d.]/g, "")
    price = price.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
    // 2.禁止第一位为小数点
    if (price.indexOf('.') == 0) {
      price = ''
    }

    // 3.如果第一位是0,那第二位开始禁止为数值,只可以为小数点
    if (price.indexOf('0') == 0 && price.length > 1) {
      if (price.indexOf('.') != 1) {
        price = '0'
      }
      if (price[2] == '.') {
        price = '0.'
      }
    }
    // if (price.indexOf('.') != -1) {
    //   price = price.slice(0, price.indexOf('.'))
    // }
    result = price
    // 4.判断最大值和最小值
    if (price) {
      price = Number(price)
      max = Number(max)
      if (max && price > max) {
        result = max
      }
      if (min && price < min) {
        result = min
      }
    }
    return result
  },
  navbarReady(e) {
    let {
      height
    } = e.detail
    this.setData({
      navHeight: height
    })
  },
  checkAgree() {
    let {
      agree
    } = this.data
    if (!agree) {
      this.setData({
        showAuthDialog: true
      })
      return true
    }
    return false
  },
  agreeEvent(e) {
    console.log(e)
    let {
      value
    } = e.detail
    if (value == 1) {
      this.setData({
        showAuthDialog: false,
        agree: true
      })
    } else {
      this.setData({
        showAuthDialog: false
      })
    }

  },
  onClose(e) {
    console.log(e)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})