finishInfo.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. // params.idCardPicPath = this.data.idPhoto
  336. // params.headPicPath = this.data.myPhoto
  337. };
  338. const messages = {
  339. userName: {
  340. required: '请输入您的姓名',
  341. },
  342. sex: {
  343. required: '请输入您的性别',
  344. },
  345. idCardNumber: {
  346. required: '请输入您的身份证号',
  347. idcard: '身份证号格式错误 ',
  348. },
  349. age: {
  350. required: '请输入您的年龄',
  351. },
  352. job: {
  353. required: '请输入您的职务',
  354. },
  355. income: {
  356. required: '请输入您的收入',
  357. },
  358. education: {
  359. required: '请输入您的学历',
  360. },
  361. idCardPicPath: {
  362. required: '请上传您的身份证照片',
  363. },
  364. headPicPath: {
  365. required: '请上传您本人的照片',
  366. },
  367. };
  368. // 创建实例对象
  369. this.WxValidate = new WxValidate(rules, messages)
  370. },
  371. showModal(error) {
  372. wx.showToast({
  373. title: error.msg,
  374. icon: 'none',
  375. duration: 2000,
  376. })
  377. },
  378. formSubmit(e) {
  379. // console.log(e.detail, "表单的内容");
  380. /***4-3(表单提交校验)*/
  381. const params = e.detail.value
  382. params.idCardPicPath = this.data.idPhoto
  383. params.headPicPath = this.data.myPhoto
  384. params.IsPerfect = '1'
  385. console.log(params, '表单的内容')
  386. if (!this.WxValidate.checkForm(params)) {
  387. const error = this.WxValidate.errorList[0]
  388. this.showModal(error)
  389. return false
  390. }
  391. /*** 这里添写验证成功以后的逻辑**/
  392. //验证通过以后->
  393. this.submitInfo(params);
  394. },
  395. //修改信息接口
  396. submitInfo(params) {
  397. wx.request({
  398. url: app.globalData.publicUrl + '/applet/suppleUserInfo',
  399. method: "POST",
  400. data: params,
  401. header: {
  402. appletsId: wx.getStorageSync('openId')
  403. },
  404. success: (res) => {
  405. if (res.data.code == 0) {
  406. console.log(res, "0000");
  407. wx.showModal({
  408. showCancel: false,
  409. content: '提交成功',
  410. success() {
  411. // wx.switchTab({
  412. // url: '/pages/index/index',
  413. // })
  414. wx.reLaunch({
  415. url: '/pages/faceRecognition/faceRecognition',
  416. })
  417. }
  418. })
  419. }
  420. }
  421. })
  422. },
  423. //获得当前登陆人的信息
  424. userInfo() {
  425. wx.request({
  426. url: app.globalData.publicUrl + '/applet/findUserInfo',
  427. method: "GET",
  428. header: {
  429. appletsId: wx.getStorageSync('openId')
  430. },
  431. success: (res) => {
  432. console.log(res.data.data, "000");
  433. this.data.parameter.forEach(item => {
  434. if (item.name == res.data.data.sex) {
  435. item.checked = true;
  436. }
  437. })
  438. //赋值问题
  439. let jonIndex = this.data.postList.findIndex(item => {
  440. return item.name == res.data.data.job
  441. })
  442. if (jonIndex != -1) {
  443. this.setData({
  444. posttext: '',
  445. postindex: jonIndex,
  446. })
  447. } else {
  448. this.setData({
  449. posttext: '请选择',
  450. })
  451. }
  452. let incomeindex = this.data.incomeList.findIndex(item => {
  453. return item.name == res.data.data.income
  454. })
  455. if (incomeindex != -1) {
  456. this.setData({
  457. incometext: '',
  458. incomeindex: incomeindex,
  459. })
  460. } else {
  461. this.setData({
  462. incometext: '请选择',
  463. })
  464. }
  465. let educationindex = this.data.educationList.findIndex(item => {
  466. return item.name == res.data.data.education
  467. })
  468. if (educationindex != -1) {
  469. this.setData({
  470. educationtext: '',
  471. educationindex: educationindex,
  472. })
  473. } else {
  474. this.setData({
  475. educationtext: '请选择',
  476. })
  477. }
  478. this.setData({
  479. userName: res.data.data.userName,
  480. parameter: this.data.parameter,
  481. idCardNumber: res.data.data.idCardNumber,
  482. age: res.data.data.age,
  483. // posttext: res.data.data.job,
  484. // incometext: res.data.data.income,
  485. // educationtext: res.data.data.education,
  486. })
  487. console.log(this.data.postList, "赋值上了么");
  488. }
  489. })
  490. },
  491. onLoad: function () {
  492. this.initValidate();
  493. this.userInfo();
  494. },
  495. })