register.ts 9.9 KB

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