Detail.jsx 6.15 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
  // 维修工单
  const Wxgd = () => {
TZW's avatar
TZW committed
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
    // return (
    //   <>
    //     <DesItem
    //       dataSource={request?.data?.dataList[0]}
    //       title="报修信息"
    //       hidden={true}
    //       index="0"
    //       // navhidden={false}
    //     />
    //     {request?.data?.dataList?.splice(1).map((it, index) => {
    //       return (
    //         <>
    //           <DesItem
    //             type="wxgd"
    //             dataSource={it}
    //             index={index + 2}
    //             hidden={true}
    //             navhidden={false}
    //           />
    //         </>
    //       );
    //     })}
    //   </>
    // );

    return hidden ? (
      <>
        <DesItem
          dataSource={request?.data?.dataList[0]}
          title="基本信息"
          hidden={true}
          type="wxgd"
          index="0"
          // navhidden={false}
        />
        <DesItem
          type="wxgd"
          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="wxgd"
          dataSource={request?.data?.dataList[request?.data?.dataList?.length - 2]}
          index={request?.data?.dataList?.length - 1}
          hidden={true}
          navhidden={false}
        />
        <DesItem
          type="wxgd"
          dataSource={request?.data?.dataList[request?.data?.dataList?.length - 1]}
          index={request?.data?.dataList?.length}
          hidden={true}
          navhidden={false}
        />
      </>
    ) : (
TZW's avatar
TZW committed
92 93
      <>
        <DesItem
TZW's avatar
TZW committed
94
          dataSource={request?.data?.dataList[0]}
TZW's avatar
TZW committed
95 96
          title="报修信息"
          hidden={true}
TZW's avatar
TZW committed
97
          index="0"
TZW's avatar
TZW committed
98
          // navhidden={false}
TZW's avatar
TZW committed
99
        />
TZW's avatar
TZW committed
100
        {request?.data?.dataList?.splice(1).map((it, index) => {
TZW's avatar
TZW committed
101 102 103 104
          return (
            <>
              <DesItem
                type="wxgd"
TZW's avatar
TZW committed
105 106
                dataSource={it}
                index={index + 2}
TZW's avatar
TZW committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
                hidden={true}
                navhidden={false}
              />
            </>
          );
        })}
      </>
    );
  };
  // 追踪工单
  const Zzgd = () => {
    return hidden ? (
      <>
        <DesItem
          dataSource={request?.data?.dataList[0]}
          title="基本信息"
          hidden={true}
TZW's avatar
TZW committed
124
          type="zzgd"
TZW's avatar
TZW committed
125 126 127 128 129 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 157 158 159 160 161 162 163 164 165 166
          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}
        />
      </>
    ) : (
      <>
        <DesItem
          dataSource={request?.data?.dataList[0]}
          title="基本信息"
TZW's avatar
TZW committed
167
          type="zzgd"
TZW's avatar
TZW committed
168 169 170 171 172 173 174 175 176 177 178
          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
179 180 181 182 183 184 185 186
                hidden={true}
                navhidden={false}
              />
            </>
          );
        })}
      </>
    );
TZW's avatar
TZW committed
187
  };
TZW's avatar
TZW committed
188 189 190 191 192 193 194 195
  // 外协工单
  const Wgd = () => {
    return (
      <>
        <DesItem
          dataSource={request?.data?.dataList[0]}
          title="基本信息"
          hidden={true}
TZW's avatar
TZW committed
196
          type="wgd"
TZW's avatar
TZW committed
197 198 199 200
          index="0"
          navhidden={true}
        />
        {request?.data?.dataList?.splice(1).map((it, index) => {
TZW's avatar
TZW committed
201
          console.log('11', it);
TZW's avatar
TZW committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
          return (
            <>
              <DesItem
                type="wgd"
                dataSource={it}
                index={index + 2}
                hidden={true}
                navhidden={false}
              />
            </>
          );
        })}
      </>
    );
  };
TZW's avatar
TZW committed
217 218 219 220 221 222 223 224 225 226 227 228
  const selectType = {
    gzbx: (
      <DesItem
        type="gzbx"
        index="0"
        dataSource={request?.data?.data}
        title="基本信息"
        hidden={true}
        navhidden={true}
      />
    ),
    wxgd: <Wxgd />,
TZW's avatar
TZW committed
229
    zzgd: <Zzgd />,
TZW's avatar
TZW committed
230
    wgd: <Wgd />,
TZW's avatar
TZW committed
231
  };
TZW's avatar
TZW committed
232 233 234
  return (
    <>
      <div>
TZW's avatar
TZW committed
235 236 237
        <h2 style={{ fontWeight: 700 }}>
          {title}{titleno}
        </h2>
TZW's avatar
TZW committed
238
      </div>
TZW's avatar
TZW committed
239
      <ProDescriptions columns={basecolumns} dataSource={baseRow} />
TZW's avatar
TZW committed
240
      <Divider />
TZW's avatar
TZW committed
241
      {selectType[type]}
TZW's avatar
TZW committed
242 243 244
    </>
  );
};