finishInfo.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. // 百度身份证OCR接口 首先去后台获得token
  85. goOcr() {
  86. wx.request({
  87. url: app.globalData.publicUrl + '/applet/getToken',
  88. method: "GET",
  89. header: {
  90. appletsId: wx.getStorageSync('openId')
  91. },
  92. success: (res) => {
  93. console.log(res.data, "0000");
  94. if (res.data.data.status == 200) {
  95. let token = res.data.data.token;
  96. if (token) {
  97. wx.showLoading({
  98. title: '加载中',
  99. })
  100. var _this = this;
  101. wx.chooseImage({
  102. count: 1, // 默认9
  103. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  104. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  105. success: function (res) {
  106. wx.showLoading({
  107. title: '加载中',
  108. })
  109. // 拿文件转换base64
  110. wx.getFileSystemManager().readFile({
  111. filePath: res.tempFilePaths[0],
  112. encoding: 'base64',
  113. success: res1 => {
  114. //返回临时文件路径
  115. console.log('读取本地文件basema ', res1.data)
  116. let img = 'data:image/png;base64,' + res1.data
  117. wx.request({
  118. url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=' + token,
  119. method: 'POST',
  120. header: {
  121. 'content-type': 'application/x-www-form-urlencoded'
  122. },
  123. data: {
  124. id_card_side: 'front',
  125. image: img
  126. },
  127. dataType: 'json',
  128. success: (e) => {
  129. // 扫描后赋值
  130. if (e.data.idcard_number_type == 1) {
  131. let result = e.data.words_result
  132. console.log(result, "00000000");
  133. _this.data.parameter.forEach(item => {
  134. if (item.name == result['性别'].words) {
  135. item.checked = true;
  136. }
  137. })
  138. result['性别'].words,
  139. _this.setData({
  140. userName: result['姓名'].words,
  141. idCardNumber: result['公民身份号码'].words,
  142. parameter: _this.data.parameter,
  143. })
  144. } else {
  145. wx.showToast({
  146. title: "身份证OCR识别失败",
  147. icon: 'none',
  148. duration: 2000,
  149. })
  150. }
  151. },
  152. complete: (e) => {
  153. wx.hideLoading();
  154. }
  155. })
  156. },
  157. // 错误信息
  158. fail: console.error
  159. })
  160. },
  161. fail: function () {
  162. wx.hideLoading();
  163. }
  164. })
  165. } else {
  166. wx.showToast({
  167. title: '身份证识别失败,token失效',
  168. icon: 'none',
  169. duration: 2000,
  170. })
  171. }
  172. }
  173. },
  174. })
  175. },
  176. postListChange: function (e) {
  177. this.setData({
  178. postindex: e.detail.value,
  179. posttext: '',
  180. })
  181. },
  182. incomeListChange: function (e) {
  183. this.setData({
  184. incomeindex: e.detail.value,
  185. incometext: '',
  186. })
  187. },
  188. educationListChange: function (e) {
  189. this.setData({
  190. educationindex: e.detail.value,
  191. educationtext: '',
  192. })
  193. },
  194. initValidate() {
  195. const rules = {
  196. userName: {
  197. required: true,
  198. },
  199. sex: {
  200. required: true,
  201. },
  202. idCardNumber: {
  203. required: true,
  204. idcard: true,
  205. },
  206. age: {
  207. required: true,
  208. },
  209. job: {
  210. required: true,
  211. },
  212. income: {
  213. required: true,
  214. },
  215. education: {
  216. required: true,
  217. },
  218. };
  219. const messages = {
  220. userName: {
  221. required: '姓名不能为空',
  222. },
  223. sex: {
  224. required: '性别不能为空',
  225. },
  226. idCardNumber: {
  227. required: '身份证号不能为空',
  228. idcard: '身份证号格式错误 ',
  229. },
  230. age: {
  231. required: '年龄不能为空',
  232. },
  233. job: {
  234. required: '职务不能为空',
  235. },
  236. income: {
  237. required: '收入不能为空',
  238. },
  239. education: {
  240. required: '学历不能为空',
  241. },
  242. };
  243. // 创建实例对象
  244. this.WxValidate = new WxValidate(rules, messages)
  245. },
  246. showModal(error) {
  247. wx.showToast({
  248. title: error.msg,
  249. icon: 'none',
  250. duration: 2000,
  251. })
  252. },
  253. formSubmit(e) {
  254. console.log(e.detail, "daying");
  255. /***4-3(表单提交校验)*/
  256. const params = e.detail.value
  257. if (!this.WxValidate.checkForm(params)) {
  258. const error = this.WxValidate.errorList[0]
  259. this.showModal(error)
  260. return false
  261. }
  262. /*** 这里添写验证成功以后的逻辑**/
  263. //验证通过以后->
  264. this.submitInfo(params);
  265. },
  266. //修改信息接口
  267. submitInfo(params) {
  268. wx.request({
  269. url: app.globalData.publicUrl + '/applet/suppleUserInfo',
  270. method: "POST",
  271. data: params,
  272. header: {
  273. appletsId: wx.getStorageSync('openId')
  274. },
  275. success: (res) => {
  276. if (res.data.code == 0) {
  277. console.log(res, "0000");
  278. }
  279. }
  280. })
  281. },
  282. //获得当前登陆人的信息
  283. userInfo() {
  284. wx.request({
  285. url: app.globalData.publicUrl + '/sys/login/session',
  286. method: "GET",
  287. header: {
  288. appletsId: wx.getStorageSync('openId')
  289. },
  290. success: (res) => {
  291. console.log(res.data.data, "000");
  292. this.data.parameter.forEach(item => {
  293. if (item.name == res.data.data.sex) {
  294. item.checked = true;
  295. }
  296. })
  297. this.setData({
  298. userName: res.data.data.userName,
  299. parameter: this.data.parameter,
  300. idCardNumber: res.data.data.idCardNumber,
  301. age: res.data.data.age,
  302. posttext: res.data.data.job,
  303. incometext: res.data.data.income,
  304. educationtext: res.data.data.education,
  305. })
  306. }
  307. })
  308. },
  309. onLoad: function () {
  310. this.initValidate();
  311. this.userInfo();
  312. },
  313. })