Identity.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. showModal(error) {
  15. wx.showModal({
  16. content: error.msg,
  17. showCancel: false,
  18. })
  19. },
  20. tj(sessionKey, params) {
  21. wx.request({
  22. url: app.globalData.publicUrl2 + '/wx/student/uthentication',
  23. method: "post",
  24. data: {
  25. studentName: params.userName,
  26. studentCard: params.card,
  27. phone: params.phone,
  28. sessionKey: sessionKey
  29. },
  30. success: function (res) {
  31. if (res.data.code == 0) {
  32. wx.showModal({
  33. showCancel: false,
  34. content: res.data.msg,
  35. success(res) {
  36. if (res.confirm) {
  37. wx.switchTab({
  38. url: '../index/index'
  39. })
  40. }
  41. }
  42. })
  43. } else {
  44. wx.showModal({
  45. showCancel: false,
  46. content: res.data.msg,
  47. success(res) {
  48. // if (res.confirm) {}
  49. }
  50. })
  51. }
  52. }
  53. })
  54. },
  55. async formSubmit(e) {
  56. wx.showLoading({
  57. mask: true,
  58. title: '加载中',
  59. })
  60. let _this = this;
  61. if (_this.data.isRz == 0) {
  62. const params = e.detail.value
  63. if (!this.WxValidate.checkForm(params)) {
  64. const error = this.WxValidate.errorList[0]
  65. this.showModal(error)
  66. wx.hideLoading()
  67. return false
  68. }
  69. const sessionKey = await tools.checkSessionAndLogin();
  70. this.tj(sessionKey, params);
  71. // wx.checkSession({
  72. // success: () => {
  73. // console.log("我有缓存")
  74. // var sessionKey = wx.getStorageSync('sessionKey');
  75. // if (sessionKey == "") {
  76. // wx.login({
  77. // success(res) {
  78. // console.log(res);
  79. // var code = res.code
  80. // wx.request({
  81. // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  82. // method: "get",
  83. // data: {
  84. // code
  85. // },
  86. // success: function (res) {
  87. // sessionKey = res.data.sessionKey;
  88. // wx.setStorageSync('sessionKey', res.data.sessionKey);
  89. // _this.tj(sessionKey, params);
  90. // wx.hideLoading()
  91. // }
  92. // })
  93. // }
  94. // })
  95. // } else {
  96. // _this.tj(sessionKey, params);
  97. // wx.hideLoading()
  98. // }
  99. // },
  100. // fail() {
  101. // console.log("我没有缓存并去登录请求")
  102. // wx.login({
  103. // success(res) {
  104. // console.log(res);
  105. // var code = res.code
  106. // wx.request({
  107. // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  108. // method: "get",
  109. // data: {
  110. // code
  111. // },
  112. // success: function (res) {
  113. // wx.setStorageSync('sessionKey', res.data.sessionKey);
  114. // var sessionKey = res.data.sessionKey;
  115. // _this.tj(sessionKey, params);
  116. // wx.hideLoading()
  117. // }
  118. // })
  119. // }
  120. // })
  121. // }
  122. // })
  123. } else {
  124. wx.hideLoading()
  125. wx.showModal({
  126. showCancel: false,
  127. content: "您已经认证过了"
  128. })
  129. }
  130. },
  131. getXx(sessionKey) {
  132. let _this = this;
  133. wx.request({
  134. url: app.globalData.publicUrl2 + '/wx/student/selStudentSessionKeyEcho',
  135. method: "post",
  136. data: {
  137. sessionKey: sessionKey
  138. },
  139. success: function (res) {
  140. if (res.data.code == 0) {
  141. if (res.data.data !== null || res.data.data !== "") {
  142. _this.setData({
  143. isRz: 1,
  144. userName: res.data.data.miniName,
  145. phone: res.data.data.miniPhone,
  146. card: res.data.data.studentCard,
  147. isInput3: true
  148. })
  149. } else {
  150. console.log("我没认证,需要认证")
  151. }
  152. } else {
  153. console.log("报错额")
  154. }
  155. console.log(res)
  156. // sessionKey = res.data.sessionKey;
  157. // wx.setStorageSync('sessionKey', res.data.sessionKey);
  158. // _this.getXx(sessionKey);
  159. }
  160. })
  161. },
  162. async onLoad() {
  163. const sessionKey = await tools.checkSessionAndLogin();
  164. this.getXx(sessionKey);
  165. this.initValidate();
  166. // var _this = this;
  167. // wx.checkSession({
  168. // success: () => {
  169. // console.log("我有缓存")
  170. // var sessionKey = wx.getStorageSync('sessionKey');
  171. // if (sessionKey == "") {
  172. // wx.login({
  173. // success(res) {
  174. // console.log(res);
  175. // var code = res.code
  176. // wx.request({
  177. // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  178. // method: "get",
  179. // data: {
  180. // code
  181. // },
  182. // success: function (res) {
  183. // sessionKey = res.data.sessionKey;
  184. // wx.setStorageSync('sessionKey', res.data.sessionKey);
  185. // _this.getXx(sessionKey);
  186. // _this.initValidate();
  187. // }
  188. // })
  189. // }
  190. // })
  191. // } else {
  192. // _this.getXx(sessionKey);
  193. // _this.initValidate();
  194. // }
  195. // },
  196. // fail() {
  197. // console.log("我没有缓存并去登录请求")
  198. // wx.login({
  199. // success(res) {
  200. // console.log(res);
  201. // var code = res.code
  202. // wx.request({
  203. // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  204. // method: "get",
  205. // data: {
  206. // code
  207. // },
  208. // success: function (res) {
  209. // wx.setStorageSync('sessionKey', res.data.sessionKey);
  210. // var sessionKey = res.data.sessionKey
  211. // _this.getXx(sessionKey);
  212. // _this.initValidate();
  213. // }
  214. // })
  215. // }
  216. // })
  217. // }
  218. // })
  219. },
  220. // onLoad: function () {
  221. // this.initValidate();
  222. // wx.login({
  223. // success(res) {
  224. // console.log(res);
  225. // var code = res.code
  226. // wx.request({
  227. // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  228. // method: "get",
  229. // data: {
  230. // code
  231. // },
  232. // success: function (res) {
  233. // console.log(res,"我是测试")
  234. // // wx.setStorageSync('sessionKey', res.data.sessionKey);
  235. // // var sessionKey = res.data.sessionKey;
  236. // // _this.tj(sessionKey, params);
  237. // }
  238. // })
  239. // }
  240. // })
  241. // },
  242. initValidate() {
  243. // 验证字段的规则
  244. const rules = {
  245. userName: {
  246. required: true
  247. },
  248. phone: {
  249. required: true,
  250. tel: true,
  251. },
  252. card: {
  253. required: true,
  254. idcard: true,
  255. }
  256. }
  257. // 验证字段的提示信息,若不传则调用默认的信息
  258. const messages = {
  259. userName: {
  260. required: '请输入姓名'
  261. },
  262. phone: {
  263. required: '请输入手机号',
  264. tel: '请输入正确的手机号',
  265. },
  266. card: {
  267. required: '请输入身份证号码',
  268. idcard: '请输入正确的身份证号码',
  269. }
  270. }
  271. // 创建实例对象
  272. this.WxValidate = new WxValidate(rules, messages)
  273. }
  274. })