/* 设备台账
 * @Author: Li Hanlin
 * @Date: 2022-11-10 09:39:56
 * @Last Modified by: Li Hanlin
 * @Last Modified time: 2022-12-20 11:27:01
 */

import * as React from 'react';
import { useState, useMemo, useRef, useEffect } from 'react';
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
import { doFetch } from '@/utils/doFetch';
import { message, Dropdown, Menu, Layout, Button, Image, Space, Divider, Tabs } from 'antd';
import TreeRender from '@/components/TreeRender';
import { ProDescriptions } from '@ant-design/pro-components';
import InitForm from '@/components/InitForm';
import ExtendField from '@/components/ExtendField';

const { Sider, Content } = Layout;

function Model(props) {
  const actionRef = useRef(),
    formRef = useRef(),
    [drawer, setDrawer] = useState({
      visible: false,
    }),
    [extraparams, setextraparams] = useState({}),
    [currDrawer, setCurrDrawer] = useState({
      visible: false,
    }),
    currfields = {
      1: [
        {
          title: '操作人',
          dataIndex: 'updateUserName',
          key: 'updateUserName',
        },
        {
          title: '操作时间',
          dataIndex: 'updateTime',
          key: 'updateTime',
        },
        {
          title: '改造日期',
          dataIndex: 'reformDate',
          key: 'reformDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '改造承包商',
          dataIndex: 'supplierId',
          key: 'supplierId',
          valueType: 'select',
          options: {
            path: '/asset/equipmentSupplier/query/selection',
            params: {},
          },
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
        },
        {
          title: '改造内容',
          dataIndex: 'reformContent',
          key: 'reformContent',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '上传文件',
          key: 'urlIds',
          valueType: 'uploadDragger',
          // column: { xs: 1, sm: 2, md: 3 },
          span: '3',
          fieldProps: {
            maxCount: 5,
          },
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
          render: (text, row) => {
            return (
              <div>
                {row?.urlIds.map((it) => (
                  // eslint-disable-next-line react/jsx-key
                  <div style={{ marginBottom: '8px' }}>
                    <a href={it?.url} download target="_blank" rel="noopener noreferrer">
                      {it?.name}
                    </a>
                  </div>
                ))}
              </div>
            );
          },
        },
      ],
      2: [
        {
          title: '操作人',
          dataIndex: 'updateUserName',
          key: 'updateUserName',
        },
        {
          title: '操作时间',
          dataIndex: 'updateTime',
          key: 'updateTime',
        },
        {
          title: '报废日期',
          dataIndex: 'scrapDate',
          key: 'scrapDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '报废原因',
          dataIndex: 'scrapReason',
          key: 'scrapReason',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '上传文件',
          key: 'urlIds',
          valueType: 'uploadDragger',
          span: '3',
          formItemProps: {
            rules: [
              {
                required: false,
                message: '此项为必填项',
              },
            ],
          },
          fieldProps: {
            maxCount: 5,
          },
          render: (text, row) => {
            return (
              <div>
                {row?.urlIds.map((it) => (
                  // eslint-disable-next-line react/jsx-key
                  <div style={{ marginBottom: '8px' }}>
                    <a href={it?.url} download target="_blank" rel="noopener noreferrer">
                      {it?.name}
                    </a>
                  </div>
                ))}
              </div>
            );
          },
        },
      ],
      3: [
        {
          title: '操作人',
          dataIndex: 'updateUserName',
          key: 'updateUserName',
        },
        {
          title: '操作时间',
          dataIndex: 'updateTime',
          key: 'updateTime',
        },
        {
          title: '调入公司',
          dataIndex: 'toOrganizationName',
          key: 'toOrganizationId',
          valueType: 'select',
          options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '调入部门',
          valueType: 'treeSelect',
          dataIndex: 'toDepartmentName',
          key: 'toDepartmentId',
          options: {
            path: '/auth/sysDepartment/query/children/tree',
            linkParams: {
              toOrganizationId: 'parentId',
            },
          },
        },
        {
          title: '调入工厂',
          dataIndex: 'toFactoryName',
          key: 'toFactoryId',
          valueType: 'select',
          options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '调入车间',
          dataIndex: 'toShopName',
          valueType: 'select',
          options: {
            path: '/auth/sysShop/getShopSelectionByFactory',
            linkParams: {
              toFactoryId: 'factoryId',
            },
          },
          key: 'toShopId',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '调入工段',
          dataIndex: 'toSectionName',
          key: 'toSectionId',
          valueType: 'select',
          options: {
            path: '/auth/sysSection/getAllSectionSelectionByShop',
            linkParams: {
              toShopId: 'shopId',
            },
          },
        },
        {
          title: '调入产线',
          dataIndex: 'toProductLineName',
          valueType: 'select',
          key: 'toProductLineId',
          options: {
            path: '/auth/sysProductionLine/getAllProductLineSelectionByShop',
            linkParams: {
              toShopId: 'shopId',
            },
          },
        },
        {
          title: '调入位置号',
          dataIndex: 'toPositionNo',
          valueType: 'input',
          key: 'toPositionNo',
        },
        {
          title: '调拨日期',
          dataIndex: 'transferDate',
          key: 'transferDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '调拨原因',
          dataIndex: 'transferReason',
          key: 'transferReason',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
      ],
      4: [
        {
          title: '操作人',
          dataIndex: 'updateUserName',
          key: 'updateUserName',
        },
        {
          title: '操作时间',
          dataIndex: 'updateTime',
          key: 'updateTime',
        },
        {
          title: '借用公司',
          dataIndex: 'toOrganizationName',
          key: 'toOrganizationName',
        },
        {
          title: '借用部门',
          valueType: 'treeSelect',
          dataIndex: 'toDepartmentName',
          key: 'toDepartmentName',
        },
        {
          title: '借用工厂',
          dataIndex: 'toFactoryName',
          key: 'toFactoryName',
        },
        {
          title: '借用车间',
          dataIndex: 'toShopName',
          valueType: 'select',
          key: 'toShopName',
        },
        {
          title: '借用工段',
          dataIndex: 'toSectionName',
          key: 'toSectionName',
        },
        {
          title: '借用产线',
          dataIndex: 'toProductLineName',
          key: 'toProductLineName',
        },
        {
          title: '借用位置号',
          dataIndex: 'toPositionNo',
          valueType: 'input',
          key: 'toPositionNo',
        },
        {
          title: '借用日期',
          dataIndex: 'borrowDate',
          key: 'borrowDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '预计归还日期',
          dataIndex: 'planReturnDate',
          key: 'planReturnDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '借用原因',
          dataIndex: 'borrowReason',
          key: 'borrowReason',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
      ],
      5: [
        {
          title: '操作人',
          dataIndex: 'updateUserName',
          key: 'updateUserName',
        },
        {
          title: '操作时间',
          dataIndex: 'updateTime',
          key: 'updateTime',
        },
        {
          title: '接收公司',
          dataIndex: 'returnOrganizationName',
          key: 'returnOrganizationName',
          valueType: 'select',
          options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '接收部门',
          valueType: 'treeSelect',
          dataIndex: 'returnDepartmentName',
          key: 'returnDepartmentName',
          options: {
            path: '/auth/sysDepartment/query/children/tree',
            linkParams: {
              returnOrganizationId: 'parentId',
            },
          },
        },
        {
          title: '接收工厂',
          dataIndex: 'returnFactoryName',
          key: 'returnFactoryName',
          valueType: 'select',
          options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '接收车间',
          dataIndex: 'returnShopName',
          valueType: 'select',
          options: {
            path: '/auth/sysShop/getShopSelectionByFactory',
            linkParams: {
              returnFactoryId: 'factoryId',
            },
          },
          key: 'returnShopId',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '接收工段',
          dataIndex: 'returnSectionName',
          key: 'returnSectionId',
          valueType: 'select',
          options: {
            path: '/auth/sysSection/getAllSectionSelectionByShop',
            linkParams: {
              returnShopId: 'shopId',
            },
          },
        },
        {
          title: '接收产线',
          dataIndex: 'returnProductLineName',
          valueType: 'select',
          key: 'returnProductLineId',
          options: {
            path: '/auth/sysProductionLine/getAllProductLineSelectionByShop',
            linkParams: {
              returnShopId: 'shopId',
            },
          },
        },
        {
          title: '接收位置号',
          dataIndex: 'returnPositionNo',
          valueType: 'input',
          key: 'returnPositionNo',
        },
        {
          title: '实际归还日期',
          dataIndex: 'realReturnDate',
          key: 'realReturnDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '备注',
          dataIndex: 'remark',
          key: 'remark',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
      ],
    },
    urlParams = {
      save: '/asset/equipment/save',
      remove: '/asset/equipment/deleteById',
      list: '/asset/equipment/queryList',
      detail: '/asset/equipment/detail',
    },
    urlParams_childEquipment = {
      list: '/asset/equipment/children/queryList',
      checked: '/asset/equipment/children/selected/queryList',
      save: '/asset/equipmentChildren/save',
    },
    urlParams_resume = {
      save: '/asset/equipmentLog/save',
      list: '/asset/equipmentLog/queryEquipmentLogPage',
      detail: '/asset/equipmentLog/query/resumeDetail',
    },
    urlParams_correlation = {
      zsb: '/asset/equipment/detail/children/page',
      fsb: '/asset/equipment/detail/parent/page',
    };

  function formatDate(date) {
    var myyear = date.getFullYear();
    var mymonth = date.getMonth() + 1;
    var myweekday = date.getDate();

    if (mymonth < 10) {
      mymonth = '0' + mymonth;
    }
    if (myweekday < 10) {
      myweekday = '0' + myweekday;
    }
    return myyear + '-' + mymonth + '-' + myweekday; //想要什么格式都可以随便自己拼
  }

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setDrawer((s) => ({
              ...s,
              visible: true,
              title: '编辑',
              val: 'only',
              type: 'edit',
              item: row,
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否删除该设备?',
          okText: '确认',
          cancelText: '取消',
          onConfirm: async () => {
            let res = await doFetch({ url: urlParams.remove, params: { id: row.id } });
            if (res.code === '0000') {
              message.success('删除成功！');
              setDrawer((s) => ({
                ...s,
                visible: false,
              }));
              actionRef.current.reload();
            }
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

  const more = (text, row, _, action) => {
    const menu = (
      <Menu
        items={[
          {
            label: (
              <a
                onClick={() => {
                  setDrawer((s) => ({
                    ...s,
                    visible: true,
                    type: 'editChildEquipment',
                    item: {
                      id: row.id,
                    },
                    val: 'only',
                    title: '编辑子设备',
                  }));
                }}
              >
                编辑子设备
              </a>
            ),
            key: '0',
          },
          {
            label: (
              <a
                onClick={() => {
                  setDrawer((s) => ({
                    ...s,
                    visible: true,
                    type: 'resume',
                    item: {
                      id: row.id,
                      reformDate: formatDate(new Date()),
                      scrapDate: formatDate(new Date()),
                      transferDate: formatDate(new Date()),
                      borrowDate: formatDate(new Date()),
                      realReturnDate: formatDate(new Date()),
                    },
                    val: 'only',
                    title: '履历登记',
                  }));
                }}
              >
                履历登记
              </a>
            ),
            key: '1',
          },
          {
            label: <a>关联备件(暂缓)</a>,
            key: '2',
          },
          {
            label: <a>寿命件台账(暂缓)</a>,
            key: '3',
          },
        ]}
      />
    );
    return (
      <Dropdown
        overlay={menu}
        trigger={['click']}
        arrow={true}
        getPopupContainer={() => containderef.current}
      >
        <Button size="small">更多</Button>
      </Dropdown>
    );
  };

  //设备详情
  const Detail = () => {
    const [activeTab, setactiveTab] = useState(1);
    // 基础信息
    const BaseInfo = () => {
      const columns = [
        {
          title: '设备编号',
          dataIndex: 'equipmentNo',
          key: 'equipmentNo',
        },
        {
          title: '设备名称',
          dataIndex: 'equipmentName',
          key: 'equipmentName',
        },
        {
          title: '位置号',
          dataIndex: 'positionNo',
          key: 'positionNo',
        },
        {
          title: '设备类型',
          dataIndex: 'equipmentTypeName',
          key: 'equipmentTypeId',
        },
        {
          title: '状态',
          dataIndex: 'statusName',
          key: 'statusName',
          span: 2,
        },
        {
          title: '公司名称',
          dataIndex: 'organizationName',
          key: 'organizationId',
        },
        {
          title: '部门名称',
          dataIndex: 'departmentName',
          key: 'departmentId',
        },
        {
          title: '工厂名称',
          dataIndex: 'factoryName',
          key: 'factoryId',
        },
        {
          title: '车间名称',
          dataIndex: 'shopName',
          key: 'shopId',
        },
        {
          title: '工段名称',
          dataIndex: 'sectionName',
          key: 'sectionId',
        },
        {
          title: '产线名称',
          dataIndex: 'productLineName',
          key: 'productLineName',
        },
        {
          title: '供应商',
          dataIndex: 'supplierName',
          key: 'supplierId',
        },
        {
          title: '设备原值',
          dataIndex: 'equipmentWorth',
          key: 'equipmentWorth',
        },
        {
          title: '安装投产日期',
          dataIndex: 'productDate',
          key: 'productDate',
        },
        {
          title: '图片',
          dataIndex: 'pictureUrl',
          key: 'pictureUrl',
          render: (text, row) => <Image width={70} src={row.pictureUrl} />,
        },
        {
          title: '二维码',
          dataIndex: 'qrCodeUrl',
          key: 'qrCodeUrl',
          render: (text, row) => <Image width={70} src={row.qrCodeUrl} />,
        },
      ];
      const [newfieldscolumns, setnewfieldscolumns] = useState(columns);
      const selectValueType = (type, options) => {
        switch (type) {
          case 1:
            return {
              valueType: 'input',
            };
          case 2:
            return {
              valueType: 'select',
              options,
            };
          case 3:
            return {
              valueType: 'radio',
              options,
            };
          case 4:
            return {
              valueType: 'select',
              options,
            };
          default:
            break;
        }
      };
      const [request, setrequest] = useState();
      useEffect(() => {
        const fn = async () => {
            console.log('d');

            let res = await doFetch({
              url: '/base/paFormField/queryList',
              params: {
                formId: '2',
              },
            });
            if (res?.data?.dataList) {
              let column = [];
              res?.data?.dataList?.forEach?.((el) => {
                column.push({
                  ...selectValueType(el.fieldChar, el.valueList),
                  title: el.fieldName,
                  dataIndex: el.id,
                  key: el.id,
                });
              });
              setnewfieldscolumns(column);
            }
          },
          fn2 = async () => {
            const res = await doFetch({
              url: urlParams.detail,
              params: { id: drawer?.item?.id },
            });
            let obj = {};
            res?.data?.data['equipmentCharList']?.forEach?.((it) => {
              obj[it?.fieldId] = it?.fieldRealValue;
            });
            console.log('drawerpro:', {
              ...(res?.data?.data ?? {}),
              ...obj,
            });
            setrequest(
              {
                ...(res?.data?.data ?? {}),
                ...obj,
              } ?? {},
            );
          };
        fn();
        fn2();
      }, []);
      return (
        <>
          <ProDescriptions dataSource={request} columns={columns} />
          <Divider />
          <h3 className="page-title" style={{ marginBottom: 16 }}>
            扩展字段
          </h3>
          <ProDescriptions dataSource={request} columns={newfieldscolumns} />
        </>
      );
    };
    // 相关设备
    const Correlation = () => {
      return (
        <>
          <AutoTable
            pagetitle="子设备"
            columns={[
              {
                title: '设备编号',
                dataIndex: 'equipmentNo',
                key: 'equipmentNo',
                search: false,

                width: 120,
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '设备名称',
                dataIndex: 'equipmentName',
                search: false,

                width: 120,
                key: 'equipmentName',
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '公司名称',

                search: false,
                dataIndex: 'organizationName',
                width: 120,
                key: 'organizationId',
                valueType: 'select',
                options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '部门名称',
                width: 120,
                search: false,

                valueType: 'treeSelect',
                dataIndex: 'departmentName',
                key: 'departmentId',
                options: {
                  path: '/auth/sysDepartment/query/children/tree',
                  linkParams: {
                    organizationId: 'parentId',
                  },
                },
              },
              {
                title: '工厂名称',
                dataIndex: 'factoryName',
                search: false,
                key: 'factoryId',
                width: 120,

                valueType: 'select',
                options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '车间名称',
                dataIndex: 'shopName',

                search: false,
                width: 120,
                valueType: 'select',
                options: {
                  path: '/auth/sysShop/getShopSelectionByFactory',
                  linkParams: {
                    factoryId: '',
                  },
                },
                key: 'shopId',
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '工段名称',
                search: false,
                width: 120,
                dataIndex: 'sectionName',

                key: 'sectionId',
                valueType: 'select',
                options: {
                  path: '/auth/sysSection/getAllSectionSelectionByShop',
                  linkParams: {
                    shopId: '',
                  },
                },
              },
              {
                title: '产线名称',
                search: false,
                width: 120,
                dataIndex: 'productLineName',
                valueType: 'select',
                key: 'productLineName',

                options: {
                  path: '/auth/sysProductionLine/getAllProductLineSelectionByShop',
                  linkParams: {
                    shopId: '',
                  },
                },
              },
            ]}
            path={urlParams_correlation.zsb}
            params={{ id: drawer?.item?.id }}
            resizeable={false}
          />
          <Divider />
          <AutoTable
            pagetitle="父设备"
            columns={[
              {
                title: '设备编号',
                dataIndex: 'equipmentNo',
                search: false,
                key: 'equipmentNo',

                width: 120,
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '设备名称',
                dataIndex: 'equipmentName',
                search: false,

                width: 120,
                key: 'equipmentName',
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '公司名称',

                dataIndex: 'organizationName',
                width: 120,
                key: 'organizationId',
                search: false,
                valueType: 'select',
                options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '部门名称',
                width: 120,

                search: false,
                valueType: 'treeSelect',
                dataIndex: 'departmentName',
                key: 'departmentId',
                options: {
                  path: '/auth/sysDepartment/query/children/tree',
                  linkParams: {
                    organizationId: 'parentId',
                  },
                },
              },
              {
                title: '工厂名称',
                search: false,
                dataIndex: 'factoryName',
                key: 'factoryId',
                width: 120,

                valueType: 'select',
                options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '车间名称',
                dataIndex: 'shopName',
                search: false,

                width: 120,
                valueType: 'select',
                options: {
                  path: '/auth/sysShop/getShopSelectionByFactory',
                  linkParams: {
                    factoryId: '',
                  },
                },
                key: 'shopId',
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '工段名称',
                width: 120,
                dataIndex: 'sectionName',

                key: 'sectionId',
                search: false,
                valueType: 'select',
                options: {
                  path: '/auth/sysSection/getAllSectionSelectionByShop',
                  linkParams: {
                    shopId: '',
                  },
                },
              },
              {
                title: '产线名称',
                width: 120,
                dataIndex: 'productLineName',
                valueType: 'select',
                search: false,
                key: 'productLineName',

                options: {
                  path: '/auth/sysProductionLine/getAllProductLineSelectionByShop',
                  linkParams: {
                    shopId: '',
                  },
                },
              },
            ]}
            path={urlParams_correlation.fsb}
            params={{ id: drawer?.item?.id }}
            resizeable={false}
          />
        </>
      );
    };
    //履历查询
    const Curritae = () => {
      return (
        <>
          <ProDescriptions
            title="设备信息"
            request={async () => {
              const { data } = await doFetch({
                url: urlParams.detail,
                params: { id: drawer?.item?.id },
              });
              return {
                success: true,
                data: data?.data,
              };
            }}
            columns={[
              {
                title: '设备编号',
                dataIndex: 'equipmentNo',
                key: 'equipmentNo',
              },
              {
                title: '设备名称',
                dataIndex: 'equipmentName',
                key: 'equipmentName',
              },
              {
                title: '位置号',
                dataIndex: 'positionNo',
                key: 'positionNo',
              },

              {
                title: '公司名称',
                dataIndex: 'organizationName',
                key: 'organizationId',
              },
              {
                title: '部门名称',
                dataIndex: 'departmentName',
                key: 'departmentId',
              },
              {
                title: '工厂名称',
                dataIndex: 'factoryName',
                key: 'factoryId',
              },
              {
                title: '车间名称',
                dataIndex: 'shopName',
                key: 'shopId',
              },
              {
                title: '工段名称',
                dataIndex: 'sectionName',
                key: 'sectionId',
              },
              {
                title: '产线名称',
                dataIndex: 'productLineName',
                key: 'productLineName',
              },
            ]}
          />
          <Divider />
          <AutoTable
            pagetitle="履历详情"
            columns={[
              {
                title: '操作时间',
                dataIndex: 'createTime',
                key: 'operateTimeList',
                width: 120,
                searchValueType: 'dateRange',
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '履历类型',
                dataIndex: 'logTypeName',
                width: 120,
                key: 'logType',
                valueType: 'select',
                options: [
                  {
                    label: '改造',
                    value: '1',
                  },
                  {
                    label: '报废',
                    value: '2',
                  },
                  {
                    label: '调拨',
                    value: '3',
                  },
                  {
                    label: '借用',
                    value: '4',
                  },
                  {
                    label: '归还',
                    value: '5',
                  },
                ],
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              },
              {
                title: '相关单号',
                dataIndex: 'relateNo',
                width: 120,
                key: 'relateNo',
                formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
                render: (text, row) => {
                  return (
                    <a
                      onClick={() => {
                        setCurrDrawer((s) => ({
                          ...s,
                          visible: true,
                          item: row,
                          val: 'only',
                          title: `${row.logTypeName}详情`,
                        }));
                      }}
                    >
                      {row.relateNo}
                    </a>
                  );
                },
              },
            ]}
            path={urlParams_resume.list}
            params={{ equipmentId: drawer?.item?.id }}
            resizeable={false}
          />
        </>
      );
    };

    return (
      <>
        <Tabs
          activeKey={activeTab}
          onChange={setactiveTab}
          items={[
            {
              label: '基础信息',
              key: 1,
              children: <BaseInfo />,
            },
            {
              label: '相关设备',
              key: 2,
              children: <Correlation />,
            },
            {
              label: '履历查询',
              key: 3,
              children: <Curritae />,
            },
          ]}
        />
      </>
    );
  };

  // 子设备
  const EditChildEquipment = () => {
    const [selectArr, setSelectArr] = useState([]);
    useEffect(() => {
      const fun = async () => {
        const result = await doFetch({
          url: '/asset/equipment/children/selected/queryList',
          params: { id: drawer?.item?.id },
        });
        // //console.log(result);
        if (!result?.data?.dataList.length == 0) {
          setSelectArr(result?.data?.dataList.map((it) => it.id));
        }
      };
      fun();
    }, []);
    const columns = [
      {
        title: '设备编号',
        dataIndex: 'equipmentNo',
        key: 'equipmentNo',
        search: false,

        width: 120,
        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      },
      {
        title: '设备名称',
        dataIndex: 'equipmentName',

        width: 120,
        key: 'equipmentName',
        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      },
      {
        title: '公司名称',

        dataIndex: 'organizationName',
        width: 120,
        key: 'organizationId',
        fieldProps: {
          placeholder: '请选择',
          showSearch: true,
        },
        valueType: 'select',
        options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      },
      {
        title: '部门名称',
        width: 120,

        valueType: 'treeSelect',
        dataIndex: 'departmentName',
        fieldProps: {
          placeholder: '请选择',
          showSearch: true,
        },
        key: 'departmentId',
        options: {
          path: '/auth/sysDepartment/query/children/tree',
          linkParams: {
            organizationId: 'parentId',
          },
        },
      },
      {
        title: '工厂名称',
        dataIndex: 'factoryName',
        key: 'factoryId',
        width: 120,

        fieldProps: {
          placeholder: '请选择',
          showSearch: true,
        },
        valueType: 'select',
        options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      },
      {
        title: '车间名称',
        dataIndex: 'shopName',

        width: 120,
        fieldProps: {
          placeholder: '请选择',
          showSearch: true,
        },
        valueType: 'select',
        options: {
          path: '/auth/sysShop/getShopSelectionByFactory',
          linkParams: {
            factoryId: '',
          },
        },
        key: 'shopId',
        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      },
      {
        title: '工段名称',
        width: 120,
        dataIndex: 'sectionName',

        key: 'sectionId',
        fieldProps: {
          placeholder: '请选择',
          showSearch: true,
        },
        valueType: 'select',
        options: {
          path: '/auth/sysSection/getAllSectionSelectionByShop',
          linkParams: {
            shopId: '',
          },
        },
      },
      {
        title: '产线名称',
        width: 120,
        dataIndex: 'productLineName',
        valueType: 'select',
        key: 'productLineName',
        fieldProps: {
          placeholder: '请选择',
          showSearch: true,
        },

        options: {
          path: '/auth/sysProductionLine/getAllProductLineSelectionByShop',
          linkParams: {
            shopId: '',
          },
        },
      },
    ];
    return (
      <>
        <ProDescriptions
          request={async () => {
            const { data } = await doFetch({
              url: urlParams.detail,
              params: { id: drawer.item.id },
            });
            return {
              success: true,
              data: data.data,
            };
          }}
          columns={[
            {
              title: '设备编号',
              dataIndex: 'equipmentNo',
              key: 'equipmentNo',
            },
            {
              title: '设备名称',
              dataIndex: 'equipmentName',
              key: 'equipmentName',
            },
            {
              title: '位置号',
              dataIndex: 'positionNo',
              key: 'positionNo',
            },
            {
              title: '公司名称',
              dataIndex: 'organizationName',
              key: 'organizationId',
            },
            {
              title: '部门名称',
              dataIndex: 'departmentName',
              key: 'departmentId',
            },
            {
              title: '工厂名称',
              dataIndex: 'factoryName',
              key: 'factoryId',
            },
            {
              title: '车间名称',
              dataIndex: 'shopName',
              key: 'shopId',
            },
            {
              title: '工段名称',
              dataIndex: 'sectionName',
              key: 'sectionId',
            },
            {
              title: '产线名称',
              dataIndex: 'productLineName',
              key: 'productLineName',
            },
          ]}
        />
        <AutoTable
          pagetitle="选择子设备"
          columns={columns}
          path={urlParams_childEquipment.list}
          params={{ id: drawer?.item?.id }}
          resizeable={false}
          rowSelection={{
            type: 'checkbox',
            selectedRowKeys: selectArr,
            // defaultSelectedRowKeys: ,
            onSelect: (record, selected, selectedRows, nativeEvent) => {
              //console.log('selectedRowKeys changed: ', record, selected, selectedRows);
              setSelectArr(() => {
                return selectedRows.map((it) => it.id);
              });
            },
            onSelectAll: (selected, selectedRows, changeRows) => {
              //console.log(selected, selectedRows, changeRows);
              if (selected) {
                let arr = selectArr.concat(changeRows.map((it) => it.id));
                setSelectArr(arr);
              } else {
                setSelectArr([]);
              }
            },
            onSelectNone: () => {
              //console.log(11);
              setSelectArr([]);
            },
          }}
        />
        <Space style={{ marginTop: 16 }}>
          <Button
            onClick={() => {
              //console.log(drawer);
              setDrawer((s) => ({
                ...s,
                visible: false,
                item: null,
                detailpath: null,
                params: null,
                val: null,
                onFinish: null,
              }));
              setSelectArr([]);
            }}
          >
            取消
          </Button>
          <Button
            type="primary"
            onClick={async () => {
              //console.log(selectArr);
              let res = await doFetch({
                url: urlParams_childEquipment.save,
                params: {
                  equipmentId: drawer?.item?.id,
                  childrenIdList: selectArr,
                },
              });
              if (res.code === '0000') {
                message.success('新增成功！');
                setDrawer((s) => ({
                  ...s,
                  visible: false,
                  item: null,
                }));
                setSelectArr([]);
                actionRef.current.reload();
              }
            }}
          >
            提交
          </Button>
        </Space>
      </>
    );
  };

  // 履历登记
  const Resume = () => {
    const [selectArr, setSelectArr] = useState([]);
    const [activeTab, setactiveTab] = useState(1);

    useEffect(() => {
      const fun = async () => {
        const result = await doFetch({
          url: '/asset/equipment/children/selected/queryList',
          params: { id: drawer?.item?.id },
        });
        // //console.log(result);
        if (!result?.data?.dataList.length == 0) {
          setSelectArr(result?.data?.dataList.map((it) => it.id));
        }
      };
      fun();
    }, []);

    const fields = {
      1: [
        {
          title: '改造日期',
          dataIndex: 'reformDate',
          key: 'reformDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '改造承包商',
          dataIndex: 'supplierId',
          key: 'supplierId',
          valueType: 'select',
          options: {
            path: '/asset/equipmentSupplier/query/selection',
            params: {},
          },
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
        },
        {
          title: '改造内容',
          dataIndex: 'reformContent',
          key: 'reformContent',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '上传文件（上限为5个）',
          key: 'urlIds',
          valueType: 'UploadDragger',
          // colProps: { span: 24 },
          fieldProps: {
            maxCount: 5,
            name: 'file',
          },
          formItemProps: {
            rules: [
              {
                required: false,
                message: '此项为必填项',
              },
            ],
          },
        },
      ],
      2: [
        {
          title: '报废日期',
          dataIndex: 'scrapDate',
          key: 'scrapDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '报废原因',
          dataIndex: 'scrapReason',
          key: 'scrapReason',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '上传文件（上限为5个）',
          key: 'urlIds',
          valueType: 'UploadDragger',
          formItemProps: {
            rules: [
              {
                required: false,
                message: '此项为必填项',
              },
            ],
          },
          fieldProps: {
            name: 'file',
            maxCount: 5,
          },
        },
      ],
      3: [
        {
          title: '调入公司',
          dataIndex: 'organizationName',
          key: 'toOrganizationId',
          valueType: 'select',
          options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '调入部门',
          valueType: 'treeSelect',
          dataIndex: 'departmentName',
          key: 'toDepartmentId',
          options: {
            path: '/auth/sysDepartment/query/children/tree',
            linkParams: {
              toOrganizationId: 'parentId',
            },
          },
        },
        {
          title: '调入工厂',
          dataIndex: 'factoryName',
          key: 'toFactoryId',
          valueType: 'select',
          options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '调入车间',
          dataIndex: 'shopName',
          valueType: 'select',
          options: {
            path: '/auth/sysShop/getShopSelectionByFactory',
            linkParams: {
              toFactoryId: 'factoryId',
            },
          },
          key: 'toShopId',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '调入工段',
          dataIndex: 'sectionName',
          key: 'toSectionId',
          valueType: 'select',
          options: {
            path: '/auth/sysSection/getAllSectionSelectionByShop',
            linkParams: {
              toShopId: 'shopId',
            },
          },
        },
        {
          title: '调入产线',
          dataIndex: 'productionLines',
          valueType: 'select',
          key: 'toProductLineId',
          options: {
            path: '/auth/sysProductionLine/getAllProductLineSelectionByShop',
            linkParams: {
              toShopId: 'shopId',
            },
          },
        },
        {
          title: '调入位置号',
          dataIndex: 'toPositionNo',
          valueType: 'input',
          key: 'toPositionNo',
        },
        {
          title: '调拨日期',
          dataIndex: 'transferDate',
          key: 'transferDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '调拨原因',
          dataIndex: 'transferReason',
          key: 'transferReason',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
      ],
      4: [
        {
          title: '借用公司',
          dataIndex: 'organizationName',
          key: 'toOrganizationId',
          valueType: 'select',
          options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '借用部门',
          valueType: 'treeSelect',
          dataIndex: 'departmentName',
          key: 'toDepartmentId',
          options: {
            path: '/auth/sysDepartment/query/children/tree',
            linkParams: {
              toOrganizationId: 'parentId',
            },
          },
        },
        {
          title: '借用工厂',
          dataIndex: 'factoryName',
          key: 'toFactoryId',
          valueType: 'select',
          options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '借用车间',
          dataIndex: 'shopName',
          valueType: 'select',
          options: {
            path: '/auth/sysShop/getShopSelectionByFactory',
            linkParams: {
              toFactoryId: 'factoryId',
            },
          },
          key: 'toShopId',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '借用工段',
          dataIndex: 'sectionName',
          key: 'toSectionId',
          valueType: 'select',
          options: {
            path: '/auth/sysSection/getAllSectionSelectionByShop',
            linkParams: {
              toShopId: 'shopId',
            },
          },
        },
        {
          title: '借用产线',
          dataIndex: 'productionLines',
          valueType: 'select',
          key: 'toProductLineId',
          options: {
            path: '/auth/sysProductionLine/getAllProductLineSelectionByShop',
            linkParams: {
              toShopId: 'shopId',
            },
          },
        },
        {
          title: '借用位置号',
          dataIndex: 'toPositionNo',
          valueType: 'input',
          key: 'toPositionNo',
        },
        {
          title: '借用日期',
          dataIndex: 'borrowDate',
          key: 'borrowDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '预计归还日期',
          dataIndex: 'planReturnDate',
          key: 'planReturnDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '借用原因',
          dataIndex: 'borrowReason',
          key: 'borrowReason',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
      ],
      5: [
        {
          title: '接收公司',
          dataIndex: 'returnOrganizationId',
          key: 'returnOrganizationId',
          valueType: 'select',
          options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '接收部门',
          valueType: 'treeSelect',
          dataIndex: 'returnDepartmentId',
          key: 'returnDepartmentId',
          options: {
            path: '/auth/sysDepartment/query/children/tree',
            linkParams: {
              returnOrganizationId: 'parentId',
            },
          },
        },
        {
          title: '接收工厂',
          dataIndex: 'returnFactoryId',
          key: 'returnFactoryId',
          valueType: 'select',
          options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '接收车间',
          dataIndex: 'returnShopId',
          valueType: 'select',
          options: {
            path: '/auth/sysShop/getShopSelectionByFactory',
            linkParams: {
              returnFactoryId: 'factoryId',
            },
          },
          key: 'returnShopId',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '接收工段',
          dataIndex: 'returnSectionId',
          key: 'returnSectionId',
          valueType: 'select',
          options: {
            path: '/auth/sysSection/getAllSectionSelectionByShop',
            linkParams: {
              returnShopId: 'shopId',
            },
          },
        },
        {
          title: '接收产线',
          dataIndex: 'returnProductLineId',
          valueType: 'select',
          key: 'returnProductLineId',
          options: {
            path: '/auth/sysProductionLine/getAllProductLineSelectionByShop',
            linkParams: {
              returnShopId: 'shopId',
            },
          },
        },
        {
          title: '接收位置号',
          dataIndex: 'returnPositionNo',
          valueType: 'input',
          key: 'returnPositionNo',
        },
        {
          title: '实际归还日期',
          dataIndex: 'realReturnDate',
          key: 'realReturnDate',
          valueType: 'date',
          formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
        },
        {
          title: '备注',
          dataIndex: 'remark',
          key: 'remark',
          valueType: 'textarea',
          formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
        },
      ],
    };

    return (
      <>
        <ProDescriptions
          request={async () => {
            const { data } = await doFetch({
              url: urlParams.detail,
              params: { id: drawer?.item?.id },
            });
            return {
              success: true,
              data: data?.data,
            };
          }}
          columns={[
            {
              title: '设备编号',
              dataIndex: 'equipmentNo',
              key: 'equipmentNo',
            },
            {
              title: '设备名称',
              dataIndex: 'equipmentName',
              key: 'equipmentName',
            },
            {
              title: '位置号',
              dataIndex: 'positionNo',
              key: 'positionNo',
            },
            {
              title: '公司名称',
              dataIndex: 'organizationName',
              key: 'organizationId',
            },
            {
              title: '部门名称',
              dataIndex: 'departmentName',
              key: 'departmentId',
            },
            {
              title: '工厂名称',
              dataIndex: 'factoryName',
              key: 'factoryId',
            },
            {
              title: '车间名称',
              dataIndex: 'shopName',
              key: 'shopId',
            },
            {
              title: '工段名称',
              dataIndex: 'sectionName',
              key: 'sectionId',
            },
            {
              title: '产线名称',
              dataIndex: 'productLineName',
              key: 'productLineName',
            },
            {
              title: '供应商',
              dataIndex: 'supplierName',
              key: 'supplierId',
            },
            {
              title: '安装投产日期',
              dataIndex: 'productDate',
              key: 'productDate',
            },
          ]}
        />
        <Divider />
        <Tabs
          activeKey={activeTab}
          onChange={setactiveTab}
          items={[
            {
              label: '改造',
              key: 1,
              children: activeTab == 1 && (
                <InitForm
                  fields={fields[activeTab]}
                  defaultFormValue={drawer?.item}
                  onFinish={async (vals) => {
                    //console.log(vals);
                    let res = await doFetch({
                      url: urlParams_resume.save,
                      params: { ...vals, type: '1', equipmentId: drawer?.item?.id },
                    });
                    if (res.code === '0000') {
                      message.success('登记成功！');
                      await setDrawer((s) => ({
                        ...s,
                        visible: false,
                        item: null,
                      }));
                      actionRef.current.reload();
                    }
                  }}
                />
              ),
            }, // remember to pass the key prop
            {
              label: '报废',
              key: 2,
              children: activeTab == 2 && (
                <InitForm
                  fields={fields[activeTab]}
                  defaultFormValue={drawer?.item}
                  onFinish={async (vals) => {
                    let res = await doFetch({
                      url: urlParams_resume.save,
                      params: { ...vals, type: '2', equipmentId: drawer?.item?.id },
                    });
                    if (res.code === '0000') {
                      message.success('登记成功！');
                      await setDrawer((s) => ({
                        ...s,
                        visible: false,
                        item: null,
                      }));
                      actionRef.current.reload();
                    }
                  }}
                />
              ),
            },
            {
              label: '调拨',
              key: 3,
              children: activeTab == 3 && (
                <InitForm
                  fields={fields[activeTab]}
                  defaultFormValue={drawer?.item}
                  onFinish={async (vals) => {
                    //console.log(vals);
                    let res = await doFetch({
                      url: urlParams_resume.save,
                      params: { ...vals, type: '3', equipmentId: drawer?.item?.id },
                    });
                    if (res.code === '0000') {
                      message.success('登记成功！');
                      await setDrawer((s) => ({
                        ...s,
                        visible: false,
                        item: null,
                      }));
                      actionRef.current.reload();
                    }
                  }}
                />
              ),
            },
            {
              label: '借用',
              key: 4,
              children: activeTab == 4 && (
                <InitForm
                  defaultFormValue={drawer?.item}
                  fields={fields[activeTab]}
                  onFinish={async (vals) => {
                    //console.log(vals);
                    let res = await doFetch({
                      url: urlParams_resume.save,
                      params: { ...vals, type: '4', equipmentId: drawer?.item?.id },
                    });
                    if (res.code === '0000') {
                      message.success('登记成功！');
                      await setDrawer((s) => ({
                        ...s,
                        visible: false,
                        item: null,
                      }));
                      actionRef.current.reload();
                    }
                  }}
                />
              ),
            },
            {
              label: '归还',
              key: 5,
              children: activeTab == 5 && (
                <InitForm
                  fields={fields[activeTab]}
                  defaultFormValue={drawer?.item}
                  onFinish={async (vals) => {
                    //console.log(vals);
                    let res = await doFetch({
                      url: urlParams_resume.save,
                      params: { ...vals, type: '5', equipmentId: drawer?.item?.id },
                    });
                    if (res.code === '0000') {
                      message.success('登记成功！');
                      await setDrawer((s) => ({
                        ...s,
                        visible: false,
                        item: null,
                      }));
                      actionRef.current.reload();
                    }
                  }}
                />
              ),
            },
          ]}
        />
      </>
    );
  };

  const columns = useMemo(() => {
    let defcolumn = getcolumns(setDrawer);
    defcolumn[1].render = (text, row) => {
      return (
        <a
          onClick={() => {
            setDrawer((s) => ({
              ...s,
              visible: true,
              type: 'detail',
              item: row,
              val: 'only',
              title: row.equipmentName + '的详细信息',
            }));
          }}
        >
          {row.equipmentName}
        </a>
      );
    };
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      fixed: 'right',
      width: 200,
      render: (text, row, _, action) => [
        edit(text, row, _, action),
        remove(text, row, _, action),
        more(text, row, _, action),
      ],
    });
  }, []);

  const onselecteTree = async (selectedKeys, e, alldata) => {
    let params = {
      treeNodeType: e.node.type,
      treeNodeKey: e.node.key,
    };
    setextraparams(params);
  };

  const selectMoreDrawerType = (type) => {
    switch (type) {
      case 'editChildEquipment':
        return <EditChildEquipment />;
      case 'resume':
        return <Resume />;
      case 'detail':
        return <Detail />;
      case 'add':
        return (
          <ExtendField
            setDrawer={setDrawer}
            drawer={drawer}
            actionRef={actionRef}
            columns={columns}
            // urlParams={urlParams}
            formId={'2'}
            onFinish={async (vals) => {
              let equipmentCharReqList = [];
              for (let i in vals) {
                if (!isNaN(Number(i))) {
                  equipmentCharReqList.push({
                    fieldId: i,
                    fieldRealValue: vals[i],
                  });
                  delete vals[i];
                }
              }
              let params = {
                ...vals,
                id: drawer?.title == '编辑' ? drawer?.item?.id : '',
                equipmentCharReqList,
              };
              //console.log(params, '!!!!');
              let res = await doFetch({
                url: urlParams.save,
                params,
              });
              if (res.code === '0000') {
                if (drawer?.title == '编辑') {
                  message.success('编辑成功！');
                } else {
                  message.success('新增成功！');
                }
                setDrawer((s) => ({
                  ...s,
                  visible: false,
                }));
                actionRef.current.reload();
              }
            }}
          />
        );
      case 'edit':
        return (
          <ExtendField
            setDrawer={setDrawer}
            drawer={drawer}
            actionRef={actionRef}
            columns={columns}
            urlParams={urlParams}
            formId={'2'}
            onFinish={async (vals) => {
              let equipmentCharReqList = [];
              for (let i in vals) {
                if (!isNaN(Number(i))) {
                  equipmentCharReqList.push({
                    fieldId: i,
                    fieldRealValue: vals[i],
                  });
                  delete vals[i];
                }
              }
              let params = {
                ...vals,
                id: drawer?.title == '编辑' ? drawer?.item?.id : '',
                equipmentCharReqList,
              };
              let res = await doFetch({
                url: urlParams.save,
                params,
              });
              if (res.code === '0000') {
                if (drawer?.title == '编辑') {
                  message.success('编辑成功！');
                } else {
                  message.success('新增成功！');
                }
                setDrawer((s) => ({
                  ...s,
                  visible: false,
                }));
                actionRef.current.reload();
              }
            }}
          />
        );
      default:
        return null;
    }
  };

  const containderef = useRef();
  return (
    <div style={{ position: 'relative' }}>
      <div className="ant-card-head" style={{ backgroundColor: 'white' }}>
        <div className="ant-card-head-wrapper">
          <div className="ant-card-head-title">
            <h3 className="page-title">设备台账</h3>
          </div>
        </div>
      </div>
      <Layout style={{ height: '100%' }} ref={containderef}>
        <Sider theme="light" width={300}>
          <TreeRender url="/auth/sysFactory/getTree" onselected={onselecteTree} noaction={true} />
        </Sider>
        <Content>
          <AutoTable
            pagetitle={<h3 style={{ marginBottom: 0, fontWeight: 400 }}>设备台账</h3>}
            columns={columns}
            path={urlParams.list}
            actionRef={actionRef}
            pageextra={'add'}
            resizeable={false}
            addconfig={{
              // access: 'sysDepartment_save',
              btn: {
                disabled: false,
                type: 'primary',
                onClick: () => {
                  setDrawer((s) => ({
                    ...s,
                    visible: true,
                    item: null,
                    title: '新增',
                    val: 'only',
                    type: 'add',
                    // onFinish: async (vals) => {
                    //   //console.log(vals);
                    //   let params = {
                    //     ...vals,
                    //   };
                    //   let res = await doFetch({
                    //     url: urlParams.save,
                    //     params,
                    //   });
                    //   if (res.code === '0000') {
                    //     message.success('新增成功！');
                    //     setDrawer((s) => ({
                    //       ...s,
                    //       visible: false,
                    //     }));
                    //     actionRef.current.reload();
                    //   }
                    // },
                  }));
                },
              },
            }}
            x={1500}
            extraparams={extraparams}
          />
        </Content>
      </Layout>
      <DrawerPro
        fields={columns}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setDrawer((s) => ({
            ...s,
            visible: false,
          }));
        }}
        {...drawer}
        colProps={{
          span: 8,
        }}
      >
        {drawer?.visible && selectMoreDrawerType(drawer?.type)}
      </DrawerPro>

      <DrawerPro
        placement="right"
        onClose={() => {
          setCurrDrawer((s) => ({
            ...s,
            visible: false,
            item: null,
          }));
        }}
        {...currDrawer}
        colProps={{
          span: 8,
        }}
      >
        <ProDescriptions
          title="设备信息"
          request={async () => {
            const { data } = await doFetch({
              url: urlParams.detail,
              params: { id: drawer?.item?.id },
            });
            return {
              success: true,
              data: data?.data,
            };
          }}
          columns={[
            {
              title: '设备编号',
              dataIndex: 'equipmentNo',
              key: 'equipmentNo',
            },
            {
              title: '设备名称',
              dataIndex: 'equipmentName',
              key: 'equipmentName',
            },
            {
              title: '位置号',
              dataIndex: 'positionNo',
              key: 'positionNo',
            },

            {
              title: '公司名称',
              dataIndex: 'organizationName',
              key: 'organizationId',
            },
            {
              title: '部门名称',
              dataIndex: 'departmentName',
              key: 'departmentId',
            },
            {
              title: '工厂名称',
              dataIndex: 'factoryName',
              key: 'factoryId',
            },
            {
              title: '车间名称',
              dataIndex: 'shopName',
              key: 'shopId',
            },
            {
              title: '工段名称',
              dataIndex: 'sectionName',
              key: 'sectionId',
            },
            {
              title: '产线名称',
              dataIndex: 'productLineName',
              key: 'productLineName',
            },
          ]}
        />
        <Divider />
        <ProDescriptions
          title={currDrawer?.item?.logTypeName + '信息'}
          column={2}
          request={async () => {
            const { data } = await doFetch({
              url: urlParams_resume.detail,
              params: { id: currDrawer?.item?.id },
            });
            return {
              success: true,
              data: data?.data?.resume,
            };
          }}
          columns={currfields[currDrawer?.item?.logType]}
        />
      </DrawerPro>
    </div>
  );
}

export default Model;
