// pages/handle/liist.js
import * as UTIL from '../../../utils/util.js';
import * as API from '../../../utils/API.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isIPX: app.globalData.isIPX,
    pageNums:1,
    scrollHeight:"",
    financeList:[],
    index:0,
    array:["收支明细公开"],
    userInfoObj:[],
    date: UTIL.formatDates(new Date),
    data:{},
    list:[],
    msgTime:0,
    msgText:"",
    showPopup:false
  },
  onConfirmReviewTime(e){
    let data = e.detail.value;
    this.setData({
      'date':data,
      'pageNums':1});
    this.getList();
  },
  paging(){
    this.setData({
      pageNums:this.data.pageNums+1,
    })
    this.getList();
  },
  getList(id){
    UTIL.httpRequest(API.URL_GET_TRANSFERINFO+id, {method:'GET'},{
      success: (res) => {
        if(res.code == 200){
          res.data.expenditureAmount =   Number(res.data.expenditureAmount ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
            return $1 + ","; }).replace(/\.$/, "") 
          this.setData({'data':res.data})
        }else{
          UTIL.showToastNoneIcon(res.msg);
        }
      }
    })
    UTIL.httpRequest(API.URL_GET_TRANSFERINFOS+id, {method:'GET'},{
      success: (res) => {
        if(res.code == 200){
          res.rows.map(rr => {
            rr.incomeAmount =   Number(rr.incomeAmount ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
            return $1 + ","; }).replace(/\.$/, "") 
          })
          console.log(res.rows);
          this.setData({list:res.rows})
        }else{
          UTIL.showToastNoneIcon(res.msg);
        }
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList(options.id)
  },
  goSubmit(){
    let _this = this
    if(this.data.data.bankType!=4){
        if(this.data.data.expenditureAmount > 50000&&this.data.data.bankType == '3'){
          wx.showModal({
            title: "",
            showCancel: false,
            showComfirm: false,
            content: "银行仅在工作日的9:00~17:00之间接收金额大于5万元的交易申请，不在此服务时间段内提交申请将导致交易失败！",
            confirmText: '确定',
            success: function (e) {
            //非建行
            if(_this.data.data.accountPassword==null||_this.data.data.accountPassword.length<1){
              UTIL.showToastNoneIcon("请输入支付口令！");
            }else{
              _this.setData({'showPopup':true})
            }
            }
          })
        }else if(this.data.data.bankType == '2'&&this.data.list.length>1&&this.data.data.isPeers == 'Y'){
          wx.showModal({
            title: "",
            showCancel: false,
            content: "同行批量转账业务银行仅支持在每日9:00-17:00之间办理，交易请求接受成功后银行会在次日3:30统一进行处理，正常1小时内处理完成，请在此时间后查询处理结果！",
            confirmText: '确定',
            success: function (e) {
            //非建行
            if(_this.data.data.accountPassword==null||_this.data.data.accountPassword.length<1){
              UTIL.showToastNoneIcon("请输入支付口令！");
            }else{
              _this.setData({'showPopup':true})
            }
            }
          })
        }else{
          wx.showModal({
            title: "",
            showCancel: false,
            content: "跨行批量转账业务银行仅支持在每日9:00-16:00之间办理，交易请求接受成功后银行会在当日17点-23点统一进行处理，请在此时间后查询处理结果！",
            confirmText: '确定',
            success: function (e) {
            //非建行
            if(_this.data.data.alternateField1==null||_this.data.data.alternateField1.length<1){
              UTIL.showToastNoneIcon("请输入验证码！");
            }else{
              _this.setData({'showPopup':true})
            }
            }
          })
        }
    }else{
        //建行
        wx.showModal({
          title: "",
          showCancel: false,
          content: "跨行批量转账业务银行仅支持在每日9:00-16:00之间办理，交易请求接受成功后银行会在当日17点-23点统一进行处理，请在此时间后查询处理结果！",
          confirmText: '确定',
          success: function (e) {
            if(_this.data.data.alternateField1==null||_this.data.data.alternateField1.length<1){
              UTIL.showToastNoneIcon("请输入验证码！");
            }else{
              _this.setData({'showPopup':true})
            }
          }
        })
        
    }
  },
  bindNewInput: function (e) {
    this.setData({
      [e.currentTarget.dataset.name]: e.detail.value
    })
  },
  confirmPay(){
    let _this = this
    this.setData({'showPopup':false})
    console.log(this.data.data.bankType);
    if(this.data.data.bankType==4){
      let params = {
        id : this.data.data.id,
        alternateField1:this.data.data.alternateField1,
        bankType: this.data.data.bankType
      }
      UTIL.httpRequest(API.URL_GET_PAY,params,{
        success: (res) => {
          wx.showModal({
            title: "",
            showCancel: false,
            content: "支付成功,请等待银行进行处理，稍后可通过查询结果按钮查询银行处理结果。",
            confirmText: '确定',
            success: function (e) {
              _this.back()
            }
          })
        },
        fail:(res) => {
          UTIL.showToastNoneIcon(res)
        }
      })
    }else{
      let params = {
        id : this.data.data.id,
        accountPassword:this.data.data.accountPassword,
        bankType: this.data.data.bankType
      }
      UTIL.httpRequest(API.URL_GET_PAY,params,{
        success: (res) => {
          if (res.code == API.SUCCESS_CODE) {
            wx.showModal({
              title: "",
              showCancel: false,
              content: "支付成功,请等待银行进行处理，稍后可通过查询结果按钮查询银行处理结果。",
              confirmText: '确定',
              success: function (e) {
                _this.back()
              }
            })
          }else{
            wx.showModal({
              title: "",
              showCancel: false,
              content: res.msg,
              confirmText: '确定',
              success: function (e) {
                
              }
            })
          }
        },
        fail:(res) => {
          UTIL.showToastNoneIcon(res)
        }
      })
    }
    
  },
  cancelPay(){
    this.setData({'showPopup':false})
  },
sendMsg(){
  let _this = this
  let params = {
      id : this.data.data.id,
      bankType: this.data.data.bankType
  }
  if(this.data.msgTime>0){
    return false
  }
  UTIL.httpRequest(API.URL_GET_SENDMSG,params,{
    success: (res) => {
      if (res.code == API.SUCCESS_CODE) {
        if (res.toString().indexOf('短信发送失败') == -1){
          _this.setData({'msgText':180+'s后可重新发送','msgTime':180})
          _this.msgTimer = setInterval(()=>{
            let tt = _this.data.msgTime
            _this.setData({'msgText':tt--+'s后可重新发送','msgTime':tt})
            if (_this.data.msgTime == 0){
              clearInterval(_this.msgTimer);
              _this.msgTime = 0 ;
              _this.smsText = '';
            }
          },1000)
        }else{
          UTIL.showToastNoneIcon("短信发送失败,请联系管理员！");
        }
      }else{
        UTIL.showToastNoneIcon(res.msg);
      }
    },
        fail:(res) => {
          UTIL.showToastNoneIcon(res)
        }
  })
},
  bindPickerChange:function(e){
    this.setData({index:e.detail.value});
  },
  switchTab:function(e){
    this.setData({
      active:e.currentTarget.dataset.gid
    })
  },
  back:function(){
    wx.navigateBack({
      delta: 1
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})