teachAuthentication.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. // pages/teachAuthentication/teachAuthentication.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. phoneNum: '', //电话号码
  8. weChatNum: '', //微信号码
  9. englishName: '', //英文名称
  10. nameFirst: '', //老师的姓
  11. nameLast: '', //老师的名字
  12. idNum: '', //身份证号
  13. sex: '', //性别,根据输入的身份证号自动判断
  14. idImgFontPath: '', //身份证正面照片的地址
  15. idImgBackPath: '', //身份证背面照片的地址
  16. diplomaPath:'', //毕业证书照片的地址
  17. stuCardPath:'', //学生证照片的地址
  18. headImgPath:'', //头像照片的地址
  19. chosedTeachAttr: '', //老师的身份
  20. showIdAttr: false, //老师的身份选项是否展示
  21. shcool: '', //毕业后就读的学校
  22. major: '', //所学专业
  23. chosedEducation: '', //学历
  24. showEdu: false, //学历的选项是否展示
  25. province: '', //籍贯的省份
  26. city: '', //籍贯的城市
  27. county: '', //籍贯的区县
  28. // 老师身份列表
  29. attributeList: [{
  30. 'attr': '专职老师',
  31. chosed: false
  32. },
  33. {
  34. 'attr': '在校大学生',
  35. chosed: false
  36. }
  37. ],
  38. // 学历列表
  39. educationList: [{
  40. 'edu': '博士毕业',
  41. chosed: false
  42. },
  43. {
  44. 'edu': '博士在读',
  45. chosed: false
  46. },
  47. {
  48. 'edu': '硕士毕业',
  49. chosed: false
  50. },
  51. {
  52. 'edu': '硕士在读',
  53. chosed: false
  54. },
  55. {
  56. 'edu': '本科毕业',
  57. chosed: false
  58. },
  59. {
  60. 'edu': '本科在读',
  61. chosed: false
  62. },
  63. {
  64. 'edu': '专科毕业',
  65. chosed: false
  66. },
  67. {
  68. 'edu': '专科在读',
  69. chosed: false
  70. }
  71. ]
  72. },
  73. /**
  74. * 生命周期函数--监听页面加载
  75. */
  76. onLoad(options) {
  77. },
  78. // 获取输入的电话号码
  79. getPhoneNum(e) {
  80. this.setData({
  81. phoneNum: e.detail.value
  82. })
  83. },
  84. //获取微信号
  85. getWeChatNum(e) {
  86. this.setData({
  87. weChatNum: e.detail.value
  88. })
  89. },
  90. // 获取英文名称
  91. getEnglishName(e) {
  92. this.setData({
  93. englishName: e.detail.value
  94. })
  95. },
  96. //获取用户输入的姓
  97. getNameFirst(e) {
  98. this.setData({
  99. nameFirst: e.detail.value
  100. })
  101. },
  102. //获取用户输入的名字
  103. getNameLast(e) {
  104. this.setData({
  105. nameLast: e.detail.value
  106. })
  107. },
  108. // 获取输入的身份证号
  109. getIdInput(e) {
  110. // console.log(e.detail.value)
  111. this.setData({
  112. idNum: e.detail.value
  113. })
  114. let idNumber = this.data.idNum
  115. let idLength = this.data.idNum.length
  116. // console.log('idLength:' + idLength)
  117. // console.log(idNumber.charAt(16))
  118. // 判断性别
  119. if (idLength < 18) {
  120. this.setData({
  121. sex: ''
  122. })
  123. return
  124. }
  125. if (idNumber.charAt(16) % 2 == 0) {
  126. this.setData({
  127. sex: '女'
  128. })
  129. } else {
  130. this.setData({
  131. sex: '男'
  132. })
  133. }
  134. // console.log(this.data.sex)
  135. },
  136. // 选择身份证的正面照片
  137. chooseIdFront() {
  138. let that = this
  139. wx.chooseMedia({
  140. count: 1,
  141. mediaType: ['image'],
  142. sourceType: ['album', 'camera'],
  143. sizeType:['compressed'],
  144. success(res) {
  145. // console.log(res.tempFiles[0].tempFilePath)
  146. console.log(res.tempFiles[0].size)
  147. that.setData({
  148. idImgFontPath: res.tempFiles[0].tempFilePath
  149. })
  150. }
  151. })
  152. },
  153. // 选择身份证的背面照片
  154. chooseIdBack() {
  155. let that = this
  156. wx.chooseMedia({
  157. count: 1,
  158. mediaType: ['image'],
  159. sourceType: ['album', 'camera'],
  160. // sizeType:['compressed'],
  161. success(res) {
  162. // console.log(res.tempFiles[0].tempFilePath)
  163. console.log(res.tempFiles[0].size)
  164. that.setData({
  165. idImgBackPath: res.tempFiles[0].tempFilePath
  166. })
  167. }
  168. })
  169. },
  170. // 选择毕业证
  171. chooseDiploma(){
  172. let that = this
  173. wx.chooseMedia({
  174. count: 1,
  175. mediaType: ['image'],
  176. sourceType: ['album', 'camera'],
  177. // sizeType:['compressed'],
  178. success(res) {
  179. // console.log(res.tempFiles[0].tempFilePath)
  180. console.log(res.tempFiles[0].size)
  181. that.setData({
  182. diplomaPath: res.tempFiles[0].tempFilePath
  183. })
  184. }
  185. })
  186. },
  187. // 选择学生证
  188. chooseStuCard(){
  189. let that = this
  190. wx.chooseMedia({
  191. count: 1,
  192. mediaType: ['image'],
  193. sourceType: ['album', 'camera'],
  194. // sizeType:['compressed'],
  195. success(res) {
  196. // console.log(res.tempFiles[0].tempFilePath)
  197. console.log(res.tempFiles[0].size)
  198. that.setData({
  199. stuCardPath: res.tempFiles[0].tempFilePath
  200. })
  201. }
  202. })
  203. },
  204. // 选择头像
  205. chooseHeadImg(){
  206. let that = this
  207. wx.chooseMedia({
  208. count: 1,
  209. mediaType: ['image'],
  210. sourceType: ['album', 'camera'],
  211. // sizeType:['compressed'],
  212. success(res) {
  213. // console.log(res.tempFiles[0].tempFilePath)
  214. console.log(res.tempFiles[0].size)
  215. that.setData({
  216. headImgPath: res.tempFiles[0].tempFilePath
  217. })
  218. }
  219. })
  220. },
  221. // 选择老师身份属性
  222. chooseTeachAttr() {
  223. this.setData({
  224. showIdAttr: true
  225. })
  226. },
  227. //老师身份选择
  228. onidAttrSelect(e) {
  229. // console.log(e)
  230. let index = e.currentTarget.dataset.index
  231. let attributeList = this.data.attributeList
  232. for (let i = 0; i < attributeList.length; i++) {
  233. if (i == index) {
  234. attributeList[i].chosed = !attributeList[i].chosed;
  235. } else {
  236. attributeList[i].chosed = false
  237. }
  238. }
  239. this.setData({
  240. attributeList
  241. })
  242. },
  243. // 定义一个退出选项的方法
  244. // 退出老师身份选项的方法
  245. hiddenTeachId() {
  246. this.setData({
  247. showIdAttr: false
  248. })
  249. },
  250. // 退出学历选项的方法
  251. hiddenEdu() {
  252. this.setData({
  253. showEdu: false
  254. })
  255. },
  256. // 老师身份选择确定
  257. confirmTeachId() {
  258. let attributeList = this.data.attributeList
  259. // let index
  260. // for(let i = 0;i < attributeList.length;i++){
  261. // if(attributeList.chosed){
  262. // index = i
  263. // }
  264. // }
  265. // let chosedTeachAttr = attributeList[index].attr
  266. let chosedTeachAttr = attributeList[attributeList.findIndex(item => item.chosed)]?.attr || ''
  267. this.setData({
  268. chosedTeachAttr
  269. })
  270. this.hiddenTeachId()
  271. },
  272. // 学历选择区
  273. chooseEducation() {
  274. this.setData({
  275. showEdu: true
  276. })
  277. },
  278. // 学历选择
  279. onEduSelect(e) {
  280. // console.log(e)
  281. let index = e.currentTarget.dataset.index
  282. let educationList = this.data.educationList
  283. for (let i = 0; i < educationList.length; i++) {
  284. if (i == index) {
  285. educationList[i].chosed = !educationList[i].chosed;
  286. } else {
  287. educationList[i].chosed = false
  288. }
  289. }
  290. this.setData({
  291. educationList
  292. })
  293. },
  294. // 学历选择确定
  295. confirmEdu() {
  296. let educationList = this.data.educationList
  297. let chosedEducation = educationList[educationList.findIndex(item => item.chosed)]?.edu || ''
  298. this.setData({
  299. chosedEducation
  300. })
  301. this.hiddenEdu()
  302. },
  303. // 获取输入的学校名称
  304. getSchool(e) {
  305. this.setData({
  306. school: e.detail.value
  307. })
  308. },
  309. // 获取输入的专业
  310. getMajor(e) {
  311. this.setData({
  312. major: e.detail.value
  313. })
  314. },
  315. // 获取输入的省份
  316. getProvince(e) {
  317. this.setData({
  318. province: e.detail.value
  319. })
  320. },
  321. // 获取输入的地市信息
  322. getCity(e) {
  323. this.setData({
  324. city: e.detail.value
  325. })
  326. },
  327. // 获取输入的区县信息
  328. getCounty(e) {
  329. this.setData({
  330. county: e.detail.value
  331. })
  332. },
  333. //提交审核
  334. toSubmit() {
  335. // 判断手机号是否正确
  336. let phone = this.data.phoneNum
  337. // 判断手机号是否为空
  338. if (!phone) {
  339. wx.showToast({
  340. title: '手机号不能为空',
  341. icon: 'none'
  342. })
  343. return
  344. }
  345. // 判断手机号是否正确
  346. let phoneReg = /^1(3|4|5|6|7|8|9)\d{9}$/;
  347. if (!phoneReg.test(phone)) {
  348. wx.showToast({
  349. title: '手机号格式错误',
  350. icon: 'none'
  351. })
  352. return;
  353. }
  354. // 判断微信号是否输入
  355. let weChatNum = this.data.weChatNum
  356. if (!weChatNum) {
  357. wx.showToast({
  358. title: '微信号不能为空',
  359. icon: 'none'
  360. })
  361. return
  362. }
  363. // 判断用户的姓是否输入
  364. let nameFirst = this.data.nameFirst
  365. if (!nameFirst) {
  366. wx.showToast({
  367. title: '姓不能为空',
  368. icon: 'none'
  369. })
  370. return
  371. }
  372. // 判断用户的名字是否输入
  373. let nameLast = this.data.nameLast
  374. if (!nameLast) {
  375. wx.showToast({
  376. title: '名字不能为空',
  377. icon: 'none'
  378. })
  379. return
  380. }
  381. // 判断用户输入的身份证号码是否正确
  382. let idNum = this.data.idNum
  383. // 判断身份证号是否为空
  384. if (!idNum) {
  385. wx.showToast({
  386. title: '身份证号码未填',
  387. icon: 'none'
  388. })
  389. return
  390. }
  391. // 判断身份证号码是否正确
  392. if (idNum.length != 18) {
  393. wx.showToast({
  394. title: '身份证号码错误',
  395. icon: 'none'
  396. })
  397. return
  398. }
  399. // 判断身份是否为空
  400. let chosedTeachAttr = this.data.chosedTeachAttr
  401. if (!chosedTeachAttr) {
  402. wx.showToast({
  403. title: '您还未选择身份',
  404. icon: 'none'
  405. })
  406. return
  407. }
  408. // 判断学校是否为空
  409. let school = this.data.school
  410. if (!school) {
  411. wx.showToast({
  412. title: '学校不能为空',
  413. icon: 'none'
  414. })
  415. return
  416. }
  417. // 判断专业是否为空
  418. let major = this.data.major
  419. if (!major) {
  420. wx.showToast({
  421. title: '专业不能为空',
  422. icon: 'none'
  423. })
  424. return
  425. }
  426. // 判断学历
  427. let chosedEducation = this.data.chosedEducation
  428. // 学历不能为空
  429. if (!chosedEducation) {
  430. wx.showToast({
  431. title: '您还未选择学历',
  432. icon: 'none'
  433. })
  434. return
  435. }
  436. if (chosedTeachAttr == '专职老师') {
  437. if (chosedEducation == '博士在读' || chosedEducation == '硕士在读' || chosedEducation == '本科在读' || chosedEducation == '专科在读') {
  438. wx.showToast({
  439. title: '学历与身份不符',
  440. icon: 'none'
  441. })
  442. return
  443. }
  444. }
  445. if (chosedTeachAttr == '在校大学生') {
  446. if (chosedEducation == '博士毕业' || chosedEducation == '硕士毕业' || chosedEducation == '本科毕业' || chosedEducation == '专科毕业') {
  447. wx.showToast({
  448. title: '学历与身份不符',
  449. icon: 'none'
  450. })
  451. return
  452. }
  453. }
  454. // 判断籍贯是否为空
  455. // 判断省份是否为空
  456. let province = this.data.province
  457. if (!province) {
  458. wx.showToast({
  459. title: '省份不能为空',
  460. icon: 'none'
  461. })
  462. return
  463. }
  464. // 判断地市是否为空
  465. let city = this.data.city
  466. if (!city) {
  467. wx.showToast({
  468. title: '地市不能为空',
  469. icon: 'none'
  470. })
  471. return
  472. }
  473. // 判断区县是否为空
  474. let county = this.data.county
  475. if (!county) {
  476. wx.showToast({
  477. title: '区县不能为空',
  478. icon: 'none'
  479. })
  480. return
  481. }
  482. // 存入本地缓存
  483. wx.setStorageSync('teach', {
  484. phoneNum: this.data.phoneNum,
  485. weChatNum: this.data.weChatNum,
  486. englishName: this.data.englishName,
  487. nameFirst: this.data.nameFirst,
  488. nameLast: this.data.nameLast,
  489. idNum: this.data.idNum,
  490. sex: this.data.sex,
  491. chosedTeachAttr: this.data.chosedTeachAttr,
  492. shcool: this.data.school,
  493. major: this.data.major,
  494. chosedEducation: this.data.chosedEducation,
  495. province: this.data.province,
  496. city: this.data.city,
  497. county: this.data.county,
  498. })
  499. wx.showToast({
  500. title: '提交成功',
  501. })
  502. },
  503. /**
  504. * 生命周期函数--监听页面初次渲染完成
  505. */
  506. onReady() {
  507. },
  508. /**
  509. * 生命周期函数--监听页面显示
  510. */
  511. onShow() {
  512. },
  513. /**
  514. * 生命周期函数--监听页面隐藏
  515. */
  516. onHide() {
  517. },
  518. /**
  519. * 生命周期函数--监听页面卸载
  520. */
  521. onUnload() {
  522. },
  523. /**
  524. * 页面相关事件处理函数--监听用户下拉动作
  525. */
  526. onPullDownRefresh() {
  527. },
  528. /**
  529. * 页面上拉触底事件的处理函数
  530. */
  531. onReachBottom() {
  532. },
  533. /**
  534. * 用户点击右上角分享
  535. */
  536. onShareAppMessage() {
  537. }
  538. })