teacher_detail.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. // pages/teacher_detail/teacher_detail.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
  3. import { TeacherDetail, DeleteTeacher, DetachTeacher, UpdateTeacherInfo,AuditTeacher } 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. baseImgUrl,
  14. thumbnail,
  15. isReview:0,
  16. refuseModel:false,
  17. subList: [
  18. {
  19. text: '语文',
  20. status:''
  21. },
  22. {
  23. text: '数学',
  24. status: ''
  25. },
  26. {
  27. text: '英语',
  28. status: ''
  29. }
  30. ],
  31. idList: [
  32. {
  33. text: '作业标注',
  34. status: '',
  35. num:'4'
  36. },
  37. {
  38. text: '现场管理',
  39. status: '',
  40. num: '2'
  41. },
  42. {
  43. text: '学科答疑',
  44. status: '',
  45. num: '3'
  46. }
  47. ],
  48. classModel:false,
  49. teacherModel:false,
  50. list:[
  51. {
  52. "classId": "asdasd",
  53. "className": "二班",
  54. "studentSum": 21,
  55. "teacherSum": 3,
  56. "isDefault": 1
  57. }
  58. ]
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad: function (options) {
  64. if(options.isReview==1){
  65. const {subList,idList}=this.data
  66. const {teacherTypeList, subject,name, imgUrl, phone,teacherId}=options;
  67. var sub = subject.split(',')
  68. for (var i in subList){
  69. for(var j in sub){
  70. if (subList[i].text == sub[j]) {
  71. subList[i].status='active'
  72. }
  73. }
  74. }
  75. for (var i in idList) {
  76. for (var j in teacherTypeList) {
  77. if (idList[i].num == teacherTypeList[j]) {
  78. idList[i].status = 'active'
  79. }
  80. }
  81. }
  82. this.setData({ idList, subList, name, imgUrl, phone,teacherId})
  83. }
  84. this.setData(options)
  85. },
  86. /**
  87. * 生命周期函数--监听页面初次渲染完成
  88. */
  89. onReady: function () {
  90. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  91. for (const i in obj) {
  92. this[i] = obj[i]
  93. }
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow: function () {
  99. const {isReview}=this.data
  100. if(isReview==0){
  101. this.getData()
  102. }
  103. },
  104. /**
  105. * 生命周期函数--监听页面隐藏
  106. */
  107. onHide: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面卸载
  111. */
  112. onUnload: function () {
  113. },
  114. /**
  115. * 页面相关事件处理函数--监听用户下拉动作
  116. */
  117. onPullDownRefresh: function () {
  118. },
  119. /**
  120. * 页面上拉触底事件的处理函数
  121. */
  122. onReachBottom: function () {
  123. },
  124. /**
  125. * 用户点击右上角分享
  126. */
  127. onShareAppMessage: function () {
  128. },
  129. /**
  130. * 拒绝审核弹框
  131. */
  132. refuseShow: function (e) {
  133. const { type,xid} = e.currentTarget.dataset;
  134. this.setData({ refuseType: Number(type),xid})
  135. if(type==2){
  136. this.setData({ refuseModel: true})
  137. }else{
  138. this.selectRefuse()
  139. }
  140. },
  141. /**
  142. * 通过拒绝审核
  143. */
  144. selectRefuse: function (cb) {
  145. const continuousFn = { fn: this.selectRefuse, param: { ...arguments } }
  146. const { teacherId,refuseType} = this.data;
  147. AuditTeacher({ data:{teacherId,type:refuseType}, continuousFn }).then(res => {
  148. if(refuseType==1){
  149. wx.showToast({
  150. title: '通过审核',
  151. icon: 'none'
  152. })
  153. }else{
  154. wx.showToast({
  155. title: '拒绝成功',
  156. icon: 'none'
  157. })
  158. }
  159. this.allShowModel()
  160. setTimeout(function(){
  161. wx.navigateBack({})
  162. },1500)
  163. if (isFn(cb)) cb()
  164. }).catch(res => {
  165. if (isFn(cb)) cb()
  166. })
  167. },
  168. /**
  169. * 提示框隐藏
  170. */
  171. allShowModel: function () {
  172. this.setData({ classModel: false, teacherModel:false,refuseModel:false})
  173. },
  174. /**
  175. * 删除老师
  176. */
  177. teacherShowModel: function () {
  178. this.setData({ teacherModel: true, classModel: false })
  179. },
  180. /**
  181. * 删除班级
  182. */
  183. classsShowModel: function (e) {
  184. const { id } = e.currentTarget.dataset;
  185. this.setData({ classModel: true, teacherModel: false,id })
  186. },
  187. /**
  188. * 删除老师
  189. */
  190. sureDeleteTeacher: function (e) {
  191. const continuousFn = { fn: this.sureDeleteTeacher, param: { ...arguments } }
  192. const { teacherId } = this.data;
  193. DeleteTeacher({ data: { teacherId }, continuousFn }).then(res => {
  194. wx.showToast({
  195. title: '删除成功',
  196. icon: 'none'
  197. })
  198. this.allShowModel()
  199. wx.navigateBack({})
  200. if (isFn(cb)) cb()
  201. }).catch(res => {
  202. if (isFn(cb)) cb()
  203. })
  204. },
  205. /**
  206. * 删除班级
  207. */
  208. sureDetachTeacher: function (e) {
  209. const continuousFn = { fn: this.sureDetachTeacher, param: { ...arguments } }
  210. const { id, teacherId } = this.data;
  211. DetachTeacher({ data: { classId: id, teacherId }, continuousFn }).then(res => {
  212. wx.showToast({
  213. title: '移除班级成功',
  214. icon: 'none'
  215. })
  216. this.allShowModel()
  217. this.getData()
  218. if (isFn(cb)) cb()
  219. }).catch(res => {
  220. if (isFn(cb)) cb()
  221. })
  222. },
  223. /**
  224. * 选择科目
  225. */
  226. selectSubject:function(e){
  227. const { sidx} = e.currentTarget.dataset;
  228. const { subList} = this.data;
  229. subList[sidx]['status'] = subList[sidx].status == '' ? 'active' : '';
  230. this.setData({ subList })
  231. var isCheck = 0;
  232. for (var i in subList) {
  233. if (subList[i].status == 'active') {
  234. isCheck++
  235. }
  236. }
  237. console.log(isCheck)
  238. if (isCheck==0){
  239. wx.showToast({
  240. title: '至少选一个学科',
  241. icon: 'none'
  242. })
  243. }else{
  244. this.sureUpdateTeacherInfo(1, sidx)
  245. }
  246. },
  247. /**
  248. * 选择身份
  249. */
  250. selectId: function (e) {
  251. const { xidx} = e.currentTarget.dataset;
  252. const { idList } = this.data;
  253. idList[xidx]['status'] = idList[xidx].status == '' ? 'active' : '';
  254. this.setData({ idList })
  255. var isCheck = 0;
  256. for (var i in idList) {
  257. if (idList[i].status == 'active') {
  258. isCheck++
  259. }
  260. }
  261. console.log(isCheck)
  262. if (isCheck == 0) {
  263. wx.showToast({
  264. title: '至少选一种身份',
  265. icon: 'none'
  266. })
  267. } else {
  268. this.sureUpdateTeacherInfo(2, xidx)
  269. }
  270. },
  271. /**
  272. * 更新老师学科或身份
  273. */
  274. sureUpdateTeacherInfo: function (i,e) {
  275. const continuousFn = { fn: this.sureUpdateTeacherInfo, param: { ...arguments } }
  276. const { teacherId, subList, idList } = this.data;
  277. var subjectList = [];
  278. for (var i in subList) {
  279. if (subList[i].status == 'active') {
  280. subjectList.push(subList[i].text)
  281. }
  282. }
  283. var teacherTypeList = [];
  284. for (var i in idList) {
  285. if (idList[i].status == 'active') {
  286. teacherTypeList.push(idList[i].num)
  287. }
  288. }
  289. UpdateTeacherInfo({ data: { teacherId, subjectList, teacherTypeList }, continuousFn }).then(res => {
  290. wx.showToast({
  291. title: '设置成功',
  292. icon: 'none'
  293. })
  294. // if (isFn(cb)) cb()
  295. }).catch(res => {
  296. // console.log('5555')
  297. if(i==1){
  298. subList[e]['status'] = subList[e].status == '' ? 'active' : '';
  299. this.setData({ subList})
  300. }else{
  301. idList[e]['status'] = idList[e].status == '' ? 'active' : '';
  302. this.setData({ idList})
  303. }
  304. // if (isFn(cb)) cb()
  305. })
  306. },
  307. /**
  308. * 获取数据
  309. */
  310. getData: function (cb) {
  311. const continuousFn = { fn: this.getData, param: { ...arguments } }
  312. const { teacherId, subList, idList} = this.data;
  313. TeacherDetail({ data: { teacherId }, continuousFn }).then(res => {
  314. const { list, teacherTypeList, subject, name, imgUrl, phone}=res.data
  315. var sub = subject.split(',')
  316. for (var i in subList){
  317. for(var j in sub){
  318. if (subList[i].text == sub[j]) {
  319. subList[i].status='active'
  320. }
  321. }
  322. }
  323. for (var i in idList) {
  324. for (var j in teacherTypeList) {
  325. if (idList[i].num == teacherTypeList[j]) {
  326. idList[i].status = 'active'
  327. }
  328. }
  329. }
  330. console.log(idList, subList)
  331. this.setData({ list, idList, subList, name, imgUrl, phone})
  332. if (isFn(cb)) cb()
  333. }).catch(res => {
  334. if (isFn(cb)) cb()
  335. })
  336. },
  337. })