Identity.js 3.4 KB

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