index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import {
  2. postApprove
  3. } from '../../services/index.js'
  4. import {
  5. uploadImg
  6. } from '../../services/uploadFile.js'
  7. import {
  8. imgServerUrl,
  9. imgServerUrl_new
  10. } from '../../config/config.js'
  11. import { isIDNum } from '../../utils/base'
  12. var app = getApp()
  13. Page({
  14. data: {
  15. imgServerUrl: imgServerUrl,
  16. imgServerUrl_new: imgServerUrl_new,
  17. realName: '',
  18. idNum: '',
  19. idFrontPic: '',
  20. idBackPic: '',
  21. idPersonPic: '',
  22. showMessage: false,
  23. message: '',
  24. canUpdate: false,
  25. from: ''
  26. },
  27. onLoad: function (options) {
  28. if (options.from) {
  29. this.setData({
  30. from: options.from
  31. })
  32. }
  33. },
  34. testCanUpdate() {
  35. let {
  36. realName,
  37. idNum,
  38. idFrontPic,
  39. idBackPic,
  40. // idPersonPic
  41. } = this.data;
  42. this.setData({
  43. canUpdate: false
  44. })
  45. if (realName == "") {
  46. return false;
  47. }
  48. if (!isIDNum(idNum)) {
  49. return false;
  50. }
  51. if (idFrontPic == "") {
  52. return false;
  53. }
  54. if (idBackPic == "") {
  55. return false;
  56. }
  57. this.setData({
  58. canUpdate: true
  59. })
  60. },
  61. callPhone() {
  62. wx.makePhoneCall({
  63. phoneNumber: '4006920099',
  64. success: () => {
  65. this.setData({
  66. showMessage: false
  67. })
  68. }
  69. })
  70. },
  71. chooseImage(e) {
  72. let index = e.currentTarget.dataset.index
  73. var up_type;
  74. switch (index) {
  75. case 1:
  76. up_type = '1';
  77. break;
  78. case 2:
  79. up_type = '2';
  80. break;
  81. case 3:
  82. up_type = '3';
  83. break;
  84. }
  85. uploadImg(up_type).then(res => {
  86. let image = res.data.imgUrl
  87. if (index == 1) {
  88. this.setData({
  89. idFrontPic: image
  90. }, _ => {
  91. this.testCanUpdate()
  92. })
  93. } else if (index == 2) {
  94. this.setData({
  95. idBackPic: image
  96. }, _ => {
  97. this.testCanUpdate()
  98. })
  99. } else if (index == 3) {
  100. this.setData({
  101. idPersonPic: image
  102. }, _ => {
  103. this.testCanUpdate()
  104. })
  105. }
  106. })
  107. },
  108. changeName(e) {
  109. this.setData({
  110. realName: e.detail.value.trim()
  111. }, _ => {
  112. this.testCanUpdate()
  113. })
  114. },
  115. changeId(e) {
  116. this.setData({
  117. idNum: e.detail.value.trim()
  118. }, _ => {
  119. this.testCanUpdate()
  120. })
  121. },
  122. submit(e) {
  123. this.testCanUpdate();
  124. let {
  125. realName,
  126. idNum,
  127. idFrontPic,
  128. idBackPic,
  129. // idPersonPic
  130. } = this.data;
  131. if (realName == "") {
  132. wx.showToast({
  133. title: '请输入姓名',
  134. icon: 'none'
  135. })
  136. return false;
  137. }
  138. if (!isIDNum(idNum)) {
  139. wx.showToast({
  140. title: '请输入18位身份证号码',
  141. icon: 'none'
  142. })
  143. return false;
  144. }
  145. if (idFrontPic == "") {
  146. wx.showToast({
  147. title: '请上传身份证正面照',
  148. icon: 'none'
  149. })
  150. return false;
  151. }
  152. if (idBackPic == "") {
  153. wx.showToast({
  154. title: '请上传身份证反面照',
  155. icon: 'none'
  156. })
  157. return false;
  158. }
  159. // if (idPersonPic == "") {
  160. // wx.showToast({
  161. // title: '请上传手持身份证照片',
  162. // icon: 'none'
  163. // })
  164. // return false;
  165. // }
  166. wx.showLoading({
  167. title: '正在创建...',
  168. mask: true
  169. })
  170. wx.hideLoading()
  171. wx.showLoading({
  172. title: '正在提交...',
  173. mask: true
  174. })
  175. let paramsObj = {
  176. realName: realName,
  177. idCardNumber: idNum,
  178. idFrontPic: idFrontPic,
  179. idBackPic: idBackPic,
  180. // idPersonPic: idPersonPic,
  181. minaType: 1, //1:代表小程序
  182. user_id: app.globalData.userId,
  183. user_token: app.globalData.userToken,
  184. member_id: app.globalData.memberId
  185. }
  186. Object.assign(paramsObj);
  187. postApprove(paramsObj).then(data => {
  188. wx.hideLoading()
  189. wx.showToast({
  190. title: '提交成功',
  191. })
  192. if (this.data.from === 'clock') {
  193. wx.redirectTo({
  194. url: '../result/index?type=auth&status=2&from=clock',
  195. })
  196. return
  197. }
  198. wx.redirectTo({
  199. url: '../result/index?type=auth&status=2',
  200. })
  201. }).catch(data => {
  202. if (data.errcode === 2100) {
  203. this.setData({
  204. showMessage: true,
  205. message:'您的身份证已经被实名认证'
  206. })
  207. return
  208. }
  209. if(data.errcode === 2101){
  210. this.setData({
  211. showMessage: true,
  212. message:'您的身份证已实名认证,无需重复认证'
  213. })
  214. return
  215. }
  216. })
  217. // 身份认证上报订阅信息
  218. wx.aldPushSubscribeMessage({
  219. eventId: '5ea25ae37739104342928e96'
  220. });
  221. },
  222. onError(err) {
  223. app.aldstat.sendEvent('报错', {
  224. 'err': err
  225. });
  226. },
  227. })