Identity.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. const app = require('../../utils/util.js');
  2. import WxValidate from '../../utils/WxValidate';
  3. const tools = require('../../utils/tools.js');
  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. if (res.data.code == 0) {
  34. wx.showModal({
  35. showCancel: false,
  36. content: res.data.msg,
  37. success(res) {
  38. if (res.confirm) {
  39. wx.switchTab({
  40. url: '../index/index'
  41. })
  42. }
  43. }
  44. })
  45. } else {
  46. wx.showModal({
  47. showCancel: false,
  48. content: res.data.msg
  49. })
  50. }
  51. }
  52. })
  53. },
  54. // 表单提交 跳转tj()
  55. async formSubmit(e) {
  56. wx.showLoading({
  57. mask: true,
  58. title: '加载中',
  59. })
  60. // let _this = this;
  61. if (this.data.isRz == 0) {
  62. wx.hideLoading()
  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. getXx(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. } else {
  100. console.log("我没认证,需要认证")
  101. }
  102. } else {
  103. console.log("报错额")
  104. }
  105. console.log(res)
  106. }
  107. })
  108. },
  109. async onLoad() {
  110. const sessionKey = await tools.checkSessionAndLogin();
  111. this.getXx(sessionKey);
  112. this.initValidate();
  113. },
  114. // 验证字段的规则
  115. initValidate() {
  116. const rules = {
  117. userName: {
  118. required: true
  119. },
  120. phone: {
  121. required: true,
  122. tel: true,
  123. },
  124. card: {
  125. required: true,
  126. idcard: true,
  127. }
  128. }
  129. // 验证字段的提示信息,若不传则调用默认的信息
  130. const messages = {
  131. userName: {
  132. required: '请输入姓名'
  133. },
  134. phone: {
  135. required: '请输入手机号',
  136. tel: '请输入正确的手机号',
  137. },
  138. card: {
  139. required: '请输入身份证号码',
  140. idcard: '请输入正确的身份证号码',
  141. }
  142. }
  143. // 创建实例对象
  144. this.WxValidate = new WxValidate(rules, messages)
  145. }
  146. })