verify_info.js 5.5 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}$/;
const reg_20_n_a = /^([a-zA-z]|[0-9]){20}$/;
var baseUrl = getApp().globalData.baseUrl;
let Authorization = '';
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 that = this
    //校验证照类型,证照号码,姓名
    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
      }
      name = name.replace(/(^\s*)|(\s*$)/g, "");
      if (!regname_c.test(name) && !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('证照号码有误0');
        return
      }else if (type.indexOf('中国护照') > -1 && !reg_9_n_a.test(idCardNo)) {
        this.showtoast('证照号码有误');
        return
      }else if (type.indexOf('永久居留') > -1 && !reg_15_n_a.test(idCardNo)) {
        this.showtoast('证照号码有误');
        return
      }
      
      if (type.indexOf('居住证') < 0 && type.indexOf('中国护照') < 0 && type.indexOf('永久居留') < 0 &&!reg_20_n_a.test(idCardNo)) {
        this.showtoast('证照号码有误');
        return
      }
      //TODO  请求数据,上传用户身份信息
      Authorization = getApp().globalData.Authorization;
      wx.request({
        url: baseUrl + 'uaa/v1/users/auth-extend',
        method: 'POST',
        data: {
          name: name,
          id_card_type: type,
          id_card_no: idCardNo
        },
        header: {
          'content-type': 'application/json',
          "Authorization": Authorization
        },
        success: function(res) {
          console.log("SUCC", res.data)
          if (res.data.code && res.data.code >= 300) {
            wx.navigateTo({
              url: 'verify_result/verify_result?result=fail',
            })
            that.showtoast(res.data.message);
          } else {
            wx.navigateTo({
              url: 'verify_result/verify_result?result=succ',
            })
          }
        }
      })
    } 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?input_name=' + name + '&input_card_number=' + idCardNo,
      })
    }
  },

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

  }
})