finishInfo.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. const app = require('../../utils/util.js');
  2. var util = require('../../utils/md5.js')
  3. import WxValidate from '../../utils/WxValidate';
  4. Page({
  5. data: {
  6. postindex: null,
  7. incomeindex: null,
  8. educationindex: null,
  9. posttext: '请选择',
  10. incometext: '请选择',
  11. educationtext: '请选择',
  12. userName: '', //姓名
  13. idCardNumber: '', //身份证号码
  14. age: '', //年龄
  15. parameter: [{
  16. name: '男'
  17. }, {
  18. name: '女',
  19. }],
  20. postList: [{
  21. name: '在职人员'
  22. },
  23. {
  24. name: '两委人员'
  25. },
  26. {
  27. name: '社会组织人员'
  28. },
  29. {
  30. name: '志愿者'
  31. },
  32. {
  33. name: '学生'
  34. },
  35. {
  36. name: '其他'
  37. },
  38. ],
  39. incomeList: [{
  40. name: '暂无'
  41. },
  42. {
  43. name: '500元以下'
  44. },
  45. {
  46. name: '500-1000元'
  47. },
  48. {
  49. name: '1000-2000元'
  50. },
  51. {
  52. name: '2000-5000元'
  53. },
  54. {
  55. name: '5000元-1万元'
  56. },
  57. {
  58. name: '1-2万元'
  59. },
  60. {
  61. name: '2万元以上'
  62. },
  63. ],
  64. educationList: [{
  65. name: '小学'
  66. },
  67. {
  68. name: '初中'
  69. },
  70. {
  71. name: '高中'
  72. },
  73. {
  74. name: '大专'
  75. },
  76. {
  77. name: '本科'
  78. },
  79. {
  80. name: '本科以上'
  81. },
  82. ],
  83. },
  84. uploadIdcard() {
  85. wx.showLoading({
  86. title: '加载中',
  87. })
  88. wx.chooseImage({
  89. count: 1,
  90. sizeType: ['compressed'],
  91. sourceType: ['camera'],
  92. success: (res) => {
  93. console.log(res, '图片的临时路径')
  94. let tempFilePaths = res.tempFilePaths[0]
  95. this.goOcr(tempFilePaths)
  96. },
  97. fail: () => {
  98. wx.hideLoading();
  99. }
  100. })
  101. },
  102. uploadIdimg() {
  103. wx.showLoading({
  104. title: '加载中',
  105. })
  106. wx.chooseImage({
  107. count: 1,
  108. sizeType: ['compressed'],
  109. sourceType: ['camera'],
  110. success: (res) => {
  111. console.log(res, '图片的临时路径')
  112. let tempFilePaths = res.tempFilePaths[0]
  113. wx.uploadFile({
  114. url: app.globalData.publicUrl + '/sys/user/upload',
  115. filePath: tempFilePaths,
  116. name: 'uploadFile',
  117. formData: {
  118. "user": "test",
  119. },
  120. header: {
  121. appletsId: wx.getStorageSync('openId'),
  122. },
  123. success: (res) => {
  124. console.log(res)
  125. let datas = JSON.parse(res.data)
  126. console.log(datas.data)
  127. this.goFace(datas.data)
  128. }
  129. })
  130. },
  131. fail: (e) => {
  132. wx.hideLoading();
  133. }
  134. })
  135. },
  136. goFace(file) {
  137. wx.request({
  138. url: app.globalData.publicUrl + '/user/getPeople',
  139. method: "POST",
  140. header: {
  141. appletsId: wx.getStorageSync('openId')
  142. },
  143. data: {
  144. photoPath: file
  145. },
  146. success: (res) => {
  147. wx.hideLoading();
  148. console.log(res, '有没有face')
  149. if (res.data.code == 0) {
  150. this.setData({
  151. myPhoto: file
  152. })
  153. } else {
  154. wx.showToast({
  155. title: '面部识别不通过,请重新上传',
  156. icon: 'none',
  157. duration: 3000,
  158. })
  159. }
  160. },
  161. fail: () => {
  162. wx.hideLoading();
  163. }
  164. })
  165. },
  166. // 百度身份证OCR接口 首先去后台获得token
  167. goOcr(file) {
  168. wx.request({
  169. url: app.globalData.publicUrl + '/applet/getToken',
  170. method: "GET",
  171. header: {
  172. appletsId: wx.getStorageSync('openId')
  173. },
  174. success: (res) => {
  175. wx.hideLoading();
  176. if (res.data.data.status == 200) {
  177. let token = res.data.data.token;
  178. if (token) {
  179. var _this = this;
  180. wx.getFileSystemManager().readFile({
  181. filePath: file,
  182. encoding: 'base64',
  183. success: res1 => {
  184. console.log('读取本地文件basema ', res1)
  185. let img = 'data:image/png;base64,' + res1.data
  186. wx.request({
  187. url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=' + token,
  188. method: 'POST',
  189. header: {
  190. 'content-type': 'application/x-www-form-urlencoded'
  191. },
  192. data: {
  193. id_card_side: 'front',
  194. image: img
  195. },
  196. dataType: 'json',
  197. success: (e) => {
  198. // 扫描后赋值
  199. if (e.data.idcard_number_type == 1) {
  200. let result = e.data.words_result
  201. console.log(result, "00000000");
  202. _this.data.parameter.forEach(item => {
  203. if (item.name == result['性别'].words) {
  204. item.checked = true;
  205. }
  206. })
  207. var myDate = new Date();
  208. var tYear = myDate.getFullYear();
  209. let aa = parseInt(result['公民身份号码'].words.slice(6, 10));
  210. // _this.data.userName
  211. if (_this.data.userName == result['姓名'].words) {
  212. _this.setData({
  213. userName: result['姓名'].words,
  214. idCardNumber: result['公民身份号码'].words,
  215. parameter: _this.data.parameter,
  216. age: tYear - aa
  217. })
  218. // wx.uploadFile({
  219. // url: app.globalData.publicUrl + '/sys/user/upload',
  220. // filePath: file,
  221. // name: 'uploadFile',
  222. // formData: {
  223. // "user": "test",
  224. // },
  225. // header: {
  226. // appletsId: wx.getStorageSync('openId'),
  227. // },
  228. // success: (res) => {
  229. // console.log(res)
  230. // let datas = JSON.parse(res.data)
  231. // console.log(datas.data)
  232. // this.setData({
  233. // idPhoto: datas.data
  234. // })
  235. // // this.goOcr(datas.data)
  236. // }
  237. // })
  238. } else {
  239. wx.showModal({
  240. showCancel: false,
  241. content: '证件信息与后台登记姓名不一致'
  242. })
  243. }
  244. } else {
  245. wx.showToast({
  246. title: "身份证OCR识别失败",
  247. icon: 'none',
  248. duration: 2000,
  249. })
  250. }
  251. },
  252. // complete: (e) => {
  253. // wx.hideLoading();
  254. // }
  255. })
  256. },
  257. // 错误信息
  258. fail: console.error
  259. })
  260. } else {
  261. // wx.hideLoading();
  262. wx.showToast({
  263. title: '身份证识别失败,token失效',
  264. icon: 'none',
  265. duration: 2000,
  266. })
  267. }
  268. } else {
  269. wx.hideLoading()
  270. }
  271. },
  272. fail: () => {
  273. wx.hideLoading();
  274. }
  275. })
  276. },
  277. postListChange: function (e) {
  278. this.setData({
  279. postindex: e.detail.value,
  280. posttext: '',
  281. })
  282. },
  283. changeIdCard(e) {
  284. console.log(e.detail.value, "121212");
  285. var myDate = new Date();
  286. var tYear = myDate.getFullYear();
  287. let aa = parseInt(e.detail.value.slice(6, 10));
  288. console.log(aa);
  289. this.setData({
  290. age: tYear - aa
  291. })
  292. },
  293. incomeListChange: function (e) {
  294. this.setData({
  295. incomeindex: e.detail.value,
  296. incometext: '',
  297. })
  298. },
  299. educationListChange: function (e) {
  300. this.setData({
  301. educationindex: e.detail.value,
  302. educationtext: '',
  303. })
  304. },
  305. initValidate() {
  306. const rules = {
  307. userName: {
  308. required: true,
  309. },
  310. sex: {
  311. required: true,
  312. },
  313. idCardNumber: {
  314. required: true,
  315. idcard: true,
  316. },
  317. age: {
  318. required: true,
  319. },
  320. job: {
  321. required: true,
  322. },
  323. income: {
  324. required: true,
  325. },
  326. education: {
  327. required: true,
  328. },
  329. // idCardPicPath: {
  330. // required: true,
  331. // },
  332. // headPicPath: {
  333. // required: true,
  334. // }
  335. };
  336. const messages = {
  337. userName: {
  338. required: '请输入您的姓名',
  339. },
  340. sex: {
  341. required: '请输入您的性别',
  342. },
  343. idCardNumber: {
  344. required: '请输入您的身份证号',
  345. idcard: '身份证号格式错误 ',
  346. },
  347. age: {
  348. required: '请输入您的年龄',
  349. },
  350. job: {
  351. required: '请输入您的职务',
  352. },
  353. income: {
  354. required: '请输入您的收入',
  355. },
  356. education: {
  357. required: '请输入您的学历',
  358. },
  359. // idCardPicPath: {
  360. // required: '请上传您的身份证照片',
  361. // },
  362. // headPicPath: {
  363. // required: '请上传您本人的照片',
  364. // },
  365. };
  366. // 创建实例对象
  367. this.WxValidate = new WxValidate(rules, messages)
  368. },
  369. showModal(error) {
  370. wx.showToast({
  371. title: error.msg,
  372. icon: 'none',
  373. duration: 2000,
  374. })
  375. },
  376. formSubmit(e) {
  377. // console.log(e.detail, "表单的内容");
  378. /***4-3(表单提交校验)*/
  379. const params = e.detail.value
  380. // params.idCardPicPath = this.data.idPhoto
  381. // params.headPicPath = this.data.myPhoto
  382. // params.IsPerfect = '1'
  383. console.log(params, '表单的内容')
  384. if (!this.WxValidate.checkForm(params)) {
  385. const error = this.WxValidate.errorList[0]
  386. this.showModal(error)
  387. return false
  388. }
  389. /*** 这里添写验证成功以后的逻辑**/
  390. //验证通过以后->
  391. this.submitInfo(params);
  392. },
  393. //修改信息接口
  394. submitInfo(params) {
  395. wx.request({
  396. url: app.globalData.publicUrl + '/applet/suppleUserInfo',
  397. method: "POST",
  398. data: params,
  399. header: {
  400. appletsId: wx.getStorageSync('openId')
  401. },
  402. success: (res) => {
  403. if (res.data.code == 0) {
  404. console.log(res, "0000");
  405. wx.showModal({
  406. showCancel: false,
  407. content: '提交成功',
  408. success() {
  409. // wx.switchTab({
  410. // url: '/pages/index/index',
  411. // })
  412. wx.reLaunch({
  413. url: '/pages/faceRecognition/faceRecognition',
  414. })
  415. }
  416. })
  417. }
  418. }
  419. })
  420. },
  421. //获得当前登陆人的信息
  422. userInfo() {
  423. wx.request({
  424. url: app.globalData.publicUrl + '/applet/findUserInfo',
  425. method: "GET",
  426. header: {
  427. appletsId: wx.getStorageSync('openId')
  428. },
  429. success: (res) => {
  430. console.log(res.data.data, "000");
  431. this.data.parameter.forEach(item => {
  432. if (item.name == res.data.data.sex) {
  433. item.checked = true;
  434. }
  435. })
  436. //赋值问题
  437. let jonIndex = this.data.postList.findIndex(item => {
  438. return item.name == res.data.data.job
  439. })
  440. if (jonIndex != -1) {
  441. this.setData({
  442. posttext: '',
  443. postindex: jonIndex,
  444. })
  445. } else {
  446. this.setData({
  447. posttext: '请选择',
  448. })
  449. }
  450. let incomeindex = this.data.incomeList.findIndex(item => {
  451. return item.name == res.data.data.income
  452. })
  453. if (incomeindex != -1) {
  454. this.setData({
  455. incometext: '',
  456. incomeindex: incomeindex,
  457. })
  458. } else {
  459. this.setData({
  460. incometext: '请选择',
  461. })
  462. }
  463. let educationindex = this.data.educationList.findIndex(item => {
  464. return item.name == res.data.data.education
  465. })
  466. if (educationindex != -1) {
  467. this.setData({
  468. educationtext: '',
  469. educationindex: educationindex,
  470. })
  471. } else {
  472. this.setData({
  473. educationtext: '请选择',
  474. })
  475. }
  476. this.setData({
  477. userName: res.data.data.userName,
  478. parameter: this.data.parameter,
  479. idCardNumber: res.data.data.idCardNumber,
  480. age: res.data.data.age,
  481. // posttext: res.data.data.job,
  482. // incometext: res.data.data.income,
  483. // educationtext: res.data.data.education,
  484. })
  485. console.log(this.data.postList, "赋值上了么");
  486. }
  487. })
  488. },
  489. onLoad: function () {
  490. this.initValidate();
  491. this.userInfo();
  492. },
  493. })