addinfo.js 13.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
// pages/main/addinfo/addinfo.js
var app = getApp();
var format = require('../../../../utils/util.js');
var baseUrl = app.globalData.baseUrl;
Page({
  cur_id:null,
  /**
   * 页面的初始数据
   */
  data: {
    isEnable: true,
    isshow01: false,
    isshow02: false,
    isshow03: false,
    proffessionlist: {},
    banklist: {},
    isself: false,
    isIdCard: true,
    name: '',
    card_number: '',
    birthday: '',
    requestBody: {},
    idInfoData: '',
    profession_index: [],

    relativeData: {
      isrequre: true,
      label: '与本人关系',
      bindtype: 'relative',
      selected: '',
      disabled: false,
      placeholder: '请选择关系',
      // values: ["子","女" ,"配偶", "父母", "祖父母、外祖父母"],
      values: ["子", "女", "配偶", "父母"],
      onChange: 'onPickerSelect'
    },
    cardtypeData: {
      isrequre: true,
      disabled: true,
      label: '证照类型',
      bindtype: 'cardtype',
      selected: '居民身份证',
      placeholder: '请选择证照类型',
      values: ["居民身份证", "军官证", '士兵证', '武警警官证', '港澳居民来往内地通行证', '外交官证', '中国护照',
        '外国护照', '香港永久性居民身份证', '澳门特别行政区永久性居民身份证', '台湾身份证', '台湾居民来往大陆通行证', '外国人永久居留证'
      ],
      onChange: 'onPickerSelect'
    },
    forignerInfo: {
      isrequre: true,
      label: '是否境外人员',
      bindtype: 'forigner',
      placeholder: '否',
      disabled: true,
      values: ["否", "是"],
      onChange: 'onPickerSelect'
    },
    genderData: {
      label: '性别',
      bindtype: 'gender',
      selected: '',
      placeholder: '请选择性别',
      values: ["男", "女"],
      onChange: 'onPickerSelect'
    },

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log('options.id', options.id)
    if (options.id && options.id.length > 0) {
      this.cur_id = options.id
      this.getpersonalTax(options.id)
    }
  },

  //****************获取自然人数据************/
  getpersonalTax: function (id) {
    var that = this
    wx.showLoading({
      title: '',
    })
    var Authorization = app.globalData.Authorization;
    wx.request({
      url: baseUrl + 'persontax/v1/personal-taxes/' + id,
      method: "GET",
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": Authorization
      },
      success: function (res) {
        console.log('taxInfo', res)
        that.setData({
          taxInfo: res.data,
          isself: res.data.family_ties=='本人' ? true : false
        })
        that.handleDatas(res.data)
      },
      fail(res) {
        console.log(res)
        wx.hideLoading()
      },
      complete() {
        wx.hideLoading()
      }
    })
  },
  //对各参数初始赋值
  handleDatas: function (tax_info) {

    var isDisable = tax_info.certification_status == 'active'//已通过拍摄身份证认证过,不能修改

    this.data.relativeData.selected = tax_info.family_ties
    // this.data.cardtypeData.selected = tax_info.id_card_type
    this.data.genderData.selected = tax_info.gender
    this.data.genderData.disabled = isDisable
    
    this.setData({
      isDisable: isDisable,
      relativeData: this.data.relativeData,
      name: tax_info.name,
      // cardtypeData: this.data.cardtypeData,
      mobile: tax_info.mobile,
      genderData: this.data.genderData,
      isIdCard: '居民身份证' == tax_info.id_card_type ? true : false,
      card_number: tax_info.id_card_no
    })
    this.dealIdInfo(tax_info.id_card_no)//处理了性别和年龄
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    wx.getStorage({
      key: 'id_info',
      success: function(res) {
        console.log('id_info', res.data)
        if (res.data && res.data.length > 0) {
          var id_info = JSON.parse(res.data)

          var birth_day
          if (id_info.birthday.month > 9 && id_info.birthday.day > 9) {
            birth_day = id_info.birthday.year + '-' + id_info.birthday.month + '-' + id_info.birthday.day;
          } else if (id_info.birthday.month > 9 && id_info.birthday.day < 10) {
            birth_day = id_info.birthday.year + '-' + id_info.birthday.month + '-0' + id_info.birthday.day;
          } else if (id_info.birthday.month < 10 && id_info.birthday.day > 9) {
            birth_day = id_info.birthday.year + '-0' + id_info.birthday.month + '-' + id_info.birthday.day;
          } else if (id_info.birthday.month < 10 && id_info.birthday.day < 10) {
            birth_day = id_info.birthday.year + '-0' + id_info.birthday.month + '-0' + id_info.birthday.day;
          }
          // var cardtype_Data = that.data.cardtypeData
          // cardtype_Data.selected = '居民身份证'
          var gender_Data = that.data.genderData
          gender_Data.selected = id_info.gender

          // that.data.birthDate.selected = birth_day

          // if (that.data.name.length > 0 && id_info.name != that.data.name) {
          //   that.showtoast("姓名冲突")
          //   return
          // }
          // if (that.data.card_number.length > 0 && id_info.id_card_number != that.data.card_number) {
          //   that.showtoast("证照号码冲突")
          //   return
          // }
          that.setData({
            idInfoData: id_info,
            name: id_info.name,
            // birthday: birth_day,
            // cardtypeData: cardtype_Data,
            genderData: gender_Data,
            // long_birth_date: Date.parse(new Date(birth_day)) / 1000,
            // birthDate: that.data.birthDate,
            card_number: id_info.id_card_number
          })
          that.dealIdInfo(id_info.id_card_number)
        }
      },
    })
    wx.removeStorage({
      key: 'id_info',
      success: function(res) {
        console.log('remove_idinfo', res)
      },
    })
  },

  // =============普通单列picker选中处理==============
  onPickerSelect: function(e) {
    console.log('picker发送选择改变,携带值为', e)
    switch (e.currentTarget.id) {
      case 'relative':
        var relative_data = this.data.relativeData
        relative_data.selected = relative_data.values[e.detail.value]
        this.setData({
          relativeData: relative_data
        })
        break;
      case 'cardtype':
        var is_idcard = this.data.isIdCard
        var cardtype_data = this.data.cardtypeData
        cardtype_data.selected = cardtype_data.values[e.detail.value]
        if (0 == e.detail.value) {
          is_idcard = true
        } else {
          is_idcard = false
        }
        this.setData({
          isIdCard: is_idcard,
          cardtypeData: cardtype_data
        })
        break;
      case 'gender':
        var gender_data = this.data.genderData
        gender_data.selected = gender_data.values[e.detail.value]
        this.setData({
          genderData: gender_data
        })
        break;
     
    }

  },
  bindinputmobile: function (e) {
    console.log('bindinputmobile', e)
    this.setData({
      mobile: e.detail.value
    })
  },
  nameInput: function (e) {
    console.log('bindinputname', e)
    this.setData({
      name: e.detail.value
    })
  },
  // =============其他数据选中处理==============

  getIdInfo: function(e) {
    if (this.data.isIdCard) {
      wx.navigateTo({
        url: '../idinfo/idinfo',
        success: function(res) {},
      })
    }
  },

  formSubmit: function(e) {
    // console.log("date", Date.parse(new Date(this.data.birthday)) / 1000)
    var regMoney = /^[0-9]*(\.[0,10]{1,2})?$/;
    var regMobile = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/;
    var regname = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,}$/;
    var regEmail = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,20}[a-z0-9]+$");
    var formdata = e.detail.value;
    console.log("formdata", formdata);
    console.log('idnum', this.data.card_number.length < 1 && !format.isIDCardNum(formdata.id_card_no))
    if (this.data.relativeData.selected.length < 1) {
      this.showtoast('请选择关系');
      return
    }
    else if (this.data.isIdCard && (this.data.card_number.length < 1 && formdata.id_card_no.length < 1)) {
      this.showtoast('请填写证照号码');
      return
    } else if (this.data.isIdCard && !format.isIDCardNum(formdata.id_card_no)) {
      this.showtoast('证照号码有误');
      return
    }
    var name = formdata.person_name.length ? formdata.person_name : this.data.name
    if (name.length < 1 ) {
      this.showtoast('姓名未填写');
      return
    } else if (!regname.test(name)) {
      this.showtoast('请输入正确姓名');
      return
    }
    if (formdata.mobile.length > 0 && !format.isMobile(formdata.mobile)) {
      this.showtoast('手机号码有误');
      return
    } 
    var new_card_num = ''
    if (this.data.isIdCard) {
      if (this.data.card_number.length > 0) {
        new_card_num = this.data.card_number
      }
      if (formdata.id_card_no.length > 0) {
        new_card_num = formdata.id_card_no
      }
    }

    if (!this.data.isIdCard && formdata.id_card_no && formdata.id_card_no.length > 0) {
      new_card_num = formdata.id_card_no
    }
    this.setData({
      card_number: new_card_num,
    })
    this.goCommit(formdata);
  },

  goCommit: function(data) {
    var that = this
    var formdata = data
    var name = formdata.person_name.length ? formdata.person_name : this.data.name
    console.log("form_data", formdata);
    var Authorization = app.globalData.Authorization;
    var url = baseUrl + 'persontax/v1/personal-taxes', method = "POST"
    if (this.cur_id && this.cur_id.length){
      url = baseUrl + 'persontax/v1/personal-taxes/' + this.cur_id
      method = "PUT"
    }
    wx.showLoading({
      title: '',
    })
    wx.request({
      url: url,
      method: method,
      data: {
        'certification_status': that.getCertifyStatus(formdata),
        "family_ties": that.data.relativeData.selected,
        "id_card_type": '居民身份证',//that.data.cardtypeData.selected,
        "id_card_no": formdata.id_card_no ? formdata.id_card_no : that.data.card_number,
        "name": name,
        "gender": that.data.genderData.selected,
        "mobile": formdata.mobile,
        //"age": formdata.age ? formdata.age : '',//不传
        "native": "中国",
        "is_overseas_personnel": "否",
      },
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": Authorization
      },
      success: function(res) {
        console.log(res)
        if (res.statusCode == 200) {
          wx.navigateBack({
            delta: 1
          })
        } else {
          wx.showModal({
            title: res.data.message,
            content: '',
          })
        }
        wx.hideLoading()
      },
      fail(res) {
        console.log(res)
        wx.hideLoading()
      }
    })
  },


  getCertifyStatus: function(formdata) {
    var iddata = this.data.idInfoData;
    var name = this.data.name.length > 0 ? this.data.name : formdata.name;
    var cardtype = this.data.cardtypeData.selected;
    var card_no = formdata.id_card_no ? formdata.id_card_no : this.data.card_number;
    var gender = this.data.genderData.selected;
    //var birth_day = this.data.birthDate.selected;
    if (name == iddata.name && cardtype == '居民身份证' && card_no == iddata.id_card_number && gender == iddata.gender ){// && birth_day == this.data.birthday) {
      return 'active'
    } else {
      return ''
    }
  },

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

  dealIdInfo: function (idCardNum) {
    var info = format.analyzeIDCard(idCardNum)
    console.log('info', info.age, info.sex)
    if (info.age) {
      this.setData({
        age: info.age
      })
    }
    if (info.sex) {
      var gender_data = this.data.genderData
      gender_data.selected = info.sex
      this.setData({
        genderData: gender_data
      })
    }
  },

  idChange: function (e) {
    console.log('idCardNoChange', e.detail.value)
    var idCardNo = e.detail.value
    if (e.detail.value.length == 18){
      if (!format.isIDCardNum(idCardNo)) {
        wx.showToast({
          image: "../../../../images/warn.png",
          title: '身份证格式有误'
        })
        return;
      }
      this.dealIdInfo(idCardNo)
    }
  },
  idDone: function (e) {

    var idCardNo = e.detail.value
    if (!idCardNo.length) {
      wx.showToast({
        image: "../../../../images/warn.png",
        title: '请输入身份证号'
      })
      return;
    }
    if (!format.isIDCardNum(idCardNo)) {
      wx.showToast({
        image: "../../../../images/warn.png",
        title: '身份证格式有误'
      })
      return;
    }

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})