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

function getcolumns(type) {
  const columns = [
    {
      title: '备件料号',
      dataIndex: 'sparePartNo',
      key: 'sparePartNo',
      editable: false,
    },
    {
      title: '备件名称',
      dataIndex: 'sparePartName',
      key: 'sparePartName',
      editable: false,
    },
    {
      title: '可用库存',
      dataIndex: 'usedStock',
      key: 'usedStock',
      editable: false,
      hideInSearch: true,
    },
    {
      title: '申请数量',
      dataIndex: 'operateNum',
      key: 'operateNum',
      hideInSearch: true,
      valueType: 'digit',
      fieldProps: {
        precision: 3,
      },
      formItemProps: {
        rules: [
          {
            required: true,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '库存单位',
      dataIndex: 'unit',
      editable: false,
      hideInSearch: true,
    },
  ];
  return [
    {
      tab: '未完成',
      key: '1',
      columns: [
        {
          title: '领用单号',
          dataIndex: 'taskNo',
          key: 'taskNo',
        },
        {
          title: '申请原因',
          dataIndex: 'applyReasonName',
          key: 'applyReason',
          valueType: 'select',
          options: [
            {
              label: '备库领用',
              value: 1,
            },
            {
              label: '维修领用',
              value: 2,
            },
            {
              label: '保养领用',
              value: 3,
            },
            {
              label: '点检领用',
              value: 4,
            },
          ],
        },
        {
          title: '入库仓库',
          dataIndex: 'inWarehouseName',
          key: 'inWarehouseId',
          valueType: 'select',
          options: {
            path: '/auth/sysShop/getUserShopSelection',
            params: {},
          },
          hideInForm: type == 1,
        },
        {
          title: '出库仓库',
          dataIndex: 'outWarehouseName',
          key: 'outWarehouseName',
          hideInForm: true,
        },
        {
          title: '备件种类',
          dataIndex: 'spareTypeNum',
          key: 'spareTypeNum',
          hideInForm: true,
          hideInSearch: true,
        },
        {
          title: '相关单号',
          dataIndex: 'relationNo',
          key: 'relationNo',
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          key: 'createTimeList',
          hideInForm: true,
          valueType: 'dateRange',
          render: (text, row) => {
            return <span>{row?.createTime}</span>;
          },
          hideInForm: true,
        },
        {
          title: '出库单号',
          dataIndex: 'outWarehouseTaskNo',
          key: 'outWarehouseTaskNo',
          hideInForm: true,
        },
        {
          dataIndex: 'remark',
          valueType: 'textarea',
          title: '备注',
          key: 'remark',
          colProps: {
            span: 24,
          },
          hideInTable: true,
          hideInSearch: true,
        },
        {
          title: '状态',
          dataIndex: 'statusName',
          key: 'status',
          hideInForm: true,
          valueType: 'select',
          options: [
            {
              label: '待审批',
              value: 1,
            },
            {
              label: '出库中',
              value: 2,
            },
          ],
        },
        {
          title: '备件信息',
          dataIndex: 'details',
          key: 'details',
          valueType: 'split',
        },
        {
          title: '备件',
          dataIndex: 'detailsList',
          key: 'detailsList',
          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?.detailsList}
              />
            );
          },
        },
        {
          title: '审批信息',
          dataIndex: 'cdetails',
          key: 'cdetails',
          valueType: 'split',
          hideInForm: true,
        },
        {
          title: '审批人',
          dataIndex: 'approvalUserName',
          key: 'approvalUserName',
          hideInTable: true,
          hideInForm: true,
          hideInSearch: true,
        },
        {
          title: '审批时间',
          dataIndex: 'approvalTime',
          key: 'approvalTime',
          hideInSearch: true,
          hideInTable: true,
          hideInForm: true,
        },
        {
          title: '审批结果',
          dataIndex: 'approvalResultName',
          key: 'approvalResultName',
          hideInSearch: true,
          hideInTable: true,
          hideInForm: true,
        },
        {
          title: '审批备注',
          dataIndex: 'approvalRemark',
          key: 'approvalRemark',
          hideInSearch: true,
          hideInTable: true,
          hideInForm: true,
        },
      ],
      pathconfig: {
        enableadd: true,
        enableedit: true,
        enabledelete: true,
        enabledetail: true,
        add: '/sparepart/spareApplyTask/save',
        edit: '',
        list: '/sparepart/spareApplyTask/queryNoComplete',
        delete: '/sparepart/spareApplyTask/deleteById',
        detail: '/sparepart/spareApplyTask/queryDetails',
      },
    },
    {
      tab: '已完成',
      key: '2',
      columns: [
        {
          title: '领用单号',
          dataIndex: 'taskNo',
          key: 'taskNo',
        },
        {
          title: '申请原因',
          dataIndex: 'applyReasonName',
          key: 'applyReason',
          valueType: 'select',
          options: [
            {
              label: '备库领用',
              value: 1,
            },
            {
              label: '维修领用',
              value: 2,
            },
            {
              label: '保养领用',
              value: 3,
            },
            {
              label: '点检领用',
              value: 4,
            },
          ],
        },
        {
          title: '入库仓库',
          dataIndex: 'inWarehouseName',
          key: 'inWarehouseId',
          valueType: 'select',
          options: {
            path: '/auth/sysShop/getUserShopSelection',
            params: {},
          },
          hideInForm: type == 1,
        },
        {
          title: '出库仓库',
          dataIndex: 'outWarehouseName',
          key: 'outWarehouseName',
          hideInForm: true,
        },
        {
          title: '备件种类',
          dataIndex: 'spareTypeNum',
          key: 'spareTypeNum',
          hideInForm: true,
          hideInSearch: true,
        },
        {
          title: '相关单号',
          dataIndex: 'relationNo',
          key: 'relationNo',
        },
        {
          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: 'outWarehouseTaskNo',
          key: 'outWarehouseTaskNo',
          hideInForm: true,
        },
        {
          dataIndex: 'remark',
          valueType: 'textarea',
          title: '备注',
          key: 'remark',
          colProps: {
            span: 24,
          },
          hideInTable: true,
          hideInSearch: true,
        },
        {
          title: '状态',
          dataIndex: 'statusName',
          key: 'status',
          hideInForm: true,
          valueType: 'select',
          options: [
            {
              label: '已驳回',
              value: 3,
            },
            {
              label: '处理失败  ',
              value: 4,
            },
            {
              label: '已完成',
              value: 5,
            },
          ],
        },
        {
          title: '备件信息',
          dataIndex: 'details',
          key: 'details',
          valueType: 'split',
          hideInForm: true,
        },
        {
          title: '备件',
          dataIndex: 'detailsList',
          key: 'detailsList',
          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?.detailsList}
              />
            );
          },
        },

        {
          title: '审批信息',
          dataIndex: 'cdetails',
          key: 'cdetails',
          valueType: 'split',
          hideInForm: true,
        },
        {
          title: '审批人',
          dataIndex: 'approvalUserName',
          key: 'approvalUserName',
          hideInTable: true,
          hideInForm: true,
          hideInSearch: true,
        },
        {
          title: '审批时间',
          dataIndex: 'approvalTime',
          key: 'approvalTime',
          hideInSearch: true,
          hideInTable: true,
          hideInForm: true,
        },
        {
          title: '审批结果',
          dataIndex: 'approvalResultName',
          key: 'approvalResultName',
          hideInSearch: true,
          hideInTable: true,
          hideInForm: true,
        },
        {
          title: '审批备注',
          dataIndex: 'approvalRemark',
          key: 'approvalRemark',
          hideInSearch: true,
          hideInTable: true,
          hideInForm: true,
        },
      ],
      pathconfig: {
        enableadd: true,
        enableedit: false,
        enabledelete: false,
        enabledetail: true,
        add: '/sparepart/spareApplyTask/save',
        edit: '',
        list: '/sparepart/spareApplyTask/queryYesComplete',
        delete: '',
        detail: '/sparepart/spareApplyTask/queryDetails',
      },
    },
  ];
}
export default getcolumns;
