import { dateFormatter } from '@/utils/formatTime'

const statusOptions = [
  { label: '审核中', value: 1 },
  { label: '已通过', value: 2 },
  { label: '已驳回', value: 3 }
]

const crudSchemas = reactive([
  {
    label: '产品名称',
    field: 'productName',
    isSearch: true,
    isTable: true
  },
  {
    label: '规格名称',
    field: 'specsName',
    isSearch: true,
    isTable: true
  },
  {
    label: '供应商',
    field: 'supplier',
    isSearch: true,
    isTable: true
  },
  {
    label: '采购数量',
    field: 'num',
    isSearch: false,
    isTable: true
  },
  {
    label: '采购单价',
    field: 'unitPrice',
    isSearch: false,
    isTable: true
  },
  {
    label: '总金额',
    field: 'totalPrice',
    isSearch: false,
    isTable: true
  },
  {
    label: '仓库',
    field: 'warehouseName',
    isSearch: false,
    isTable: true
  },
  {
    label: '申请人',
    field: 'applyUserName',
    isSearch: true,
    isTable: true
  },
  {
    label: '申请时间',
    field: 'applyTime',
    isSearch: true,
    isTable: true,
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD'
    },
    search: {
      component: 'DatePicker',
      componentProps: {
        type: 'daterange',
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
        startPlaceholder: '申请时间',
        endPlaceholder: '申请时间'
      }
    }
  },
  {
    label: '审核人',
    field: 'checkUserName',
    isSearch: true,
    isTable: true
  },
  {
    label: '审核时间',
    field: 'checkTime',
    isSearch: true,
    isTable: true,
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD'
    },
    search: {
      component: 'DatePicker',
      componentProps: {
        type: 'daterange',
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
        startPlaceholder: '审核时间',
        endPlaceholder: '审核时间'
      }
    }
  },
  {
    label: '采购状态',
    field: 'auditStatus',
    isSearch: true,
    isTable: true,
    search: {
      component: 'Select',
      api: () => statusOptions,
      componentProps: {
        optionsAlias: {
          labelField: 'label',
          valueField: 'value'
        }
      }
    },
    table: {
      field: 'auditStatusName',
      fixed: 'right'
    }
  },
  {
    label: '备注',
    field: 'remark',
    isSearch: false,
    isTable: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
