content: // 加载 React 相关组件
  import React, { Component } from 'react';
  // 加载 AntD 相关组件
  import { Button, notification, Spin, Modal, Form, Input, Select } from 'antd';
  // 加载自定义组件
  import CommonTable from '../CommonTable';
  // 加载自定义工具集
  import { checkMapData } from '../../tools/Check';
  // 加载 React-Redux 组件
  import { connect } from 'react-redux';
  // 加载 Actions
  import {
    // 获取专业列表
    getMajorList,
    getMajorListSuccess,
    getMajorListFailure,
    // 获取班级列表
    getClassList,
    getClassListSuccess,
    getClassListFailure,
    // 添加班级
    addClassData,
    addClassDataSuccess,
    addClassDataFailure,
    // 删除班级
    delClassData,
    delClassDataSuccess,
    delClassDataFailure,
    // 修改班级
    editClassData,
    editClassDataSuccess,
    editClassDataFailure,
  } from '../../actions/Actions';
  
  // 声明组件
  let classTableTitle = null; // 声明班级列表表头
  let classTableColumns = null; // 声明班级列表列字段
  let classTableDataSource = []; // 声明班级列表数据源
  
  const FormItem = Form.Item;
  const Option = Select.Option;
  const confirm = Modal.confirm;
  
  // 创建 ClassAdmin 组件
  class ClassAdmin extends Component {
    // 自定义组件属性
    states = {
      loading: false, // 表明数据加载状态
    };
    // 自定义组件的数据
    datas = {
      userData: null, // 缓存用户数据
      majorList: null, // 缓存专业列表
      classData: null, // 缓存待修改的班级数据
      classList: null, // 缓存班级列表
    };
    // 构造方法
    constructor(props) {
      super(props);
      this.state = {
        modalVisible: false, // 弹框显示状态
        modalTitle: '', // 弹框标题
        modalOnOk: () => { }, // 弹框"确认按钮"事件
        modalOnCancel: () => { }, // 弹框"取消按钮"事件
        majorOptions: [],
      };
    }
    // ------------------------------添加班级相关方法------------------------------
    // 添加班级方法
    handleAddClassData() {
      this.openAddClassDataModal();
    }
    // 打开添加班级弹框
    openAddClassDataModal() {
      this.setState({ // 初始化弹框
        modalVisible: true,
        modalTitle: '添加班级',
        modalOnOk: this.handleConfirmAddClassData.bind(this),
        modalOnCancel: this.handleCancelAddClassData.bind(this),
      });
      const { setFieldsValue } = this.props.form;
      setFieldsValue({ // 初始化值
        major_name: '',
        class_no: '',
      });
    }
    // 关闭添加班级弹框
    closeAddClassDataModal() {
      this.setState({ modalVisible: false });
    }
    // 确认添加班级按钮事件
    handleConfirmAddClassData() {
      const { validateFields } = this.props.form;
      validateFields((error, values) => {
        if (!error) {
          this.props.addClassData({
            user_role: 'admin',
            user_no: this.datas.userData['admin_no'],
            login_password: this.datas.userData['login_password'],
            add_type: 'class',
            add_data: {
              major_id: this.searchMajorId(values['major_name']),
              major_name: values['major_name'],
              class_no: values['class_no'],
            },
          });
          this.closeAddClassDataModal();
        }
      });
    }
    // 取消添加班级按钮事件
    handleCancelAddClassData() {
      this.closeAddClassDataModal();
    }
    // ------------------------------修改班级相关方法------------------------------
    // 修改班级方法
    handleEditClassData(text, record, index) {
      this.openEditClassDataModal(record);
    }
    // 打开修改班级弹框
    openEditClassDataModal(record) {
      this.setState({ // 初始化弹框
        modalVisible: true,
        modalTitle: '修改班级',
        modalOnOk: this.handleConfirmEditClassData.bind(this),
        modalOnCancel: this.handleCancelEditClassData.bind(this),
      });
      const { setFieldsValue } = this.props.form;
      setFieldsValue({ // 初始化值
        major_name: record['major_name'],
        class_no: record['class_no'],
      });
      this.datas.classData = record;
    }
    // 关闭修改班级弹框
    closeEditClassDataModal() {
      this.setState({ modalVisible: false });
    }
    // 确认修改班级按钮事件
    handleConfirmEditClassData() {
      const { validateFields } = this.props.form;
      validateFields((error, values) => {
        if (!error) {
          this.props.editClassData({
            user_role: 'admin',
            user_no: this.datas.userData['admin_no'],
            login_password: this.datas.userData['login_password'],
            edit_type: 'class',
            edit_data: {
              class_id: this.datas.classData['class_id'],
              major_id: this.searchMajorId(values['major_name']),
              major_name: values['major_name'],
              class_no: values['class_no'],
            },
          });
          this.closeEditClassDataModal();
        }
      });
    }
    // 取消修改班级按钮事件
    handleCancelEditClassData() {
      this.closeEditClassDataModal();
    }
    // ------------------------------删除班级相关方法------------------------------
    // 删除班级方法
    handleDeleteClassData(text, record, index) {
      let delClassData = this.props.delClassData;
      let requestParams = {
        user_role: 'admin',
        user_no: this.datas.userData['admin_no'],
        login_password: this.datas.userData['login_password'],
        del_type: 'class',
        del_id: record['class_id'],
      };
      confirm({
        title: `确定删除班级"${record['class_name']}"吗？`,
        onOk() {
          delClassData(requestParams);
        },
      });
    }
    // -----------------------------------其他方法-----------------------------------
    // 过滤专业列表方法
    filterMajorList(majorName) {
      let majorOptions = [];
      this.datas.majorList.forEach((item, index) => {
        if (item['major_name'].indexOf(majorName) !== -1) {
          majorOptions.push(<Option key={index} value={item['major_name']}>{item['major_name']}</Option>);
        }
      });
      this.setState({ majorOptions: majorOptions });
    }
    // 查找专业ID方法
    searchMajorId(majorName) {
      let majorList = this.datas.majorList;
      let length = majorList.length;
      for (let i = 0; i < length; i++) {
        let item = majorList[i];
        if (item['major_name'] === majorName) {
          return item['major_id'];
        }
      }
      return -1;
    }
    // -----------------------------------------------------------------------------
    // 组件加载预处理方法
    componentWillMount() {
      classTableTitle = ( // 初始化表头
        <div className='table-title'>
          <div className='table-title-left'><h2>班级管理</h2></div>
          <div className='table-title-right'>
            <Button
              type='primary'
              icon='plus'
              onClick={this.handleAddClassData.bind(this)}>手动添加</Button>
          </div>
        </div>
      );
      classTableColumns = [{ // 初始化列定义
        title: '所属专业',
        dataIndex: 'major_name',
        key: 'major_name'
      }, {
        title: '班级编号',
        dataIndex: 'class_no',
        key: 'class_no'
      }, {
        title: '班级名称',
        dataIndex: 'class_name',
        key: 'class_name',
      }, {
        title: '操作',
        dataIndex: 'operation',
        key: 'operation',
        width: 240,
        render: (text, record, index) => {
          return (
            <div>
              <Button
                style={{ marginRight: 10 }}
                type='primary'
                icon='edit'
                onClick={this.handleEditClassData.bind(this, text, record, index)}>修改班级</Button>
              <Button
                type='primary'
                icon='delete'
                onClick={this.handleDeleteClassData.bind(this, text, record, index)}>删除班级</Button>
            </div>
          );
        }
      }];
      const { mapUserData } = this.props.actions; // 初始化用户数据
      if (checkMapData(mapUserData)) {
        this.datas.userData = mapUserData.data; // 缓存用户数据
      }
    }
    // 组件加载后处理方法
    componentDidMount() {
      this.props.getMajorList(
        this.datas.userData['admin_no'],
        this.datas.userData['login_password']
      );
      this.props.getClassList(
        this.datas.userData['admin_no'],
        this.datas.userData['login_password']
      );
      this.states.loading = true;
    }
    // 组件接受新属性处理方法
    componentWillReceiveProps(newProps) {
      const { mapMajorList, mapClassList } = newProps.actions;
      if (checkMapData(mapMajorList) && checkMapData(mapClassList)) {
        this.datas.majorList = mapMajorList.data; // 缓存专业列表数据
        this.datas.classList = mapClassList.data; // 缓存班级列表数据
        this.states.loading = false; // 修改数据加载状态
        if (!this.state.addClassModalState) {
          classTableDataSource = [];
          this.datas.classList.forEach((item, index) => {
            let classObject = {};
            classObject['key'] = index;
            classObject['major_id'] = item['major_id'];
            classObject['major_name'] = item['major_name'];
            classObject['class_id'] = item['class_id'];
            classObject['class_no'] = item['class_no'];
            classObject['class_name'] = item['class_name'];
            classTableDataSource.push(classObject);
          });
        }
      } else {
        this.states.loading = true; // 修改数据加载状态
      }
    }
    // 组件渲染方法
    render() {
      const { getFieldDecorator } = this.props.form;
      return (
        <div className="class-admin">
          {/*班级列表*/}
          <Spin spinning={this.states.loading} tip='数据加载中 ...' size='large'>
            <CommonTable
              title={() => classTableTitle}
              columns={classTableColumns}
              dataSource={classTableDataSource} />
          </Spin>
          {/*添加、修改班级弹框*/}
          <Modal
            title={this.state.modalTitle}
            visible={this.state.modalVisible}
            onOk={this.state.modalOnOk}
            onCancel={this.state.modalOnCancel}
          >
            <Form className='common-form'>
              <FormItem className='common-form-item'>
                <span>请输入班级所属专业：</span>
                {getFieldDecorator('major_name', {
                  rules: [{ required: true, message: '请输入班级所属专业' }],
                  initialValue: ''
                })(
                  <Select
                    className="select"
                    getPopupContainer={() => document.querySelector('.select')}
                    mode="combobox"
                    placeholder="请输入班级所属专业"
                    defaultActiveFirstOption={false}
                    showArrow={false}
                    filterOption={false}
                    onChange={this.filterMajorList.bind(this)}>{this.state.majorOptions}</Select>
                  )}
              </FormItem>
              <FormItem className='common-form-item'>
                <span>请输入班级编号：</span>
                {getFieldDecorator('class_no', {
                  rules: [{ required: true, message: '请输入班级编号' }],
                  initialValue: ''
                })(
                  <Input
                    type='text'
                    size='large'
                    placeholder='请输入班级编号' />
                  )}
              </FormItem>
            </Form>
          </Modal>
        </div>
      )
    }
  }
  
  // 声明待绑定的状态
  const mapStateToProps = (store) => {
    return {
      actions: store.actionsState
    }
  }
  
  // 声明待绑定的方法
  const mapDispatchToProps = (dispatch) => {
    let mapFunction = {
      // 获取专业列表
      getMajorList: (adminNo, loginPassword) => {
        dispatch(getMajorList('admin', adminNo, loginPassword)).mapMajorList.then((response) => {
          let resData = response.data;
          if (resData.errorCode === 0) {
            dispatch(getMajorListSuccess(resData.data));
            notification['success']({
              message: '获取专业列表成功',
              duration: 4.5,
            });
          } else {
            dispatch(getMajorListFailure(resData));
            notification['error']({
              message: '获取专业列表失败',
              description: resData.errorMessage,
              duration: 4.5,
            });
          }
        });
      },
      // 获取班级列表
      getClassList: (adminNo, loginPassword) => {
        dispatch(getClassList('admin', adminNo, loginPassword)).mapClassList.then((response) => {
          let resData = response.data;
          if (resData.errorCode === 0) {
            dispatch(getClassListSuccess(resData.data));
            notification['success']({
              message: '获取班级列表成功',
              duration: 4.5,
            });
          } else {
            dispatch(getClassListFailure(resData));
            notification['error']({
              message: '获取班级列表失败',
              description: resData.errorMessage,
              duration: 4.5,
            });
          }
        });
      },
      // 添加班级
      addClassData: (requestParams) => {
        dispatch(addClassData(requestParams)).mapAddClassData.then((response) => {
          let resData = response.data;
          if (resData.errorCode === 0) {
            dispatch(addClassDataSuccess(resData));
            notification['success']({
              message: '添加班级成功',
              duration: 4.5,
            });
            mapFunction.getClassList(requestParams['user_no'], requestParams['login_password']);
          } else {
            dispatch(addClassDataFailure(resData));
            notification['error']({
              message: '添加班级失败',
              description: resData.errorMessage,
              duration: 4.5,
            });
          }
        });
      },
      // 删除班级
      delClassData: (requestParams) => {
        dispatch(delClassData(requestParams)).mapDelClassData.then((response) => {
          let resData = response.data;
          if (resData.errorCode === 0) {
            dispatch(delClassDataSuccess(resData));
            notification['success']({
              message: '删除班级成功',
              duration: 4.5,
            });
            mapFunction.getClassList(requestParams['user_no'], requestParams['login_password']);
          } else {
            dispatch(delClassDataFailure(resData));
            notification['error']({
              message: '删除班级失败',
              description: resData.errorMessage,
              duration: 4.5,
            });
          }
        });
      },
      // 修改班级
      editClassData: (requestParams) => {
        dispatch(editClassData(requestParams)).mapEditClassData.then((response) => {
          let resData = response.data;
          if (resData.errorCode === 0) {
            dispatch(editClassDataSuccess(resData));
            notification['success']({
              message: '修改班级成功',
              duration: 4.5,
            });
            mapFunction.getClassList(requestParams['user_no'], requestParams['login_password']);
          } else {
            dispatch(editClassDataFailure(resData));
            notification['error']({
              message: '修改班级失败',
              description: resData.errorMessage,
              duration: 4.5,
            });
          }
        });
      },
    }
    return mapFunction;
  }
  
  // 导出组件
  export default connect(mapStateToProps, mapDispatchToProps)(Form.create()(ClassAdmin))
  