finishInfo.js 13 KB

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