teachAuthentication.js 16 KB

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