register.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. // pages/register/register.ts
  2. import { ConstsData } from "../../utils/const"
  3. import { httpUtil } from "../../utils/restful";
  4. import { storage } from "../../utils/storageUtil"
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. regionOne: Array<String>(),
  11. regionTwo: Array<String>(),
  12. regionThree: Array<String>(),
  13. regionOneIndex: 0,
  14. regionTwoIndex: 0,
  15. regionThreeIndex: 0,
  16. region: [
  17. Array<String>(),
  18. Array<String>(),
  19. Array<String>()
  20. ],
  21. regionIndex: [0, 0, 0],
  22. schoolArray: [['暂无学校']],
  23. schoolIndex: 0,
  24. classArray: ['暂无班级'],
  25. classIndex: 0,
  26. isShowPassWord: true,
  27. userName: '',
  28. userPhone: "",
  29. verificationCode: '',
  30. userPwd: '',
  31. provinceValue: '',//省份value
  32. regionValue: '',//地区value
  33. cityValue: '',
  34. schoolData: [{ 'id': '' }],
  35. schoolId: '',
  36. classData: [{ 'id': '' }],
  37. classId: '',
  38. hasGetVCode: false,
  39. getVCodeText: "获取验证码",
  40. getvcodeInter: -5,
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad() {
  46. this.changeOrganizeInfo();
  47. },
  48. changeOrganizeInfo: function () {
  49. //切换地区
  50. this.setData({
  51. regionOne: [],
  52. regionTwo: [],
  53. regionThree: []
  54. })
  55. ConstsData.AppData.organizeInfo.data.children.forEach((item) => {
  56. this.data.regionOne.push(item.title)
  57. })
  58. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item) => {
  59. this.data.regionTwo.push(item.title)
  60. })
  61. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item) => {
  62. this.data.regionThree.push(item.title)
  63. })
  64. this.setData({
  65. region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
  66. regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
  67. provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
  68. cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
  69. regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString()
  70. })
  71. //切换学校
  72. this.changeSchool();
  73. },
  74. //查询学校
  75. changeSchool: function () {
  76. //查询学校
  77. let params = {
  78. city: this.data.cityValue,
  79. province: this.data.provinceValue,
  80. region: this.data.regionValue,
  81. type: 1,
  82. }
  83. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  84. this.setData({
  85. schoolArray: [],
  86. schoolIndex: 0,
  87. schoolData: res.data.data,
  88. schoolId: res.data.data[0].id
  89. })
  90. let newArray: string[] = [];
  91. res.data.data.forEach((element: { title: string; }) => {
  92. newArray.push(element.title)
  93. });
  94. this.data.schoolArray.push(newArray)
  95. this.setData({
  96. schoolArray: this.data.schoolArray
  97. })
  98. //切换班级
  99. this.changeClass()
  100. }).catch(res => {
  101. console.log("查询学校error:", res)
  102. this.setData({
  103. schoolArray: [['暂无学校']],
  104. schoolId: '',
  105. classArray: ['暂无班级'],
  106. classId: ''
  107. })
  108. })
  109. },
  110. //查询班级
  111. changeClass: function () {
  112. let params = {
  113. "city": this.data.cityValue,
  114. "father": this.data.schoolId,//学校ID
  115. "province": this.data.provinceValue,
  116. "region": this.data.regionValue,
  117. "type": 2,
  118. }
  119. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  120. this.setData({
  121. classArray: [],
  122. classIndex: 0
  123. })
  124. this.setData({
  125. classData: res.data.data,
  126. classId: res.data.data[0].id
  127. })
  128. res.data.data.forEach((element: { title: string; }) => {
  129. this.data.classArray.push(element.title)
  130. });
  131. this.setData({
  132. classArray: this.data.classArray,
  133. })
  134. }).catch(res => {
  135. console.log("查询班级error:", res)
  136. this.setData({
  137. classArray: ['暂无班级'],
  138. classId: ''
  139. })
  140. })
  141. },
  142. bindMultiPickerColumnChange: function (event: any) {
  143. //
  144. switch (Number(event.detail.column)) {
  145. case 0:
  146. //代表第一列
  147. this.setData({
  148. regionOneIndex: event.detail.value,
  149. })
  150. break;
  151. case 1:
  152. //代表第二列
  153. this.setData({
  154. regionTwoIndex: event.detail.value,
  155. })
  156. break;
  157. case 2:
  158. //代表第三列
  159. this.setData({
  160. regionThreeIndex: event.detail.value
  161. })
  162. break;
  163. }
  164. this.changeOrganizeInfo();
  165. },
  166. bindRegionChange: function (event: any) {
  167. this.setData({
  168. regionIndex: event.detail.value
  169. })
  170. },
  171. bindSchoolPicker: function (event: any) {
  172. this.setData({
  173. schoolIndex: event.detail.value,
  174. schoolId: this.data.schoolData[event.detail.value].id
  175. })
  176. this.changeClass();
  177. },
  178. bindClssPicker: function (event: any) {
  179. this.setData({
  180. classIndex: event.detail.value,
  181. classId: this.data.classData[event.detail.value].id
  182. })
  183. console.log("班级ID:", this.data.classId)
  184. },
  185. showPwdTab: function () {
  186. if (this.data.isShowPassWord) {
  187. this.setData({
  188. isShowPassWord: false
  189. })
  190. } else {
  191. this.setData({
  192. isShowPassWord: true
  193. })
  194. }
  195. },
  196. exitPage: function () {
  197. wx.navigateBack()
  198. },
  199. //获取输入的姓名
  200. bindUserNameInput: function (event: any) {
  201. this.setData({
  202. userName: event.detail.value
  203. })
  204. },
  205. //获取输入的手机号
  206. bindUserPhoneInput: function (event: any) {
  207. this.setData({
  208. userPhone: event.detail.value
  209. })
  210. },
  211. //获取输入的验证码
  212. bindVerificationCodeInput: function (event: any) {
  213. this.setData({
  214. verificationCode: event.detail.value
  215. })
  216. },
  217. //获取输入的密码
  218. bindPwdInput: function (event: any) {
  219. this.setData({
  220. userPwd: event.detail.value
  221. })
  222. },
  223. //获取验证码
  224. getVerificationCode: function (event: any) {
  225. if (this.data.hasGetVCode) {
  226. this.showToast("请勿频繁点击")
  227. return;
  228. }
  229. if (!this.data.userPhone) {
  230. this.showToast("请输入手机号")
  231. return;
  232. }
  233. let that = this;
  234. let time = 60;
  235. this.data.getvcodeInter = setInterval(function () {
  236. if (time <= 1) {
  237. clearInterval(that.data.getvcodeInter)
  238. that.setData({
  239. hasGetVCode: false,
  240. getVCodeText: '获取验证码',
  241. getvcodeInter: -5
  242. })
  243. return;
  244. }
  245. time--;
  246. that.setData({
  247. getVCodeText: time.toString(),
  248. hasGetVCode: true
  249. })
  250. }, 1000)
  251. let params = {
  252. mobileNo: this.data.userPhone
  253. }
  254. httpUtil.wxGet(httpUtil.interfaces.getVerifyCode, params).then((res) => {
  255. console.log("获取验证码成功:", res)
  256. }).catch((res) => {
  257. console.log("获取验证码失败:", res)
  258. })
  259. },
  260. doRegister: function () {
  261. //注册
  262. if (!this.data.userName) {
  263. this.showToast("请输入姓名:")
  264. return;
  265. }
  266. if (!this.data.userPhone) {
  267. this.showToast("请输入手机号")
  268. return;
  269. }
  270. if (!this.data.userPwd) {
  271. this.showToast("请输入密码")
  272. return;
  273. }
  274. if (!this.data.verificationCode) {
  275. this.showToast("请输入验证码")
  276. return;
  277. }
  278. let params = {
  279. city: this.data.cityValue,
  280. classId: this.data.classId,
  281. mobile: this.data.userPhone,
  282. name: this.data.userName,
  283. password: this.data.userPwd,
  284. province: this.data.provinceValue,//省份
  285. region: this.data.regionValue,//地区
  286. schoolId: this.data.schoolId,
  287. userName: this.data.userPhone,//账号
  288. verifyCode: this.data.verificationCode//
  289. }
  290. httpUtil.wxPost(httpUtil.interfaces.phoneRegister, params).then((res: any) => {
  291. httpUtil.httpData.userId = res.data.data.id;
  292. ConstsData.AppData.myInfoData = res.data.data;
  293. console.log(" res.data.data:", res.data.data)
  294. storage.saveStorage(storage.storageKey.userId, res.data.data.id);
  295. wx.navigateTo({
  296. url: '../teacher/index/index',
  297. })
  298. }).catch((res) => {
  299. console.log("注册失败:", res)
  300. })
  301. },
  302. showToast: function (message: string) {
  303. wx.showToast({
  304. title: message,
  305. icon: 'none'
  306. })
  307. },
  308. onUnload() {
  309. if (this.data.getvcodeInter != -5) {
  310. clearInterval(this.data.getvcodeInter)
  311. }
  312. }
  313. })