123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- // pages/teacher_detail/teacher_detail.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
- import { TeacherDetail, DeleteTeacher, DetachTeacher, UpdateTeacherInfo,AuditTeacher } from '../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
- const { baseImgUrl, thumbnail } = globalData
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- thumbnail,
- isReview:0,
- refuseModel:false,
- subList: [
- {
- text: '语文',
- status:''
- },
- {
- text: '数学',
- status: ''
- },
- {
- text: '英语',
- status: ''
- }
- ],
- idList: [
- {
- text: '作业标注',
- status: '',
- num:'4'
- },
- {
- text: '现场管理',
- status: '',
- num: '2'
- },
- {
- text: '学科答疑',
- status: '',
- num: '3'
- }
- ],
- classModel:false,
- teacherModel:false,
- list:[
- {
- "classId": "asdasd",
- "className": "二班",
- "studentSum": 21,
- "teacherSum": 3,
- "isDefault": 1
- }
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if(options.isReview==1){
- const {subList,idList}=this.data
- const {teacherTypeList, subject,name, imgUrl, phone,teacherId}=options;
- var sub = subject.split(',')
- for (var i in subList){
- for(var j in sub){
- if (subList[i].text == sub[j]) {
-
- subList[i].status='active'
- }
- }
- }
- for (var i in idList) {
- for (var j in teacherTypeList) {
- if (idList[i].num == teacherTypeList[j]) {
- idList[i].status = 'active'
- }
- }
- }
- this.setData({ idList, subList, name, imgUrl, phone,teacherId})
- }
- this.setData(options)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- const {isReview}=this.data
- if(isReview==0){
- this.getData()
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- /**
- * 拒绝审核弹框
- */
- refuseShow: function (e) {
- const { type,xid} = e.currentTarget.dataset;
- this.setData({ refuseType: Number(type),xid})
- if(type==2){
- this.setData({ refuseModel: true})
- }else{
- this.selectRefuse()
- }
- },
- /**
- * 通过拒绝审核
- */
- selectRefuse: function (cb) {
- const continuousFn = { fn: this.selectRefuse, param: { ...arguments } }
- const { teacherId,refuseType} = this.data;
- AuditTeacher({ data:{teacherId,type:refuseType}, continuousFn }).then(res => {
- if(refuseType==1){
- wx.showToast({
- title: '通过审核',
- icon: 'none'
- })
- }else{
- wx.showToast({
- title: '拒绝成功',
- icon: 'none'
- })
- }
- this.allShowModel()
- setTimeout(function(){
- wx.navigateBack({})
- },1500)
- if (isFn(cb)) cb()
- }).catch(res => {
- if (isFn(cb)) cb()
- })
- },
- /**
- * 提示框隐藏
- */
- allShowModel: function () {
- this.setData({ classModel: false, teacherModel:false,refuseModel:false})
- },
- /**
- * 删除老师
- */
- teacherShowModel: function () {
- this.setData({ teacherModel: true, classModel: false })
- },
- /**
- * 删除班级
- */
- classsShowModel: function (e) {
- const { id } = e.currentTarget.dataset;
- this.setData({ classModel: true, teacherModel: false,id })
- },
- /**
- * 删除老师
- */
- sureDeleteTeacher: function (e) {
- const continuousFn = { fn: this.sureDeleteTeacher, param: { ...arguments } }
- const { teacherId } = this.data;
- DeleteTeacher({ data: { teacherId }, continuousFn }).then(res => {
- wx.showToast({
- title: '删除成功',
- icon: 'none'
- })
- this.allShowModel()
- wx.navigateBack({})
- if (isFn(cb)) cb()
- }).catch(res => {
- if (isFn(cb)) cb()
- })
- },
- /**
- * 删除班级
- */
- sureDetachTeacher: function (e) {
- const continuousFn = { fn: this.sureDetachTeacher, param: { ...arguments } }
- const { id, teacherId } = this.data;
- DetachTeacher({ data: { classId: id, teacherId }, continuousFn }).then(res => {
- wx.showToast({
- title: '移除班级成功',
- icon: 'none'
- })
- this.allShowModel()
- this.getData()
- if (isFn(cb)) cb()
- }).catch(res => {
- if (isFn(cb)) cb()
- })
- },
- /**
- * 选择科目
- */
- selectSubject:function(e){
- const { sidx} = e.currentTarget.dataset;
- const { subList} = this.data;
- subList[sidx]['status'] = subList[sidx].status == '' ? 'active' : '';
- this.setData({ subList })
- var isCheck = 0;
- for (var i in subList) {
- if (subList[i].status == 'active') {
- isCheck++
- }
- }
- console.log(isCheck)
- if (isCheck==0){
- wx.showToast({
- title: '至少选一个学科',
- icon: 'none'
- })
- }else{
- this.sureUpdateTeacherInfo(1, sidx)
- }
- },
- /**
- * 选择身份
- */
- selectId: function (e) {
- const { xidx} = e.currentTarget.dataset;
- const { idList } = this.data;
- idList[xidx]['status'] = idList[xidx].status == '' ? 'active' : '';
- this.setData({ idList })
- var isCheck = 0;
- for (var i in idList) {
- if (idList[i].status == 'active') {
- isCheck++
- }
- }
- console.log(isCheck)
- if (isCheck == 0) {
- wx.showToast({
- title: '至少选一种身份',
- icon: 'none'
- })
- } else {
- this.sureUpdateTeacherInfo(2, xidx)
- }
-
- },
- /**
- * 更新老师学科或身份
- */
- sureUpdateTeacherInfo: function (i,e) {
- const continuousFn = { fn: this.sureUpdateTeacherInfo, param: { ...arguments } }
- const { teacherId, subList, idList } = this.data;
- var subjectList = [];
- for (var i in subList) {
- if (subList[i].status == 'active') {
- subjectList.push(subList[i].text)
- }
- }
- var teacherTypeList = [];
- for (var i in idList) {
- if (idList[i].status == 'active') {
- teacherTypeList.push(idList[i].num)
- }
- }
- UpdateTeacherInfo({ data: { teacherId, subjectList, teacherTypeList }, continuousFn }).then(res => {
- wx.showToast({
- title: '设置成功',
- icon: 'none'
- })
- // if (isFn(cb)) cb()
- }).catch(res => {
- // console.log('5555')
- if(i==1){
- subList[e]['status'] = subList[e].status == '' ? 'active' : '';
- this.setData({ subList})
- }else{
- idList[e]['status'] = idList[e].status == '' ? 'active' : '';
- this.setData({ idList})
- }
- // if (isFn(cb)) cb()
- })
- },
- /**
- * 获取数据
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- const { teacherId, subList, idList} = this.data;
- TeacherDetail({ data: { teacherId }, continuousFn }).then(res => {
- const { list, teacherTypeList, subject, name, imgUrl, phone}=res.data
- var sub = subject.split(',')
- for (var i in subList){
- for(var j in sub){
- if (subList[i].text == sub[j]) {
-
- subList[i].status='active'
- }
- }
- }
- for (var i in idList) {
- for (var j in teacherTypeList) {
- if (idList[i].num == teacherTypeList[j]) {
- idList[i].status = 'active'
- }
- }
- }
- console.log(idList, subList)
- this.setData({ list, idList, subList, name, imgUrl, phone})
- if (isFn(cb)) cb()
- }).catch(res => {
- if (isFn(cb)) cb()
- })
- },
- })
|