verify_info.js 4.7 KB
// pages/main/verify/verify_info.js
var format = require('../../../utils/util.js');
const reg_18_Number = /^[0-9]{18}$/;
const reg_9_n_a = /^([a-zA-z]|[0-9]){9}$/;
const reg_15_n_a = /^([a-zA-z]|[0-9]){15}$/;
Page({
  /**
   * Page initial data
   */
  data: {
    is_foreigner: false,
    btn_text: "下一步",
    info_steps: [
      {
        label: '身份信息',
        status: 'success'
      }, {
        label: '上传证件照',
        status: 'circle'
      }
    ],
    cardTypeArray: ['中国护照', '港澳居民来往内地通行证', '港澳居民居住证', '台湾居民来往大陆通行证', '台湾居民居住证', '外国护照', '外国人永久居留身份证', '外国人工作许可证(A类)', '外国人工作许可证(B类)', '外国人工作许可证(C类)'],
    cardtype: "",
    card_number:"",
    name:"",
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    console.log("options", options);
    this.setData({
      is_foreigner: options.foreigner,
      btn_text: "true" == options.foreigner ? "提交" : "下一步"
    })
  },

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

  },

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

  },

  bindCardtypeChange: function (e) {
    console.log("bindCardtypeChange", e)
    var cardTypeArray = this.data.cardTypeArray
    var new_type = cardTypeArray[e.detail.value] //['name']
    this.setData({
      cardtype: new_type
    })
  },

  bindinputcardnum: function (e) {
    var idCardNo = e.detail.value
    this.setData({
      card_number: idCardNo
    })
  },

  nameInput: function (e) {
    this.setData({
      name: e.detail.value
    })
  },

  dealCardType: function () {//提交前验证输入的内容规则
    
  },

  gonext: function () {
     //校验证照类型,证照号码,姓名
    var type = this.data.cardtype;
    var idCardNo = this.data.card_number;
    var name = this.data.name.replace(/(^\s*)|(\s*$)/g, "");
    var regname_c = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,30}$/;  //中文
    var regname_e = /^[A-Za-z][A-Za-z\s]*[A-Za-z]$/;         //英文
    console.log('cardtype', type)
    if (this.data.is_foreigner == 'true') {//非身份证
      if (type.length < 1) {
        this.showtoast('请选择证照类型');
        return
      }
      if (name.length < 1) {
        this.showtoast('请输入姓名');
        return
      }
      //todo 需要跟喜文确认 中英文姓名规则
      name = name.replace(/(^\s*)|(\s*$)/g, "");
      if (type.indexOf('中国护照') > -1) {
        if (!regname_c.test(name)) {
          this.showtoast('请输入正确的中文名');
          return
        }
      } else if (!regname_e.test(name)) {
        this.showtoast('请输入正确的英文名');
        return
      }
      if (idCardNo.length < 1) {
        this.showtoast('请填写证照号码');
        return
      }
      if (type.indexOf('居住证') > -1 && !reg_18_Number.test(idCardNo)) {
        this.showtoast('证照号码有误');
        return
      }
      if (type.indexOf('中国护照') > -1 && !reg_9_n_a.test(idCardNo)) {
        this.showtoast('证照号码有误');
        return
      }
      if (type.indexOf('永久居留') > -1 && !reg_15_n_a.test(idCardNo)) {
        this.showtoast('证照号码有误');
        return
      }
      //TODO  请求数据,上传用户身份信息
      wx.showToast({
        title: '提交成功',
        icon: "none",
        duration: 2000
      })
      wx.navigateBack({})
    } else {//身份证
      if (name.length < 1) {
        this.showtoast('请输入姓名');
        return
      }
      if (!regname_c.test(name)) {
        this.showtoast('请输入正确的姓名');
        return
      }
      if (idCardNo.length < 1) {
        this.showtoast('请填写证照号码');
        return
      }
      if (!format.isIDCardNum(idCardNo)) {
        this.showtoast('证照号码有误');
        return;
      }
      wx.navigateTo({
        url: 'verify_idcard/verify_idcard',
      })
    }
  },

  showtoast: function (title) {
    wx.showToast({
      title: title,
      duration: 2000,
      icon: 'none'
      // image: '/images/error.png'
    })
  },

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

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {

  },

  /**
   * 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 () {

  }
})