import AutoTable from '@/components/AutoTable/mtable';

function ExtraTable({ dataSource }) {
  return (
    <div style={{ padding: '4px 4px 4px 36px' }}>
      <AutoTable
        dataSource={dataSource}
        pagination={false}
        resizeable={false}
        columns={[
          { title: '供应商编号', dataIndex: 'supplierNo', key: 'supplierNo', width: 200 },
          { title: '供应商名称', dataIndex: 'supplierName', key: 'supplierName', width: 200 },
          {
            title: '库存数量',
            dataIndex: 'actualStock',
            key: 'actualStock',
            hideInSearch: true,
            width: 200,
          },
          { title: '下架数量', dataIndex: 'operateNum', key: 'operateNum', hideInSearch: true },
        ]}
      />
    </div>
  );
}

function getcolumns(setdrawer) {
  const columns = [
    {
      title: '备件料号',
      dataIndex: 'sparePartNo',
      key: 'sparePartNo',
      editable: false,
      width: 235,
    },
    {
      title: '备件名称',
      dataIndex: 'sparePartName',
      key: 'sparePartName',
      editable: false,
      width: 200,
    },
    {
      title: '可用库存',
      dataIndex: 'usedStock',
      key: 'usedStock',
      editable: false,
      hideInSearch: true,
      width: 200,
    },
    {
      title: '出库数量',
      dataIndex: 'operateNum',
      key: 'operateNum',
      hideInSearch: true,
      valueType: 'digit',
      fieldProps: {
        precision: 3,
      },
      width: 200,
    },
    {
      title: '库存单位',
      dataIndex: 'unit',
      editable: false,
      hideInSearch: true,
    },
  ];

  return [
    {
      tab: '未完成',
      key: '1',
      columns: [
        {
          title: '出库单号',
          dataIndex: 'taskNo',
          key: 'taskNo',
        },
        {
          title: '出库类型',
          dataIndex: 'outTypeName',
          key: 'outType',
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
          valueType: 'select',
          options: [
            {
              label: '销售出库',
              value: '1',
            },
            {
              label: '报废出库',
              value: '2',
            },
            {
              label: '其它出库',
              value: '3',
            },
            {
              label: '备件申领出库',
              value: '4',
            },
          ],
        },
        {
          title: '入库仓库',
          dataIndex: 'inWarehouseName',
          key: 'inWarehouseName',
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
        },
        {
          title: '出库仓库',
          dataIndex: 'outWarehouseName',
          key: 'outWarehouseName',
          hideInForm: true,
        },
        {
          title: '备件种类',
          dataIndex: 'spareTypeNum',
          key: 'spareTypeNum',
          hideInSearch: true,
          hideInForm: true,
        },
        {
          title: '相关单号',
          dataIndex: 'relationNo',
          key: 'relationNo',
        },
        {
          title: '备注',
          dataIndex: 'remark',
          key: 'remark',
          colProps: {
            span: 24,
          },
          hideInSearch: true,
          valueType: 'textarea',
        },
        {
          title: '创建人',
          dataIndex: 'createUserName',
          key: 'createUserId',
          hideInForm: true,
          valueType: 'select',
          fieldProps: {
            showSearch: true,
          },
          options: {
            path: '/auth/sysUser/selection',
            params: {},
          },
          hideInForm: true,
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          key: 'createTimeList',
          hideInForm: true,
          valueType: 'dateRange',
          render: (text, row) => {
            return <span>{row?.createTime}</span>;
          },
          hideInForm: true,
        },
        {
          title: '备件信息',
          dataIndex: 'details',
          key: 'details',
          valueType: 'split',
        },
        {
          title: '备件',
          dataIndex: 'taskSpareList',
          key: 'taskSpareList',
          valueType: 'formSelectList',
          colProps: {
            span: 24,
          },
          columns,
          span: 12,
          path: '/sparepart/spareStock/queryByOperate',
          hideInSearch: true,
          hideInTable: true,
          rowName: 'sparePartName',
          render: (text, row) => {
            return (
              <AutoTable
                columns={columns?.map((it) => ({
                  ...it,
                  hideInSearch: true,
                }))}
                dataSource={row?.taskSpareList}
                resizeable={false}
                expandable={{
                  expandedRowRender: (record) => (
                    <ExtraTable dataSource={record?.taskSpareSupplierList ?? []} />
                  ),
                }}
              />
            );
          },
        },
      ],
      pathconfig: {
        enableadd: true,
        enableedit: true,
        enabledelete: true,
        enabledetail: true,
        add: '/sparepart/outWarehouseTask/save',
        edit: '',
        list: '/sparepart/outWarehouseTask/queryNoComplete',
        delete: '',
        detail: '/sparepart/outWarehouseTask/queryDetails',
      },
    },
    {
      tab: '已完成',
      key: '2',
      columns: [
        {
          title: '出库单号',
          dataIndex: 'taskNo',
          key: 'taskNo',
        },
        {
          title: '出库类型',
          dataIndex: 'outTypeName',
          key: 'outType',
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
          valueType: 'select',
          options: [
            {
              label: '销售出库',
              value: '1',
            },
            {
              label: '报废出库',
              value: '2',
            },
            {
              label: '其它出库',
              value: '3',
            },
            {
              label: '备件申领出库',
              value: '4',
            },
          ],
        },
        {
          title: '入库仓库',
          dataIndex: 'inWarehouseName',
          key: 'inWarehouseName',
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
        },
        {
          title: '出库仓库',
          dataIndex: 'outWarehouseName',
          key: 'outWarehouseName',
          hideInForm: true,
        },
        {
          title: '备件种类',
          dataIndex: 'spareTypeNum',
          key: 'spareTypeNum',
          hideInSearch: true,
          hideInForm: true,
        },
        {
          title: '相关单号',
          dataIndex: 'relationNo',
          key: 'relationNo',
        },
        {
          title: '备注',
          dataIndex: 'remark',
          key: 'remark',
          colProps: {
            span: 24,
          },
          hideInSearch: true,
          valueType: 'textarea',
        },
        {
          title: '创建人',
          dataIndex: 'createUserName',
          key: 'createUserId',
          hideInForm: true,
          valueType: 'select',
          fieldProps: {
            showSearch: true,
          },
          options: {
            path: '/auth/sysUser/selection',
            params: {},
          },
          hideInForm: true,
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          key: 'createTimeList',
          hideInForm: true,
          valueType: 'dateRange',
          render: (text, row) => {
            return <span>{row?.createTime}</span>;
          },
          hideInForm: true,
        },
        {
          title: '完成时间',
          dataIndex: 'completeTime',
          key: 'completeTimeList',
          hideInForm: true,
          valueType: 'dateRange',
          render: (text, row) => {
            return <span>{row?.completeTime}</span>;
          },
          hideInForm: true,
        },
        {
          title: '备件信息',
          dataIndex: 'details',
          key: 'details',
          valueType: 'split',
        },
        {
          title: '备件',
          dataIndex: 'taskSpareList',
          key: 'taskSpareList',
          valueType: 'formSelectList',
          colProps: {
            span: 24,
          },
          columns,
          span: 12,
          path: '/sparepart/spareStock/queryByOperate',
          hideInSearch: true,
          hideInTable: true,
          rowName: 'sparePartName',
          render: (text, row) => {
            return (
              <AutoTable
                columns={columns?.map((it) => ({
                  ...it,
                  hideInSearch: true,
                }))}
                resizeable={false}
                dataSource={row?.taskSpareList}
                expandable={{
                  expandedRowRender: (record) => (
                    <ExtraTable dataSource={record?.taskSpareSupplierList ?? []} />
                  ),
                }}
              />
            );
          },
        },
        {
          dataIndex: 'splias',
          valueType: 'split',
          title: '出库/关单信息',
          key: 'splisa',
        },
        {
          dataIndex: 'statusName',
          valueType: 'select',
          title: '状态',
          key: 'status',
          options: [
            {
              label: '已出库',
              value: 2,
            },
            {
              label: '已关单',
              value: 3,
            },
          ],
          hideInForm: true,
        },
        {
          title: '操作人',
          dataIndex: 'operateUserName',
          key: 'operateUserName',
          hideInSearch: true,
          hideInTable: true,
          hideInForm: true,
        },
        {
          title: '操作时间',
          dataIndex: 'operateTime',
          key: 'operateTime',
          hideInSearch: true,
          hideInTable: true,
          hideInForm: true,
        },
      ],
      pathconfig: {
        enableadd: true,
        enableedit: false,
        enabledelete: false,
        enabledetail: true,
        add: '/sparepart/outWarehouseTask/save',
        edit: '',
        list: '/sparepart/outWarehouseTask/queryYesComplete',
        delete: '',
        detail: '/sparepart/outWarehouseTask/queryDetails',
      },
    },
  ];
}
export default getcolumns;
