checkoutIdCard.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp()
  4. Page({
  5. data: {
  6. userInfo: {},
  7. curUser: {},
  8. idNoM: '',
  9. idNo: '',
  10. currentIdNo: '',
  11. userName: '',
  12. array: ['居民身份证'],
  13. items: [
  14. { name: '1', value: '反光识别', checked: 'true' },
  15. { name: '2', value: '读数识别' },
  16. ],
  17. isAgree: false
  18. },
  19. radioChange: function (e) {
  20. console.log('radio发生change事件,携带value值为:', e.detail.value)
  21. },
  22. checkBoxAgree: function(e){
  23. this.setData({
  24. isAgree: !this.data.isAgree
  25. });
  26. },
  27. onLoad: function (options) {
  28. // 页面初始化 options为页面跳转所带来的参数
  29. let that = this;
  30. },
  31. onReady: function () {
  32. },
  33. onShow: function () {
  34. let that = this;
  35. let userInfo = wx.getStorageSync('userInfo');
  36. let token = wx.getStorageSync('token');
  37. // 页面显示
  38. if (userInfo && token) {
  39. app.globalData.userInfo = userInfo;
  40. app.globalData.token = token;
  41. this.setData({
  42. userInfo: app.globalData.userInfo,
  43. });
  44. util.request(api.getCurUser, {
  45. userInfo: app.globalData.userInfo
  46. }, 'POST').then(function (res) {
  47. if (res.errno === 0) {
  48. that.setData({
  49. curUser: res.data
  50. });
  51. if (res.data.idNo) {
  52. that.setData({
  53. idNoM: that.formatidcard(res.data.idNo),
  54. idNo: res.data.idNo,
  55. currentIdNo: res.data.idNo,
  56. userName: res.data.username
  57. });
  58. }
  59. }
  60. });
  61. } else {
  62. wx.navigateTo({
  63. url: '/pages/ucenter/userLogin/userLogin'
  64. })
  65. }
  66. },
  67. onHide: function () {
  68. // 页面隐藏
  69. },
  70. onUnload: function () {
  71. // 页面关闭
  72. },
  73. readUserService: function(){
  74. // wx.navigateTo({
  75. // url: '../userService/userService'
  76. // });
  77. },
  78. readUserPrivacy: function () {
  79. // wx.navigateTo({
  80. // url: '../userPrivacy/userPrivacy'
  81. // });
  82. },
  83. saveIdCard: function (e) {
  84. let that = this;
  85. if (that.data.isAgree == false) {
  86. wx.showToast({
  87. title: '请先阅读并勾选内容',
  88. icon: 'none'
  89. });
  90. return false;
  91. }
  92. if (!e.detail.value.idNo) {
  93. wx.showToast({
  94. title: '身份证号不能为空',
  95. icon: 'none'
  96. });
  97. return false;
  98. }
  99. if (!e.detail.value.username) {
  100. wx.showToast({
  101. title: '姓名不能为空',
  102. icon: 'none'
  103. });
  104. return false;
  105. }
  106. if (that.data.idNoM != that.formatidcard(e.detail.value.idNo)) {
  107. that.setData({
  108. idNo: e.detail.value.idNo
  109. });
  110. } else {
  111. that.setData({
  112. idNo: that.data.currentIdNo
  113. });
  114. }
  115. that.setData({
  116. userName: e.detail.value.username
  117. });
  118. console.log(that.data.idNo);
  119. if (!that.checkIdcard(that.data.idNo)) {
  120. wx.showToast({
  121. title: '请输入正确的身份证号',
  122. icon: 'none'
  123. });
  124. return false;
  125. }
  126. wx.navigateTo({
  127. url: '../checkVideo/checkVideo'
  128. });
  129. /**util.request(api.idCardRealName, {
  130. idNo: that.data.idNo,
  131. userName: that.data.userName
  132. }, 'POST').then(function (res) {
  133. if (res.errno === 0) {
  134. //成功提示
  135. // wx.showToast({
  136. // title: res.errmsg
  137. // });
  138. that.setData({
  139. idNoM: that.formatidcard(e.detail.value.idNo)
  140. });
  141. wx.navigateTo({
  142. url: '../checkVideo/checkVideo'
  143. });
  144. } else {
  145. wx.showToast({
  146. title: res.errmsg,
  147. icon: 'none'
  148. });
  149. }
  150. });**/
  151. },
  152. clearData: function () {
  153. let that = this;
  154. that.setData({
  155. idNoM: ''
  156. });
  157. },
  158. formatidcard(idcard) {
  159. var reg = /^(.).+(.)$/g;
  160. if (idcard.length == 15) {
  161. // return idcard.replace(/(\d{6})\d{6}(\d{3})/, "$1******$2");
  162. return idcard.replace(reg, "$1*************$2");
  163. } else {
  164. return idcard.replace(reg, "$1****************$2");
  165. }
  166. },
  167. // 校验身份证号
  168. //校验码校验
  169. checkCode: function (val) {
  170. var p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
  171. var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  172. var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
  173. var code = val.substring(17);
  174. if (p.test(val)) {
  175. var sum = 0;
  176. for (var i = 0; i < 17; i++) {
  177. sum += val[i] * factor[i];
  178. }
  179. if (parity[sum % 11] == code.toUpperCase()) {
  180. return true;
  181. }
  182. }
  183. return false;
  184. },
  185. //省份校验
  186. checkProv: function (val) {
  187. var pattern = /^[1-9][0-9]/;
  188. var provs = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江 ", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北 ", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏 ", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门" };
  189. if (pattern.test(val)) {
  190. if (provs[val]) {
  191. return true;
  192. }
  193. }
  194. return false;
  195. },
  196. //出生日期码校验
  197. checkDate: function (val) {
  198. var pattern = /^(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)$/;
  199. if (pattern.test(val)) {
  200. var year = val.substring(0, 4);
  201. var month = val.substring(4, 6);
  202. var date = val.substring(6, 8);
  203. var date2 = new Date(year + "-" + month + "-" + date);
  204. if (date2 && date2.getMonth() == (parseInt(month) - 1)) {
  205. return true;
  206. }
  207. }
  208. return false;
  209. },
  210. checkIdcard: function (val) {
  211. if (this.checkCode(val)) {
  212. var date = val.substring(6, 14);
  213. if (this.checkDate(date)) {
  214. if (this.checkProv(val.substring(0, 2))) {
  215. return true;
  216. }
  217. }
  218. }
  219. // this.isError("请输入正确身份证号");
  220. return false;
  221. },
  222. // 通过身份证号获取出生日期和性别
  223. getBirthAndSex: function (idCard) {
  224. var that = this;
  225. var info = {};
  226. var birth = (idCard.length === 18) ? idCard.slice(6, 14) : idCard.slice(6, 12);
  227. var order = (idCard.length === 18) ? idCard.slice(-2, -1) : idCard.slice(-1);
  228. info.birthDay = (idCard.length === 18) ? ([birth.slice(0, 4), birth.slice(4, 6), birth.slice(-2)]).join('-') : (['19' + birth.slice(0, 2), birth.slice(2, 4), birth.slice(-2)]).join('-');
  229. info.sex = (order % 2 === 0 ? 2 : 0);
  230. return info;
  231. }
  232. })