finishInfo.js 7.8 KB

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