index.jsx 10.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
/**
 * 转办组件
 * 徐立
 * 2020.4.8
 * @param { Function } asyncUser 选择用户同步函数
 * @param { Function } asyncReasion 转交理由同步参数
 */
import React, { Component } from 'react';
import { Input, Table, Row, Col, Tooltip, Spin } from 'antd';
import styles from '../style.less';
import { connect } from 'dva';
const { Search } = Input;
const { TextArea } = Input;
@connect()
export default class index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: [], // 表格参数
      checkedUser: '', // 用户选择参数
      textAreaValue: '', // 用户转发理由
      current: 1, // 当前页数
      pageSize: 10, // 每页条数
      total: 0, // 数据总数
      realname: '', // 姓名输入框输入值
      username: '', // 账号输入框输入值
      userData: '', // 回退数据
      isLoading: false, // 请求状态
    };
    this.columns = [
      {
        title: '工号',
        dataIndex: 'stuNo',
        width: 170,
      },
      {
        title: '用户名',
        dataIndex: 'realname',
        width: 170,
      },
      {
        title: '邮箱',
        dataIndex: 'email',
        width: 200,
        render: text => {
          return (
            <Tooltip title={text}>
              <div className={styles.table_post_name}>{text}</div>
            </Tooltip>
          );
        },
      },
      {
        title: '职位',
        dataIndex: 'mainPostName',
        render: text => {
          return (
            <Tooltip title={text}>
              <div className={styles.table_post_name}>{text}</div>
            </Tooltip>
          );
        },
      },
    ];
  }
  componentDidMount() {
    this.setState(
      {
        isLoading: true,
      },
      () => {
        this.getInit();
      },
    );
  }
  getInit = async () => {
    const { dispatch, value } = this.props;
    // 用户名列表
    await dispatch({
钟是志's avatar
钟是志 committed
80
      type: 'uaa_User_OneStop/fetch',
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
      payload: {
        pageNo: 1,
        pageSize: 5,
      },
      callback: val => {
        this.setState({
          data: val.rows,
          current: val.pageNo,
          total: val.totalPage,
          pageSize: val.pageSize,
        });
      },
    });
    await dispatch({
      type: 'trunTo/detailProcess',
      payload: {
        taskId: value.taskId,
      },
      callback: val => {
        this.setState({
          userData: Array.isArray(val) && val?.length > 0 ? val[val.length - 1] : '',
        });
      },
    });
    await this.setState({
      isLoading: false,
    });
  };
  userPaginationChange = value => {
    const { dispatch } = this.props;
    const { realname, username } = this.state;
    // 用户名列表
    dispatch({
钟是志's avatar
钟是志 committed
114
      type: 'uaa_User_OneStop/fetch',
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
      payload: {
        pageNo: value,
        pageSize: 5,
        realname,
        username,
      },
      callback: val => {
        this.setState({
          data: val.rows,
          current: val.pageNo,
          total: val.totalPage,
          pageSize: val.pageSize,
        });
      },
    });
  };
  /**
   * 根据名字查询
   * @param { string } value 用户输入值
   */
  searchNameChange = value => {
    const { dispatch } = this.props;
    dispatch({
钟是志's avatar
钟是志 committed
138
      type: 'uaa_User_OneStop/fetch',
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
      payload: {
        pageNo: 1,
        pageSize: 5,
        realname: value,
      },
      callback: val => {
        this.setState({
          data: val.rows,
          current: val.pageNo,
          total: val.totalPage,
          pageSize: val.pageSize,
        });
      },
    });
  };
  /**
   * 名字输入事件
   * @param { stirng } e 用户输入事件
   */
  onNameChange = e => {
    this.setState({
      realname: e.target.value,
      username: '',
    });
  };
  /**
   * 根据账号查询
   * @param { stirng } value 用户输入值
   */
  serachStuNoChange = value => {
    const { dispatch } = this.props;
    this.setState({
      username: value,
    });
    dispatch({
钟是志's avatar
钟是志 committed
174
      type: 'uaa_User_OneStop/fetch',
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
      payload: {
        pageNo: 1,
        pageSize: 5,
        username: value,
      },
      callback: val => {
        this.setState({
          data: val.rows,
          current: val.pageNo,
          total: val.totalPage,
          pageSize: val.pageSize,
        });
      },
    });
  };
  /**
   * 账号输入数据
   * @param { stirng } e 用户输入事件
   */
  onStuNoChange = e => {
    this.setState({
      username: e.target.value,
      realname: '',
    });
  };
  /**
   * 表格选择事件
   */
  tableChange = (selectedRowKeys, selectedRows) => {
    this.setState(
      {
        checkedUser: selectedRows?.[0] ?? '',
      },
      () => {
        this.props.asyncUser(this.state.checkedUser);
      },
    );
  };
  /**
   * 表格默认选择配置
   */
  getCheckboxProps = record => {
    return {
      disabled: record.name === 'Disabled User', // Column configuration not to be checked
      name: record.name,
    };
  };
  /**
   * 多行文本输入
   */
  textAreaChange = e => {
    this.setState({
      textAreaValue: e.target.value,
    });
    this.props.asyncReasion(e.target.value);
  };
  render() {
    const {
      data,
      checkedUser,
      current,
      total,
      pageSize,
      realname,
      username,
      userData,
      isLoading,
    } = this.state;
    const rowSelection = {
      onChange: this.tableChange,
      type: 'radio',
      fixed: true,
      // getCheckboxProps: this.getCheckboxProps,
    };
    let allWidth = 0;
    // 计算滑动总长度
    if (Array.isArray(this.columns)) {
      this.columns.map((item, index) => {
        if (this.columns.length - 1 === index) {
          // 为最后一个元素时跳过
          allWidth += 270; // 自适应200宽度
          return item;
        }
        if (item.width) {
          // 存在默认宽度
          allWidth += item.width;
        } else {
          // 不存在
          allWidth += 170;
        }
        return item;
      });
    }
    return (
      <>
        {!isLoading ? (
          <>
            <Row>
              <Col span={12}>
                <Row>
                  <Col
                    span={4}
                    style={{
                      minHeight: 32,
                      textAlign: 'right',
                      lineHeight: '32px',
                    }}
                  >
                    姓名 &nbsp;
                  </Col>
                  <Col span={20}>
                    <Search
                      placeholder="姓名"
                      value={realname}
                      onSearch={this.searchNameChange}
                      onChange={this.onNameChange}
                      enterButton
                    />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Col
                  span={4}
                  style={{
                    minHeight: 32,
                    textAlign: 'right',
                    lineHeight: '32px',
                  }}
                >
                  账号 &nbsp;
                </Col>
                <Col span={20}>
                  <Search
                    placeholder="账号"
                    value={username}
                    onSearch={this.serachStuNoChange}
                    onChange={this.onStuNoChange}
                    enterButton
                  />
                </Col>
              </Col>
            </Row>
            <div id="trun_to_table" className={styles.trun_to_table_div}>
              <Table
                rowSelection={rowSelection}
                columns={this.columns}
                dataSource={data}
                scroll={{ x: allWidth }}
                pagination={{
                  hideOnSinglePage: true,
                  pageSize,
                  total,
                  current,
                  onChange: this.userPaginationChange,
                }}
              />
            </div>
            {checkedUser ? (
              <div className={styles.show_checked_user_div}>
                <Row gutter={16}>
                  <Col
                    span={4}
                    style={{
                      textAlign: 'right',
                    }}
                  >
                    转发人:
                  </Col>
                  <Col span={20}>{checkedUser.realname}</Col>
                </Row>
                <Row
                  gutter={16}
                  style={{
                    marginTop: 12,
                  }}
                >
                  <Col
                    span={4}
                    style={{
                      textAlign: 'right',
                    }}
                  >
                    转发原因:
                  </Col>
                  <Col span={20}>
                    <TextArea
                      rows={4}
                      style={{
                        resize: 'none',
                      }}
                      onChange={this.textAreaChange}
                    />
                  </Col>
                </Row>
              </div>
            ) : null}
            {userData && (
              <div
                className={styles.show_checked_user_div}
                style={{
                  marginTop: 12,
                }}
              >
                <Row gutter={16}>
                  <Col
                    span={4}
                    style={{
                      textAlign: 'right',
                    }}
                  >
                    回退人:
                  </Col>
                  <Col span={20}>
                    {userData?.receiveUserName ?? '暂无'}
                    {/* {checkedUser.realname} */}
                  </Col>
                </Row>
                <Row
                  gutter={16}
                  style={{
                    marginTop: 12,
                  }}
                >
                  <Col
                    span={4}
                    style={{
                      textAlign: 'right',
                    }}
                  >
                    回退原因:
                  </Col>
                  <Col span={20}>{userData?.massage}</Col>
                </Row>
              </div>
            )}
          </>
        ) : (
          <div className={styles.spin_div}>
            <Spin />
          </div>
        )}
      </>
    );
  }
}