MeterInfo.tsx 2.71 KB
Newer Older
DarkForst's avatar
DarkForst committed
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
import React, {useState} from 'react';
import { history, useRequest } from 'umi';
import { Tabs, Card } from 'antd'
import {FormOutlined} from '@ant-design/icons'
import {BorderLeft} from '@/components/Customized/AutoTitle'
import {fetchMeterInfo} from '@/services/gather'
import InfoTab from '../../Device/StandingBook/components/DeviceInfo/InfoTab'
import FileTab from '../../Device/StandingBook/components/DeviceInfo/FileTab'
import style from '../../Device/StandingBook/components/DeviceInfo/style.less'

const {TabPane} = Tabs;

type DeviceInfoProps = {
  deviceId: string;
  onUpdate?: () => void;
  hasBook: boolean
}

const Index: React.FC<DeviceInfoProps> = (props) => {
  const {deviceId, onUpdate, hasBook} = props
  const deviceDetail = useRequest(() => fetchMeterInfo(deviceId))

  const deviceInfo = deviceDetail?.data ? {...deviceDetail?.data, ...deviceDetail?.data?.device} : {}

  const [tab, setTab] = useState<string>('1')
  /**
   * @页面方法
   */
  const tabChange = (tabKey: string) => {
    setTab(tabKey)
  }
  /**
   * @页面数据
   */
  const tabData = [
    {tab: '基础信息', key: '1'},
    {tab: '设备文件', key: '2'},
  ]

  const testVal = deviceInfo.highestPriorityStatusCode;

  const className = {
    normal: "btn_success", malfunction: "btn_warning", alert: "btn_alarm",
    offline: "btn_disabled", deactivate: "btn_disabled", scrapped: 'btn_disabled'
  }[testVal]

  const title = {
    normal: '正常', malfunction: '故障', alert: '报警',
    offline: '离线', deactivate: '停用', scrapped: '报废'
  }[testVal]

  const tabExtra = <div className={className}>{title}</div>

  const editHref = () => {
    const url = hasBook
      ? `/ops/book/account/${deviceInfo?.device?.type}/edit/${deviceId}`
      : `/ops/gather/instrument/edit/${deviceId}`
    history.push(url)
  }
  const editUpdate = () => {
    onUpdate?.();
    deviceDetail.run()
  }

  return (
    <Card
      size="small"
      className={style.record_box}
      bodyStyle={{padding: '0 10px 10px'}}
      title={
        <div className="pos_aline_no_wrap">
          <BorderLeft title="设备信息"/>
          <div onClick={editHref} className={style.btn_primary}>
            编&nbsp;辑&nbsp;<FormOutlined />
          </div>
        </div>
      }
    >
      <Tabs
        activeKey={tab}
        onChange={tabChange}
        className={style.record_tab}
        tabBarExtraContent={tabExtra}
      >
        {tabData.map((item) => (
          <TabPane tab={item.tab} key={item.key}/>
        ))}
      </Tabs>
      {tab === '1' && (
        <InfoTab update={editUpdate} deviceInfo={deviceInfo} type="account"/>
      )}
      {tab === '2' && (
        <FileTab deviceInfo={deviceInfo}/>
      )}
    </Card>
  );
};

export default Index;