ListCard.jsx 2.4 KB
Newer Older
Maofei94's avatar
Maofei94 committed
1
import React, { useState, useEffect, useCallback } from 'react';
Maofei94's avatar
Maofei94 committed
2
import { Spin, Button } from 'antd';
3
import ListCardItem from './listCardItem';
陈前坚's avatar
陈前坚 committed
4
import { get, post, CITY_SERVICE } from '../../services';
Maofei94's avatar
Maofei94 committed
5
import styles from './listCardItem.less';
6

Maofei94's avatar
Maofei94 committed
7 8
const tip = 'loading...';
const ListCard = props => {
Maofei94's avatar
Maofei94 committed
9 10 11 12 13 14 15
  const {
    ouid,
    searchWord,
    valueCallback,
    onCommit = () => {},
    btnLoading = false,
  } = props;
16
  const [valueList, setValueList] = useState({});
Maofei94's avatar
Maofei94 committed
17 18
  const [dataList, setdataList] = useState([]);
  const [loading, setLoading] = useState(true);
19

Maofei94's avatar
Maofei94 committed
20
  const getValueCallback = useCallback((value, index) => {
21 22 23
    valueList[index] = value;
    setValueList({ ...valueList });
    valueCallback({ ...valueList });
Maofei94's avatar
Maofei94 committed
24
  }, []);
25

Maofei94's avatar
Maofei94 committed
26 27 28 29 30 31 32
  useEffect(() => {
    setLoading(true);
    const defaultConfig = {
      optionsList: [],
      title: '默认组',
      id: '',
    };
陈前坚's avatar
陈前坚 committed
33 34
    //  ${CITY_SERVICE}/OMS.svc/U_GetUserListForBatchOper
    get(`${CITY_SERVICE}/OMS.svc/P_GetUserByStation`, {
Maofei94's avatar
Maofei94 committed
35 36 37 38
      // OUID:ouid||'',
      stationID: ouid || '',
      _version: 9999,
      _dc: new Date().getTime(),
39
    })
Maofei94's avatar
Maofei94 committed
40 41 42
      .then(res => {
        setLoading(false);
        const list = [];
43
        // eslint-disable-next-line no-unused-expressions
Maofei94's avatar
Maofei94 committed
44
        res &&
45
          res.forEach(item => {
Maofei94's avatar
Maofei94 committed
46 47 48 49 50 51 52 53 54
            list.push({ ...defaultConfig, ...item });
          });
        setdataList(list);
      })
      .catch(err => {
        console.error(err);
        setLoading(false);
      });
  }, [ouid]);
55
  return (
Maofei94's avatar
Maofei94 committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    <div>
      {loading ? (
        <Spin
          size="large"
          spinning={loading}
          tip={tip}
          style={{
            position: 'absolute',
            top: '30%',
            left: '0',
            right: '0',
            bottom: '0',
          }}
        />
      ) : (
        dataList &&
        dataList.length > 0 &&
        dataList.map((item, index) => (
          <ListCardItem
            {...item}
            itemid={index}
            key={`item${index}key`}
            getValueCallback={getValueCallback}
            searchWord={searchWord}
            {...props}
          />
        ))
      )}
84
      {true && !loading && dataList && (
Maofei94's avatar
Maofei94 committed
85
        <div className={styles.btnBox}>
Maofei94's avatar
Maofei94 committed
86 87 88 89 90
          <Button
            type="primary"
            onClick={() => onCommit()}
            loading={btnLoading}
          >
Maofei94's avatar
Maofei94 committed
91 92 93
            提交
          </Button>
        </div>
Maofei94's avatar
Maofei94 committed
94 95 96 97
      )}
    </div>
  );
};
98

Maofei94's avatar
Maofei94 committed
99
export default ListCard;