cashout.js 3.8 KB
// pages/main/rewardpoint/cashout/cashout.js
Page({

  /**
   * Page initial data
   */
  data: {
    taxpercent:25,//暂时固定为25%
    showModal:false,
    hasBind:true,
    hasPayPwd:true,
    rightNum:false,
    cashNum:6989.88,
    inputNum:"",
    inputNum2Fixed:"",
    taxNum:"",
    pwdList: [1, 2, 3, 4, 5, 6],
    //输入框聚焦状态
    isFocus: false,
    //输入框聚焦样式 是否自动获取焦点
    focusType: true,
    valueData: '', //输入的值
    dataLength:''
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {

  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {

  },

  /**
   * 绑定银行卡
   */
  bindCard:function(){
    wx.navigateTo({
      url: '../bindcard/bindcard',
    })
  },
  
  /**
   * 实时监听输入框内容
   */
  getInput:function(e){
    var money;
    if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) { //正则验证,提现金额小数点后不能大于两位数字
      money = e.detail.value;
    } else {
      money = e.detail.value.substring(0, e.detail.value.length - 1);
    }
    var flag = (money&&money>0&&money<=this.data.cashNum)?true:false
    this.setData({
      inputNum: money,
      rightNum:flag
    })
  },

 /**
  * 清空输入内容
  */
  clear:function(){
    this.setData({
      inputNum: "",
      rightNum:false
    })
  },

  /**
   * 全部提现
   */
  cashAll:function(){
    this.setData({
      inputNum: this.data.cashNum,
      rightNum:true
    })
  },

  /**
   * 提现
   */
  cashOut:function(){
    if(!this.data.hasPayPwd){
        wx.navigateTo({
          url: '../setpaypwd/setpaypwd',
        })
        return
    }
    var inputnum = this.data.inputNum
    if(this.data.rightNum){
      this.setData({
        inputNum2Fixed:parseFloat(inputnum).toFixed(2),
        taxNum:parseFloat(inputnum*this.data.taxpercent/100).toFixed(2),
        showModal: !this.data.showModal?true:this.data.showModal,
      })
    }else{
      wx.showToast({
        title: '请输入正确提现金额',
        icon:"none"
      })
    }
  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {
    
  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {
    console.log('onUnload')
    this.setData({
      inputNum:"",
    inputNum2Fixed:"",
    taxNum:"",
    })
  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {

  },

  // 获得焦点时
  handleUseFocus() {
    this.setData({
      focusType: true
    })
  },

  // 失去焦点时
  handleUseBlur() {
    this.setData({
      focusType: false
    })
  },

  // 点击6个框聚焦
  handleFocus() {
    this.setData({
      isFocus: true
    })
  },

  // 获取输入框的值
  handleSetData(e) {
    // 更新数据
    this.setData({
      valueData: e.detail.value,
      dataLength:e.detail.value.length
    })
    console.log("valueData",this.data.valueData)
    // 当输入框的值等于6时(发起支付等...)
    if (e.detail.value.length === 6) {
      // 通知用户输入数字达到6位数可以发送接口校验密码是否正确
      // this.triggerEvent('initData', e.detail.value)
      wx.navigateTo({
        url: '../pointdetail/pointdetail',
      })
      this.setData({
        showModal:false,
        valueData:'',
        dataLength:0
      })
    }
  },

  closeModal:function(){
    this.setData({
      showModal:false,
      valueData:''
    })
  },

})