addinfo.js 17.9 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 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
// pages/main/addinfo/addinfo.js
var app = getApp();
var format = require('../../../../utils/util.js');
var baseUrl = app.globalData.baseUrl;
const cardTypeArray8 = ['居民身份证', '中国护照', '港澳居民居住证', '台湾居民居住证', '外国人永久居留身份证', '外国人工作许可证(A类)', '外国人工作许可证(B类)', '外国人工作许可证(C类)'];

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',
      placeholder: '请选择证照类型',
      values: cardTypeArray8,
      // values: ["居民身份证", "军官证", '士兵证', '武警警官证', '港澳居民来往内地通行证', '外交官证', '中国护照','外国护照', '香港永久性居民身份证', '澳门特别行政区永久性居民身份证', '台湾身份证', '台湾居民来往大陆通行证', '外国人永久居留证'],
      // range_key: 'name',
      onChange: 'onPickerSelect'
    },
    forignerInfo: {
      isrequre: true,
      label: '是否境外人员',
      bindtype: 'forigner',
      placeholder: '否',
      disabled: true,
      values: ["否", "是"],
      onChange: 'onPickerSelect'
    },
    genderData: {
      label: '性别',
      bindtype: 'gender',
      isrequre: true,
      // disabled: true,
      selected: '',
      placeholder: '请选择性别',
      // placeholder: '性别',
      values: ["男", "女"],
      onChange: 'onPickerSelect'
    },
    countryData: {
      label: '国籍',
      bindtype: 'country',
      isrequre: true,
      selected: '',
      // range_key:'name',
      placeholder: '请选择国籍',
      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)
    }
    this.getCountry()
  },
  //****************获取国籍数据************/
  getCountry: function () {
    var that = this
    wx.showLoading({
      title: '',
    })
    var Authorization = app.globalData.Authorization;
    wx.request({
      url: baseUrl + 'persontax/v1/nation-list',
      method: "GET",
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": Authorization
      },
      success: function (res) {
        var countrys = res.data
        if (countrys.indexOf('中国') > -1) {
          countrys.splice(countrys.indexOf('中国'), 1);
        }
        if (countrys.indexOf('中国台湾') > -1) {
          countrys.splice(countrys.indexOf('中国台湾'), 1);
        }
        if (countrys.indexOf('香港') > -1) {
          countrys.splice(countrys.indexOf('香港'), 1);
        }
        if (countrys.indexOf('澳门') > -1) {
          countrys.splice(countrys.indexOf('澳门'), 1);
        }
        that.data.countryData.values = countrys
        that.countrys = countrys
        that.setData({
          countryData: that.data.countryData,
        })
      },
      fail(res) {
        wx.hideLoading()
      },
      complete() {
        wx.hideLoading()
      }
    })
  },
  //****************获取自然人数据************/
  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) {
    this.dealCardType(tax_info.id_card_type)//为防止干扰其他字段,需要先执行

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

    this.data.relativeData.selected = tax_info.family_ties
    this.data.genderData.selected = tax_info.gender
    this.data.countryData.selected = tax_info.native
    // this.data.genderData.disabled = isDisable
    
    this.setData({
      isDisable: isDisable,
      relativeData: this.data.relativeData,
      name: tax_info.name,
      cardtypeData: this.data.cardtypeData,
      age: tax_info.age,
      mobile: tax_info.mobile,
      genderData: this.data.genderData,
      isIdCard: '居民身份证' == tax_info.id_card_type ? true : false,
      card_number: tax_info.id_card_no,
      countryData: this.data.countryData
    })
    // 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 = '居民身份证'
          // cardtypeData.selected_code = '1'
          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)
      },
    })
  },

  dealCardType: function (new_type) {
    var is_idcard = this.data.isIdCard
    this.data.cardtypeData.selected = new_type

    if ('居民身份证' == new_type) {
      is_idcard = true
      this.data.genderData.disabled = true
    } else {
      is_idcard = false
      this.data.genderData.disabled = false
    }
    this.data.overseas = '否'
    if ('居民身份证' == new_type || '中国护照' == new_type) {
      this.data.countryData.selected = '中国'
      this.data.countryData.disabled = true
    } else if (new_type.indexOf("港澳") != -1) {
      this.data.countryData.values = ['中国香港', '中国澳门']
      this.data.countryData.selected = ''
      this.data.countryData.disabled = false
    } else if (new_type.indexOf("台湾") != -1) {
      this.data.countryData.selected = '中国台湾'
      this.data.countryData.disabled = true
    } else {
      this.data.overseas = '是'
      this.data.countryData.selected = ''
      this.data.countryData.values = this.countrys ? this.countrys : []
      this.data.countryData.disabled = false
    }
    this.setData({
      isIdCard: is_idcard,
      genderData: this.data.genderData,
      countryData: this.data.countryData,
      cardtypeData: this.data.cardtypeData,
      overseas: this.data.overseas,
    })


  },


  // =============普通单列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 cardtypeData = this.data.cardtypeData
        var new_type = cardtypeData.values[e.detail.value] //['name']
        // var new_type_code = cardtypeData.values[e.detail.value]['code']
        if (new_type != cardtypeData.selected) {
          this.dealCardType(new_type)
          this.setData({
            card_number: ""
          })
        }
        break;
      case 'gender':
        var gender_data = this.data.genderData
        gender_data.selected = gender_data.values[e.detail.value]
        this.setData({
          genderData: gender_data
        })
        break;
      case 'country':
        var countryData = this.data.countryData
        var new_country = countryData.values[e.detail.value]
        if (new_country != countryData.selected) {
          countryData.selected = new_country
          this.setData({
            countryData: countryData
          })
        }
        break;
    }

  },
  bindinputmobile: function (e) {
    if (e.detail.value.length == 11 && !format.isMobile(e.detail.value)){
      this.showtoast("手机号码有误")
    }
    this.setData({
      mobile: e.detail.value
    })
  },
  nameInput: function (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-\u9FA5A-Za-z·s]{2,20}$/;
    // 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);
    if (this.data.relativeData.selected.length < 1) {
      this.showtoast('请选择关系');
      return
    }
    var rel = this.data.relativeData.selected
    if (this.data.card_number.length < 1) {
      this.showtoast('请填写证照号码');
      return
    } else if (this.data.isIdCard && this.data.card_number.length > 0 && !format.isIDCardNum(this.data.card_number)) {
      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 (this.data.genderData.selected.length < 1) {
      this.showtoast('请选择性别');
      return
    }else {
      if (this.data.genderData.selected == '男') {
        if (rel == '女') {
          this.showtoast('关系和性别冲突');
          return
        }
      } else {
        if (rel == '子') {
          this.showtoast('关系和性别冲突');
          return
        }
      }
      if (rel == '配偶' && this.data.genderData.selected == app.globalData.hostInfo.gender) {
        this.showtoast('关系和性别冲突');
        return
      }
    }
    if (!formdata.age) {
      this.showtoast('请填写年龄');
      return
    } else {
      var host_birth = format.formatTime_date(app.globalData.hostInfo.birth_date) 
      var host_age = format.getAge(host_birth)
      console.log('host_age',host_age,'hostInfo', app.globalData.hostInfo)
      if ((rel == '子' || rel == '女') && formdata.age > host_age) {
        this.showtoast('子女年龄有误');
        return
      }
      if (rel == '父母' && formdata.age < host_age) {
        this.showtoast('父母年龄有误');
        return
      }
    }
    if (formdata.mobile.length > 0 && !format.isMobile(formdata.mobile)) {
      this.showtoast('手机号码有误');
      return
    }
    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,//_code,
        "id_card_no": that.data.card_number,
        "name": name,
        "gender": that.data.genderData.selected,
        "mobile": formdata.mobile,
        //"age": formdata.age ? formdata.age : '',//不传
        "age": formdata.age ? formdata.age : '',
        "native": that.data.countryData.selected,
        "is_overseas_personnel": that.data.overseas,
      },
      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,
      icon:'none'
      // 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
    this.setData({
      card_number: idCardNo
    })
    if (!this.data.isIdCard) {
      return;
    }
    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
    this.setData({
      card_number: idCardNo
    })
    if (!this.data.isIdCard) {
      return;
    }
    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() {

  }
})