// pages/validateForm/yzCard/yzCard.js
const app = getApp()
var util = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr: ['', '', '', '', '', ''],
    numNo: '',
    msg: {
      IdCard: "51010519410613971x",
      Name: "付淑清",
      PassportNo: "ED3495877",
      choosetype:"1",
      TCID:'7003',
    },
    focusShow:true,
    focusList: [true, false, false, false, false, false],
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let msg = this.data.msg;
    if (options.IdCard) {
      msg = {
        IdCard: options.IdCard,
        Name: options.Name,
        PassportNo: options.PassportNo,
        choosetype: options.choosetype,
        TCID: options.TCID,
      }
      this.setData({
        msg:msg
      })
    }

  },
  numer(e) {
    let index = e.currentTarget.dataset.index;
    let val = e.detail.value;
    let newArr = val.split('');
    
    this.setData({
      arr: newArr
    })
  },
  showKeyboard(){
    this.setData({
      focusShow: true
    })
  },
  yzBtn() {
    let openId = (wx.getStorageSync('openId'))
    let self = (wx.getStorageSync('self'))
    let arr = this.data.arr;
    let msg = this.data.msg;
    let number = arr[0] + arr[1] + arr[2] + arr[3] + arr[4] + arr[5];
    let str = '';
    let str1='';
    let tips='';
    let info = {
      Type: msg.choosetype,
      TCID: msg.TCID,
      Number: '',
      OpenId: openId,
      Photo: self.avatarUrl,
    };
    if (msg.choosetype=='1'){
      let str_6 = msg.IdCard.substring(msg.IdCard.length - 6);
      
      let last = msg.IdCard.substring(msg.IdCard.length - 1);
      let p = /[a-z]/i; 
      let b = p.test(str_6);
      if(b){
        str1 = str_6.toUpperCase();
      }
      str = str_6.toLowerCase();
      tips ="身份证号码";
      info.Number = msg.IdCard;
    }
    if (msg.choosetype == '2') {
      str = msg.PassportNo.substring(msg.PassportNo.length - 6);
      tips = "护照";
      info.Number = msg.PassportNo;
    }
    if (str != number && str1 !=number){
      util.showToast('text', tips+'不一致！', { duration: 3000 })
      return;
    }
   
    app.$api('b2b_get_GetMXYTravelOrderInfo', info).then(res => {
      if (res.IsOK == 1) {
        let userInfo = res.Info
        wx.setStorageSync('userInfo', userInfo)
        wx.switchTab({ url: '/pages/index/index' })
      }
    }).catch(err => { })
    
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})