CurrentSolution.jsx 2.87 KB
Newer Older
1 2
import React, { useState, useEffect } from 'react';
import { Select, Card, Row, Col, Button, Spin, notification } from 'antd';
3
import PageContainer from '@/components/BasePageContainer';
4 5 6 7
import { getSolutionList, changeSolution } from '@/services/database/api';
import styles from './CurrentSolution.less';
const { Option } = Select;
const CurrentSolution = () => {
8 9
  const [currentData, setCurrentData] = useState(''); // 解决方案的值
  const [dataList, setDataList] = useState([]); // 下拉数组
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  const [loading, setLoading] = useState(false);
  useEffect(() => {
    setLoading(true);
    getSolutionList({
      _version: 9999,
      _dc: new Date().getTime(),
    })
      .then(res => {
        setLoading(false);
        if (res.success) {
          setCurrentData(res.currentSolution);
          setDataList(res.solutions);
        }
      })
      .catch(err => {
        setLoading(false);
        console.error(err);
      });
  }, []);
29
  // 切换解决方案
30 31 32
  const handleSelect = e => {
    setCurrentData(e);
  };
33
  // 提交配置信息
34 35 36 37 38 39 40 41 42 43 44 45
  const submit = params => {
    setLoading(true);
    changeSolution({
      solution: currentData,
      _version: 9999,
      _dc: new Date().getTime(),
    })
      .then(res => {
        setLoading(false);
        if (res.success) {
          notification.success({
            message: '提示',
46
            description: res.message || '切换成功',
47 48 49 50 51
            duration: 3,
          });
        } else {
          notification.error({
            message: '提示',
52
            description: res.message || '切换失败',
Maofei94's avatar
Maofei94 committed
53
            duration: 15,
54 55 56 57 58
          });
        }
      })
      .catch(err => {
        setLoading(false);
Maofei94's avatar
Maofei94 committed
59
        console.error(err);
60 61 62 63 64 65 66 67
      });
  };
  return (
    <PageContainer>
      <Card className={styles.cardbox}>
        <Spin tip="Loading..." spinning={loading} className={styles.tAlign}>
          <Row>
            <Col span={2} className={styles.divbox}>
Maofei94's avatar
Maofei94 committed
68
              <div>切换解决方案:</div>
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
            </Col>
            <Col span={21}>
              {currentData && (
                <Select
                  style={{ width: '100%' }}
                  placeholder="请切换解决方案"
                  defaultValue={currentData}
                  onChange={e => {
                    handleSelect(e);
                  }}
                >
                  {dataList &&
                    dataList.map((item, index) => (
                      <Option value={item} key={`item${index}`}>
                        {item}
                      </Option>
                    ))}
                </Select>
              )}
            </Col>
          </Row>
          <div className={styles.btnBox}>
            <Button type="primary" onClick={() => submit()}>
              提交
            </Button>
          </div>
        </Spin>
      </Card>
    </PageContainer>
  );
};

export default CurrentSolution;