Detail.jsx 4.46 KB
Newer Older
TZW's avatar
TZW committed
1 2
import React, { useState, useEffect } from 'react';
import { ProDescriptions } from '@ant-design/pro-components';
TZW's avatar
TZW committed
3
import { Divider, Button, Tooltip } from 'antd';
TZW's avatar
TZW committed
4
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
5
import { MoreOutlined } from '@ant-design/icons';
TZW's avatar
TZW committed
6 7
import { useRequest } from 'ahooks';
import DesItem from './DesItem';
TZW's avatar
TZW committed
8
export default (props) => {
TZW's avatar
TZW committed
9
  const { type, detailpath, params, baseRow, basecolumns, title, titleno } = props;
TZW's avatar
TZW committed
10
  const [hidden, sethidden] = useState(false);
TZW's avatar
TZW committed
11 12 13

  const request = useRequest(async () => {
    let res = await doFetch({ url: detailpath, params });
TZW's avatar
TZW committed
14 15 16
    if (res?.data?.dataList?.length > 4) {
      sethidden(true);
    }
TZW's avatar
TZW committed
17
    return res?.data || {};
TZW's avatar
TZW committed
18 19
  });

TZW's avatar
TZW committed
20 21 22 23 24
  // 维修工单
  const Wxgd = () => {
    return (
      <>
        <DesItem
TZW's avatar
TZW committed
25
          dataSource={request?.data?.dataList[0]}
TZW's avatar
TZW committed
26 27
          title="报修信息"
          hidden={true}
TZW's avatar
TZW committed
28
          index="0"
TZW's avatar
TZW committed
29
          // navhidden={false}
TZW's avatar
TZW committed
30
        />
TZW's avatar
TZW committed
31
        {request?.data?.dataList?.splice(1).map((it, index) => {
TZW's avatar
TZW committed
32 33 34 35
          return (
            <>
              <DesItem
                type="wxgd"
TZW's avatar
TZW committed
36 37
                dataSource={it}
                index={index + 2}
TZW's avatar
TZW committed
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
                hidden={true}
                navhidden={false}
              />
            </>
          );
        })}
      </>
    );
  };
  // 追踪工单
  const Zzgd = () => {
    return hidden ? (
      <>
        <DesItem
          dataSource={request?.data?.dataList[0]}
          title="基本信息"
          hidden={true}
          index="0"
          // navhidden={false}
        />
        <DesItem
          type="zzgd"
          dataSource={request?.data?.dataList[1]}
          index={'2'}
          hidden={true}
          navhidden={false}
        />
        <div className="fault-detail" style={{ paddingTop: 30, paddingBottom: 30 }}>
          <Tooltip title="点击展开">
            <Button
              type="primary"
              shape="circle"
              icon={<MoreOutlined />}
              onClick={() => {
                sethidden(false);
              }}
            />
          </Tooltip>
        </div>
        <DesItem
          type="zzgd"
          dataSource={request?.data?.dataList[request?.data?.dataList?.length - 2]}
          index={request?.data?.dataList?.length - 1}
          hidden={true}
          navhidden={false}
        />
        <DesItem
          type="zzgd"
          dataSource={request?.data?.dataList[request?.data?.dataList?.length - 1]}
          index={request?.data?.dataList?.length}
          hidden={true}
          navhidden={false}
        />
        {/* {request?.data?.dataList?.splice(1).map((it, index) => {
    return (
      <>
        <DesItem
          type="zzgd"
          dataSource={it}
          index={index + 2}
          hidden={true}
          navhidden={false}
        />
      </>
    );
  })} */}
      </>
    ) : (
      <>
        <DesItem
          dataSource={request?.data?.dataList[0]}
          title="基本信息"
          hidden={true}
          index="0"
          // navhidden={false}
        />
        {request?.data?.dataList?.splice(1).map((it, index) => {
          return (
            <>
              <DesItem
                type="zzgd"
                dataSource={it}
                index={index + 2}
TZW's avatar
TZW committed
121 122 123 124 125 126 127 128
                hidden={true}
                navhidden={false}
              />
            </>
          );
        })}
      </>
    );
TZW's avatar
TZW committed
129
  };
TZW's avatar
TZW committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
  // 外协工单
  const Wgd = () => {
    return (
      <>
        <DesItem
          dataSource={request?.data?.dataList[0]}
          title="基本信息"
          hidden={true}
          index="0"
          navhidden={true}
        />
        {request?.data?.dataList?.splice(1).map((it, index) => {
          return (
            <>
              <DesItem
                type="wgd"
                dataSource={it}
                index={index + 2}
                hidden={true}
                navhidden={false}
              />
            </>
          );
        })}
      </>
    );
  };
TZW's avatar
TZW committed
157 158 159 160 161 162 163 164 165 166 167 168
  const selectType = {
    gzbx: (
      <DesItem
        type="gzbx"
        index="0"
        dataSource={request?.data?.data}
        title="基本信息"
        hidden={true}
        navhidden={true}
      />
    ),
    wxgd: <Wxgd />,
TZW's avatar
TZW committed
169
    zzgd: <Zzgd />,
TZW's avatar
TZW committed
170
    wgd: <Wgd />,
TZW's avatar
TZW committed
171
  };
TZW's avatar
TZW committed
172 173 174
  return (
    <>
      <div>
TZW's avatar
TZW committed
175 176 177
        <h2 style={{ fontWeight: 700 }}>
          {title}{titleno}
        </h2>
TZW's avatar
TZW committed
178
      </div>
TZW's avatar
TZW committed
179
      <ProDescriptions columns={basecolumns} dataSource={baseRow} />
TZW's avatar
TZW committed
180
      <Divider />
TZW's avatar
TZW committed
181
      {selectType[type]}
TZW's avatar
TZW committed
182 183 184
    </>
  );
};