visitFind.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/visitFind/visitFind.js
  2. const app = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. idNumber: null
  9. },
  10. getInputValue(e) {
  11. this.setData({
  12. idNumber: e.detail.value
  13. })
  14. },
  15. bindNumber() {
  16. let id = wx.getStorageSync('openId');
  17. console.log(this.data.idNumber)
  18. if (!this.data.idNumber) {
  19. this.setData({
  20. numberNull: true
  21. })
  22. } else {
  23. this.setData({
  24. numberNull: false
  25. })
  26. if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(this.data.idNumber)) && this.data.idNumber.length != 18) {
  27. this.setData({
  28. eight: true
  29. })
  30. } else {
  31. this.setData({
  32. eight: false
  33. })
  34. var myDate = new Date();
  35. var month = myDate.getMonth() + 1;
  36. var day = myDate.getDate();
  37. var age = myDate.getFullYear() - this.data.idNumber.substring(6, 10) - 1;
  38. if (this.data.idNumber.substring(10, 12) < month || this.data.idNumber.substring(10, 12) == month && this.data.idNumber.substring(12, 14) <= day) {
  39. age++;
  40. }
  41. console.log(age, '我是身份证的年龄')
  42. if (age < 60) {
  43. this.setData({
  44. wrong: true
  45. })
  46. } else {
  47. this.setData({
  48. wrong: false
  49. })
  50. wx.showLoading({
  51. title: '加载中',
  52. })
  53. wx.request({
  54. url: app.globalData.publicUrl + '/wxinfo/visitBing',
  55. method: "GET",
  56. data: {
  57. openId: id,
  58. number: this.data.idNumber
  59. },
  60. success: res => {
  61. if (res.data.code == 0) {
  62. console.log('我绑定成功了', res)
  63. wx.navigateTo({
  64. url: '/pages/bindOld/bindOld?idNumber=' + this.data.idNumber,
  65. })
  66. } else {
  67. wx.showModal({
  68. showCancel: false,
  69. content: res.data.message,
  70. })
  71. }
  72. },
  73. complete: () => {
  74. wx.hideLoading()
  75. }
  76. });
  77. }
  78. }
  79. }
  80. },
  81. /**
  82. * 生命周期函数--监听页面加载
  83. */
  84. onLoad: function (options) {
  85. },
  86. /**
  87. * 生命周期函数--监听页面初次渲染完成
  88. */
  89. onReady: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面显示
  93. */
  94. onShow: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. }
  121. })