Identitycopy.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. import WxValidate from '../../utils/WxValidate';
  4. const COS = require('../../utils/cos.js');
  5. Page({
  6. data: {
  7. isRz: 0,
  8. userName: "",
  9. phone: "",
  10. card: "",
  11. isInput1: false,
  12. isInput2: false,
  13. isInput3: false,
  14. carWin_img: '', //存放照片路径的
  15. cosPath: "" //腾讯云上传的路径
  16. },
  17. // 错误信息回显
  18. showModal(error) {
  19. wx.showModal({
  20. content: error.msg,
  21. showCancel: false,
  22. })
  23. },
  24. openCamera() {
  25. wx.chooseImage({
  26. count: 1,
  27. sizeType: ['original', 'compressed'],
  28. sourceType: ['', 'camera'],
  29. success:(res)=> {
  30. console.log(res)
  31. let path = res.tempFilePaths[0];
  32. // tempFilePath可以作为img标签的src属性显示图片
  33. console.log(path)
  34. this.setData({
  35. carWin_img: path
  36. })
  37. }
  38. })
  39. },
  40. // 提交
  41. tj(sessionKey, params) {
  42. wx.request({
  43. url: app.globalData.publicUrl + '/wx/student/uthentication',
  44. method: "post",
  45. data: {
  46. studentName: params.userName,
  47. studentCard: params.card,
  48. phone: params.phone,
  49. sessionKey: sessionKey
  50. },
  51. success: function (res) {
  52. wx.hideLoading()
  53. if (res.data.code == 0) {
  54. wx.showModal({
  55. showCancel: false,
  56. content: "提交成功啦",
  57. success(res) {
  58. if (res.confirm) {
  59. wx.switchTab({
  60. url: '../index/index'
  61. })
  62. }
  63. }
  64. })
  65. } else {
  66. wx.showModal({
  67. showCancel: false,
  68. content: res.data.msg
  69. })
  70. }
  71. }
  72. })
  73. },
  74. // 表单提交 跳转tj()
  75. async formSubmit(e) {
  76. wx.showLoading({
  77. mask: true,
  78. title: '加载中',
  79. })
  80. if (this.data.isRz == 0) {
  81. const params = e.detail.value
  82. if (!this.WxValidate.checkForm(params)) {
  83. const error = this.WxValidate.errorList[0]
  84. this.showModal(error)
  85. wx.hideLoading()
  86. return false
  87. }
  88. const sessionKey = await tools.checkSessionAndLogin();
  89. this.tj(sessionKey, params);
  90. } else {
  91. wx.hideLoading()
  92. wx.showModal({
  93. showCancel: false,
  94. content: "您已经认证过了"
  95. })
  96. }
  97. },
  98. // 如果有就把信息回显出来
  99. getInformation(sessionKey) {
  100. // let _this = this;
  101. wx.request({
  102. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKeyEcho',
  103. method: "post",
  104. data: {
  105. sessionKey: sessionKey
  106. },
  107. success: (res) => {
  108. if (res.data.code == 0) {
  109. if (res.data.data !== null || res.data.data !== "") {
  110. this.setData({
  111. isRz: 1,
  112. userName: res.data.data.miniName,
  113. phone: res.data.data.miniPhone,
  114. card: res.data.data.studentCard,
  115. isInput3: true
  116. })
  117. }
  118. }
  119. }
  120. })
  121. },
  122. async onLoad() {
  123. const sessionKey = await tools.checkSessionAndLogin();
  124. this.getInformation(sessionKey);
  125. this.initValidate();
  126. },
  127. // 验证字段的规则
  128. initValidate() {
  129. const rules = {
  130. userName: {
  131. required: true
  132. },
  133. phone: {
  134. required: true,
  135. tel: true,
  136. },
  137. card: {
  138. required: true,
  139. idcard: true,
  140. }
  141. }
  142. // 验证字段的提示信息,若不传则调用默认的信息
  143. const messages = {
  144. userName: {
  145. required: '请输入姓名'
  146. },
  147. phone: {
  148. required: '请输入手机号',
  149. tel: '请输入正确的手机号',
  150. },
  151. card: {
  152. required: '请输入身份证号码',
  153. idcard: '请输入正确的身份证号码',
  154. }
  155. }
  156. // 创建实例对象
  157. this.WxValidate = new WxValidate(rules, messages)
  158. }
  159. })