new_teacher.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // pages/new_teacher/new_teacher.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber,formatEncrypt} from '../../utils/util.js'
  3. import { CreateTeacher, CreateTeacherV1 } from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. input:125533222255,
  14. subList:[
  15. {
  16. text:'语文',
  17. status:"active"
  18. },
  19. {
  20. text: '数学',
  21. status: "active"
  22. },
  23. {
  24. text: '英语',
  25. status: "active"
  26. },
  27. ],
  28. idList:[
  29. {
  30. text: '作业标注',
  31. status: "active",
  32. num: '4'
  33. },
  34. {
  35. text: '现场管理',
  36. status: "active",
  37. num: '2'
  38. },
  39. {
  40. text: '学科答疑',
  41. status: "active",
  42. num: '3'
  43. },
  44. ]
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad: function (options) {
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面显示
  58. */
  59. onShow: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload: function () {
  70. },
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh: function () {
  75. },
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function () {
  80. },
  81. /**
  82. * 用户点击右上角分享
  83. */
  84. onShareAppMessage: function () {
  85. },
  86. /**
  87. * 加密
  88. */
  89. code:function(res){
  90. var input_rsa = res;
  91. var encrypt_rsa = new RSA.RSAKey();
  92. encrypt_rsa = RSA.KEYUTIL.getKey(publicKey);
  93. var encStr = encrypt_rsa.encrypt(input_rsa)
  94. encStr = RSA.hex2b64(encStr);
  95. return encStr
  96. },
  97. /**
  98. * 选择学科
  99. */
  100. selectSubject:function(e){
  101. const { sidx } = e.currentTarget.dataset
  102. const { subList}=this.data
  103. var temp={}
  104. subList[sidx]['status'] = subList[sidx].status == '' ? 'active' : '';
  105. this.setData({ subList})
  106. },
  107. /**
  108. * 选择身份
  109. */
  110. selectTeacher: function(e) {
  111. const { sidx } = e.currentTarget.dataset
  112. const { idList } = this.data
  113. var temp = {}
  114. idList[sidx]['status'] = idList[sidx].status == '' ? 'active' : '';
  115. this.setData({ idList })
  116. },
  117. /**
  118. * input
  119. */
  120. inputCtl: function (e) {
  121. const mobileExp = /^1[0-9]{10}$/;
  122. const { temp = {}, type } = e.currentTarget.dataset
  123. const { value } = e.detail
  124. temp[type] = value;
  125. const { name, mobile } = temp;
  126. // console.log(name)
  127. if (type == 'mobile') {
  128. if (value != '') {
  129. if (!mobileExp.test(value)) {
  130. wx.showToast({
  131. title: '手机号码位数不对',
  132. icon: 'none',
  133. duration: 2000
  134. })
  135. return this.setData({ mobile })
  136. } else {
  137. return this.setData({ mobile })
  138. }
  139. }
  140. } else if (type == 'name') {
  141. // if (value != '') {
  142. return this.setData({ name })
  143. // }
  144. }
  145. },
  146. /**
  147. * 取消
  148. */
  149. cancel:function(){
  150. wx.navigateBack({})
  151. },
  152. /**
  153. * 添加老师
  154. */
  155. sureCreateTeacher: function (cb) {
  156. const continuousFn = { fn: this.sureDeleteClass, param: { ...arguments } }
  157. const { name, mobile, subList, idList} = this.data;
  158. var that=this
  159. var subjectList = [];
  160. for (var i in subList){
  161. if (subList[i].status =='active'){
  162. console.log(subList[i].text)
  163. subjectList.push(subList[i].text)
  164. }
  165. }
  166. var teacherTypeList = []
  167. for (var i in idList) {
  168. if (idList[i].status == 'active') {
  169. teacherTypeList.push(idList[i].num)
  170. }
  171. }
  172. if (!name) {
  173. wx.showToast({
  174. title: '请输入姓名',
  175. icon: 'none'
  176. })
  177. return
  178. }
  179. if (!mobile) {
  180. wx.showToast({
  181. title: '请输入手机号',
  182. icon: 'none'
  183. })
  184. return
  185. }
  186. if (subjectList.length==0) {
  187. wx.showToast({
  188. title: '至少选择一个学科',
  189. icon: 'none'
  190. })
  191. return
  192. }
  193. if (teacherTypeList.length==0) {
  194. wx.showToast({
  195. title: '至少选择一种身份',
  196. icon: 'none'
  197. })
  198. return
  199. }
  200. CreateTeacherV1({ data: { name:formatEncrypt(name), mobile:formatEncrypt(mobile), subjectList, teacherTypeList }, continuousFn }).then(res => {
  201. wx.showToast({
  202. title: '创建成功',
  203. icon: 'none'
  204. })
  205. that.cancel()
  206. if (isFn(cb)) cb()
  207. }).catch(res => {
  208. if (isFn(cb)) cb()
  209. })
  210. },
  211. })