register.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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: ['一年级一班', '一年级2班', '一年级3班', '一年级4班'],
  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. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad() {
  42. this.changeOrganizeInfo();
  43. },
  44. changeOrganizeInfo: function () {
  45. //切换地区
  46. this.setData({
  47. regionOne: [],
  48. regionTwo: [],
  49. regionThree: []
  50. })
  51. ConstsData.AppData.organizeInfo.data.children.forEach((item) => {
  52. this.data.regionOne.push(item.title)
  53. })
  54. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item) => {
  55. this.data.regionTwo.push(item.title)
  56. })
  57. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item) => {
  58. this.data.regionThree.push(item.title)
  59. })
  60. this.setData({
  61. region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
  62. regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
  63. provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
  64. cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
  65. regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString()
  66. })
  67. console.log("provinceValue", this.data.provinceValue)
  68. //切换学校
  69. this.changeSchool();
  70. //切换班级
  71. },
  72. //查询学校
  73. changeSchool: function () {
  74. console.log("查询学校")
  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. console.log(" res.data.data:", res.data.data[0].id)
  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. console.log("schoolId:", this.data.schoolId)
  99. this.changeClass()
  100. }).catch(res => {
  101. console.log("查询学校error:", res)
  102. })
  103. },
  104. //查询班级
  105. changeClass: function () {
  106. let params = {
  107. "city": this.data.cityValue,
  108. "father": this.data.schoolId,//学校ID
  109. "province": this.data.provinceValue,
  110. "region": this.data.regionValue,
  111. "type": 2,
  112. }
  113. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  114. this.setData({
  115. classArray: [],
  116. classIndex: 0
  117. })
  118. this.setData({
  119. classData: res.data.data,
  120. classId: res.data.data[0].id
  121. })
  122. res.data.data.forEach((element: { title: string; }) => {
  123. console.log("element:", element.title)
  124. this.data.classArray.push(element.title)
  125. });
  126. this.setData({
  127. classArray: this.data.classArray,
  128. })
  129. }).catch(res => {
  130. console.log("查询班级error:", res)
  131. })
  132. },
  133. bindMultiPickerColumnChange: function (event: any) {
  134. //
  135. switch (Number(event.detail.column)) {
  136. case 0:
  137. //代表第一列
  138. this.setData({
  139. regionOneIndex: event.detail.value,
  140. })
  141. break;
  142. case 1:
  143. //代表第二列
  144. this.setData({
  145. regionTwoIndex: event.detail.value,
  146. })
  147. break;
  148. case 2:
  149. //代表第三列
  150. this.setData({
  151. regionThreeIndex: event.detail.value
  152. })
  153. break;
  154. }
  155. this.changeOrganizeInfo();
  156. },
  157. bindRegionChange: function (event: any) {
  158. console.log('picker发送选择改变,携带值为', event.detail.value)
  159. this.setData({
  160. regionIndex: event.detail.value
  161. })
  162. },
  163. bindSchoolPicker: function (event: any) {
  164. console.log("event:", event.detail.value)
  165. console.log("schoolData:", this.data.schoolData[event.detail.value].id)
  166. this.setData({
  167. schoolIndex: event.detail.value,
  168. schoolId: this.data.schoolData[event.detail.value].id
  169. })
  170. this.changeClass();
  171. },
  172. bindClssPicker: function (event: any) {
  173. this.setData({
  174. classIndex: event.detail.value
  175. })
  176. },
  177. showPwdTab: function () {
  178. if (this.data.isShowPassWord) {
  179. this.setData({
  180. isShowPassWord: false
  181. })
  182. } else {
  183. this.setData({
  184. isShowPassWord: true
  185. })
  186. }
  187. },
  188. exitPage: function () {
  189. wx.navigateBack()
  190. },
  191. //获取输入的姓名
  192. bindUserNameInput: function (event: any) {
  193. console.log("event.detail.value:",)
  194. this.setData({
  195. userName: event.detail.value
  196. })
  197. },
  198. //获取输入的手机号
  199. bindUserPhoneInput: function (event: any) {
  200. this.setData({
  201. userPhone: event.detail.value
  202. })
  203. },
  204. //获取输入的验证码
  205. bindVerificationCodeInput: function (event: any) {
  206. this.setData({
  207. verificationCode: event.detail.value
  208. })
  209. },
  210. //获取输入的密码
  211. bindPwdInput: function (event: any) {
  212. this.setData({
  213. userPwd: event.detail.value
  214. })
  215. },
  216. //获取验证码
  217. getVerificationCode: function () {
  218. },
  219. doRegister: function () {
  220. //注册
  221. if (!this.data.userName) {
  222. this.showToast("请输入姓名:")
  223. return;
  224. }
  225. if (!this.data.userPhone) {
  226. this.showToast("请输入手机号")
  227. return;
  228. }
  229. if (!this.data.userPwd) {
  230. this.showToast("请输入密码")
  231. return;
  232. }
  233. if (!this.data.verificationCode) {
  234. this.showToast("请输入验证码")
  235. return;
  236. }
  237. let params = {
  238. city: this.data.cityValue,
  239. classId: this.data.classId,
  240. mobile: this.data.userPhone,
  241. name: this.data.userName,
  242. password: this.data.userPwd,
  243. province: this.data.provinceValue,//省份
  244. region: this.data.regionValue,//地区
  245. schoolId: this.data.schoolId,
  246. userName: this.data.userPhone,//账号
  247. verifyCode: this.data.verificationCode//
  248. }
  249. console.log("params:", params)
  250. httpUtil.wxPost(httpUtil.interfaces.phoneRegister, params).then((res: any) => {
  251. console.log("注册成功:", res.data)
  252. httpUtil.httpData.userId = res.data.data.id;
  253. wx.navigateTo({
  254. url: '../teacher/index/index',
  255. })
  256. }).catch((res) => {
  257. console.log("注册失败:", res)
  258. })
  259. },
  260. showToast: function (message: string) {
  261. wx.showToast({
  262. title: message,
  263. icon: 'none'
  264. })
  265. },
  266. })