From b7e2556aaea15193dfc9259d3fa73ed236df7660 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 9 Jul 2019 14:00:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E5=AE=A1=E6=89=B9=E5=BE=85=E5=AE=A1?= =?UTF-8?q?=E6=89=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/courses/members/teacherList.js | 118 +++++++++++++++--- 1 file changed, 98 insertions(+), 20 deletions(-) diff --git a/public/react/src/modules/courses/members/teacherList.js b/public/react/src/modules/courses/members/teacherList.js index 2c5108f8d..18915f20c 100644 --- a/public/react/src/modules/courses/members/teacherList.js +++ b/public/react/src/modules/courses/members/teacherList.js @@ -1,5 +1,5 @@ import React,{ Component } from "react"; -import { Input,Checkbox,Table, Divider, Tooltip,Spin } from "antd"; +import { Input,Checkbox,Table, Divider, Tooltip,Spin, Menu } from "antd"; import CourseLayoutcomponent from '../common/CourseLayoutComponent' @@ -27,11 +27,14 @@ const ROLE_ADMIN = "管理员" const ROLE_TEACHER = "教师" const ROLE_TEACHER_ASSISTANT = "助教" const pageSize = 20; + function buildColumns(that) { + let sortedInfo = that.state.sortedInfo || {} const isAdmin = that.props.isAdmin() const isAdminOrCreator = that.props.isAdminOrCreator(); const isAdminOrTeacher = that.props.isAdminOrTeacher() - const { course_groups } = that.state + const { course_groups, filterKey } = that.state + const showSorter = filterKey == '1' const columns = [{ title: '序号', dataIndex: 'name', @@ -55,6 +58,8 @@ function buildColumns(that) { dataIndex: 'name', width: 120, key: 'name', + sorter: showSorter, + sortOrder: sortedInfo.columnKey === 'name' && sortedInfo.order, render: (name, record) => { return 4 ? name : ''}`}>{name} @@ -63,6 +68,11 @@ function buildColumns(that) { title: '角色', dataIndex: 'role', key: 'role', + sorter: showSorter, + // 'ascend' | 'descend' + defaultSortOrder: 'ascend', + sortOrder: sortedInfo.columnKey === 'role' && sortedInfo.order, + }] that.state.course_groups && that.state.course_groups.length && columns.push({ title: 管理权限, @@ -138,8 +148,11 @@ function buildColumns(that) { columns.push({ title: '答辩组', // width: 90, + sorter: showSorter, key: 'graduation_group', dataIndex: 'graduation_group', + sortOrder: sortedInfo.columnKey === 'graduation_group' && sortedInfo.order, + render: text => ( {text} @@ -200,6 +213,7 @@ class studentsList extends Component{ this.state={ headIndex:"1", page:1, + sortedInfo: { columnKey: 'role', order: 'ascend'}, totalPage:undefined, searchValue:"", order: ORDER_BY_DATE, @@ -209,7 +223,8 @@ class studentsList extends Component{ checkBoxValues: [], isSpin:false, application_list: [], - checkAllArray: [] + checkAllArray: [], + filterKey: 1, // 1 已审批 2 待审批 } } onCheckAllChange = (e, item, index) => { @@ -339,7 +354,7 @@ class studentsList extends Component{ console.log(error); }); } - fetchAll=(argPage)=>{ + fetchAll = (argPage) => { this.setState({ isSpin:true }) @@ -347,9 +362,28 @@ class studentsList extends Component{ if (argPage) { this.setState({ page: argPage }) } + + const sortedInfo = this.state.sortedInfo; let page = argPage || this.state.page - let { order, searchValue }=this.state - let url=`/courses/${id}/teachers.json?order=${order}&page=${page}`; + let { searchValue, filterKey }=this.state + let order = 1; + if (sortedInfo.columnKey == 'role') { + order = 1; + } else if (sortedInfo.columnKey == 'name') { + order = 2; + } else if (sortedInfo.columnKey == 'graduation_group') { + order = 3; + } + let sort = 'desc' + if (sortedInfo.order == 'ascend') { + sort = 'asc' + } + let url=`/courses/${id}/teachers.json?order=${order}&page=${page}&sort=${sort}`; + if (filterKey == '1') { + + } else if (filterKey == '2') { + url = `/courses/${id}/apply_teachers.json?_a=1` + } if(searchValue!=""){ url+='&search='+searchValue; } @@ -358,8 +392,17 @@ class studentsList extends Component{ this.setState({ teachers: result.data.teacher_list, total_count: result.data.teacher_list_size, - application_list: result.data.application_list, + // application_list: result.data.application_list || [], + is_admin: result.data.is_admin, + apply_size: result.data.apply_size, + isSpin:false + }) + } else if (result.data.application_list) { + this.setState({ + total_count: result.data.teacher_list_size, + application_list: result.data.application_list || [], is_admin: result.data.is_admin, + apply_size: result.data.apply_size, isSpin:false }) } @@ -529,13 +572,33 @@ class studentsList extends Component{ }) return result && result.length > 0 } - + onTableChange = (pagination, filters, sorter) => { + console.log('Various parameters', pagination, filters, sorter); + this.setState({ + sortedInfo: sorter, + }, () => { + this.fetchAll() + }); + }; + clearSelection = () => { + this.setState({ checkBoxValues: [] }) + } + selectedStatus=(e)=>{ + this.clearSelection() + this.setState({ + filterKey: e.key, + page:1, + isSpin:true + }, () => { + this.fetchAll(); + }) + } render(){ const isAdmin = this.props.isAdmin() const columns = buildColumns(this) let { searchValue, checkBoxValues, checkAllValue, - groupList, total_count, teachers, order, page + groupList, total_count, teachers, order, page, apply_size, filterKey }=this.state let currentOrderName = '加入时间排序' @@ -544,12 +607,13 @@ class studentsList extends Component{ } else if (order == ORDER_BY_GRADUATION_GROUP) { currentOrderName = '答辩组排序' } - const combineArray = teachers.slice(0) - if (page == 1) { - this.state.application_list && this.state.application_list.slice(0).reverse().forEach(item => { - item.isApply = true - combineArray.unshift(item) - }) + let combineArray = teachers.slice(0) + if (page == 1 && filterKey == '2') { + // this.state.application_list && this.state.application_list.slice(0).reverse().forEach(item => { + // item.isApply = true + // combineArray.unshift(item) + // }) + combineArray = this.state.application_list } const isAdminOrTeacher = this.props.isAdminOrTeacher() const hasGraduationModule = this.hasGraduationModule() @@ -585,12 +649,25 @@ class studentsList extends Component{ } secondRowLeft={ - total_count ? : '' + isAdminOrTeacher ?
+ + 已审批({total_count}) + 待审批({apply_size}) + +
: + (total_count ? : '') } onPressEnter={this.onPressEnter} >