// packageCourse/components/studentManage/index.js const app = getApp(); import moment from "moment" import { getPublicImage } from '../../../assets/js/middleGround/tool' Component({ /** * 组件的属性列表 */ properties: { classId: { type: Number, default: 0 }, }, /** * 组件的初始数据 */ data: { userList: [], page: 1, limit: 10, total: 0, searchKey: '', currentIdentity: null, showConfirm: false, radioVal: 'RefCode', roleList: [{ name: '学生', value: 'RefCode' }, { name: '助教', value: 'Teacher' }], isAll: false, isEnbled: false, currentState: 'Normal', // 加载参数 bottomLoading: false, isMoreData: false, // 返回顶部 isBackTop: false, setScrollValue: 0, skeletonLoding: true }, ready() { this.getStudentList() }, /** * 组件的方法列表 */ methods: { changeHandle(e) { const { value } = e.detail; let cmsList = this.data.userList this.setData({ userList: [] }) if (value) { const data = cmsList.filter(item => item.appUser.name.indexOf(value) > -1); this.setData({ userList: data }) } if (value == '') { this.setData({ userList: [], }) this.getStudentList() } }, // 当前状态 onTabsChange(e) { this.setData({ currentState: e.detail.value, userList: [], isAll: false, isEnbled: false, searchKey: '' }) this.getStudentList() }, // 选择学生 selectUser(e) { const { index } = e.currentTarget.dataset let bool = false; let allBool = false; const data = [...this.data.userList]; data[index].isCheck = !data[index].isCheck; const list = data.filter(item => item.isCheck == true); if (list.length === data.length) { allBool = true } if (list.length > 0) { bool = true } this.setData({ userList: data, isEnbled: bool, isAll: allBool }) }, // 全选 selectAll(e) { const data = this.data.userList; data.forEach(item => { if (item.linkType != 'Creator') { item.isCheck = e.detail.checked } }) this.setData({ userList: data, isAll: e.detail.checked, isEnbled: e.detail.checked, }) }, // 批量通过 updateStateNormalDatas() { const dataUser = this.data.userList.filter((item) => item.isCheck == true && item.linkType != 'Creator') const data = { groupId: this.properties.classId, requests: dataUser.map((item) => { return { linkId: item.linkId, linkType: item.linkType, state: 'Normal', groupState: 'Normal' } }) } app.MG.identity.updateAppUserGroupLink(data).then((res) => { if (res) { wx.showToast({ title: '已通过', duration: 1000, icon: 'none', }) this.setData({ userList: [] }) this.getStudentList() } }) }, // 批量移除学生 removeStudentDatas() { wx.showModal({ title: '提示', content: '是否批量移除选中成员?', complete: (res) => { if (res.cancel) { return } if (res.confirm) { const dataUser = this.data.userList.filter((item) => item.isCheck == true && item.linkType != 'Creator') const data = { groupId: this.properties.classId, appUserIds: dataUser.map((item) => item.appUser.id) } app.MG.identity.removeAppUserFromGroup(data).then((res) => { if (res) { wx.showToast({ title: '已移除', duration: 1000, icon: 'none', }) this.setData({ userList: [] }) this.getStudentList() } }) } } }) }, // 批量拒绝 updateStateRejectDatas() { const dataUser = this.data.userList.filter((item) => item.isCheck == true && item.linkType != 'Creator') const data = { groupId: this.properties.classId, requests: dataUser.map((item) => { return { linkId: item.linkId, linkType: item.linkType, state: 'Reject', groupState: 'Normal' } }) } app.MG.identity.updateAppUserGroupLink(data).then((res) => { if (res) { wx.showToast({ title: '已拒绝', duration: 1000, icon: 'none', }) this.setData({ userList: [] }) this.getStudentList() } }) }, // 更新状态 拒绝 updateStateReject(e) { const { item } = e.currentTarget.dataset const data = { groupId: this.properties.classId, requests: [{ linkId: item.linkId, linkType: item.linkType, state: 'Reject', groupState: 'Normal' }] } app.MG.identity.updateAppUserGroupLink(data).then((res) => { if (res) { wx.showToast({ title: '已拒绝', duration: 1000, icon: 'none', }) this.setData({ userList: [] }) this.getStudentList() } }) }, // 获取学生列表 getStudentList(isReachBottom) { const data = { start: (this.data.page - 1) * this.data.limit, size: this.data.limit, filterList: [{ value: this.data.currentState, field: "State", subFilters: [] }], searchList: this.data.searchKey ? [{ keywords: this.data.searchKey, field: 'Name', compareType: 'Contains' }] : [], groupId: this.properties.classId } app.MG.identity.getGroupUserList(data).then((res) => { const { datas, totalSize } = res if (datas.length > 0) { let list = datas.map((item, index) => { if (item.linkType == 'Creator') { const wechatData = item.appUser?.infoList?.find((citem) => citem.type == 'WeChat') const defaultData = item.appUser?.infoList?.find((citem) => citem.type == 'teacherInfo') let userInfo = defaultData; if (wechatData?.name) { userInfo = wechatData; item.appUser.name = userInfo.name item.appUser.icon = userInfo.icon } else { if (userInfo?.data) { const iconData = JSON.parse(userInfo.data) item.appUser.icon = getPublicImage(iconData?.relevantCertificates[0]?.md5, 100) ?? '' } } } if (item.linkType == 'RefCode' || item.linkType == 'Teacher') { let userInfo = null const wechatData = item.appUser?.infoList?.find((citem) => citem.type == 'WeChat') const defaultData = item.appUser?.infoList?.find((citem) => citem.type == 'Default') userInfo = defaultData if (wechatData?.name) { userInfo = wechatData } item.appUser.name = userInfo.name item.appUser.icon = userInfo.icon } return { ...item, index: index + 1, createDate: moment(item.createDate).format('YYYY-MM-DD'), isCheck: false } }) //触底加载新数据并保留老数据 if (isReachBottom) { list = [...this.data.courseList, ...list] //将新数据加入老数据中 } this.setData({ userList: list, total: totalSize, isAll: false, isEnbled: false, skeletonLoding: false, bottomLoading: false }) } }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (this._freshing) return this.setData({ page: 1, bottomLoading: false, isMoreData: false }) setTimeout(() => { this._freshing = true; this.setData({ triggered: false, }) this.getStudentList(); this._freshing = false }, 500); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { if (this.data.pageCourse.total > this.data.courseList.length) { this.setData({ page: this.data.pageCourse.page + 1, bottomLoading: true, isMoreData: false }) } else { this.setData({ bottomLoading: false, isMoreData: true }) return false; } this.getStudentList(true); }, // 监听滚动距离 onPageScroll(e) { if (e && e.scrollTop >= 1000) { this.setData({ isBackTop: true }) } else { this.setData({ isBackTop: false }) } }, selectIdentity(e) { const { item } = e.currentTarget.dataset this.setData({ showConfirm: true, currentIdentity: item }) }, onChangeVal(e) { this.setData({ radioVal: e.detail.value }); }, // 移除学生 removeStudent(e) { wx.showModal({ title: '提示', content: '是否移除当前成员?', complete: (res) => { if (res.cancel) { return } if (res.confirm) { const { item } = e.currentTarget.dataset const data = { groupId: this.properties.classId, appUserIds: [item.appUser.id] } app.MG.identity.removeAppUserFromGroup(data).then((res) => { if (res) { wx.showToast({ title: '已移除', duration: 1000, icon: 'none', }) this.setData({ userList: [], isAll: false, isEnbled: false }) this.getStudentList() } }) } } }) }, cancle() { this.setData({ showConfirm: false, radioVal: 'RefCode' }) }, // 更新状态 updateStateNormal() { const data = { groupId: this.properties.classId, requests: [{ linkId: this.data.currentIdentity.linkId, linkType: this.data.radioVal, state: 'Normal', groupState: 'Normal' }] } app.MG.identity.updateAppUserGroupLink(data).then((res) => { if (res) { wx.showToast({ title: '已通过', duration: 1000, icon: 'success', }) this.setData({ userList: [], isAll: false, isEnbled: false }) this.cancle() this.getStudentList() } }) }, }, // 新建通知 newNotice(item, type) { const messageId = wx.getStorageSync('messageId') const str = type == 'success' ? item.appUser.name + '--加入班级' : item.appUser.name + '--已被移除班级' if (!messageId) { return false } const data = { description: '', icon: '', state: 'Normal', topicIdOrRefCode: String(messageId), name: str, content: "", type: 'Normal', cmsTypeRefCode: '', newDataListRequest: [] } app.MG.ugc .newTopicMessage(data) .then() .catch((err) => { console.log(err) }) } })