import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesWmProductSalesStatisticsApi } from '#/api/mes/wm/productsales/statistics';

import { markRaw } from 'vue';

import { getDateRangePickerDefaultProps } from '#/utils';
import { MdClientSelect } from '#/views/mes/md/client/components';
import { MdItemSelect } from '#/views/mes/md/item/components';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'clientId',
      label: '客户',
      component: markRaw(MdClientSelect),
      componentProps: {
        placeholder: '请选择客户',
      },
    },
    {
      fieldName: 'salesOrderCode',
      label: '销售订单编号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入销售订单编号',
      },
    },
    {
      fieldName: 'itemId',
      label: '产品',
      component: markRaw(MdItemSelect),
      componentProps: {
        placeholder: '请选择产品',
      },
    },
    {
      fieldName: 'shipmentDate',
      label: '发货日期',
      component: 'RangePicker',
      componentProps: {
        ...getDateRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<MesWmProductSalesStatisticsApi.Statistics>['columns'] {
  return [
    {
      field: 'clientName',
      title: '客户名称',
      minWidth: 140,
    },
    {
      field: 'salesOrderCode',
      title: '销售订单编号',
      minWidth: 160,
    },
    {
      field: 'itemCode',
      title: '产品编码',
      minWidth: 130,
    },
    {
      field: 'itemName',
      title: '产品名称',
      minWidth: 160,
    },
    {
      field: 'specification',
      title: '规格型号',
      minWidth: 130,
    },
    {
      field: 'unitMeasureName',
      title: '单位',
      width: 90,
      align: 'center',
    },
    {
      field: 'totalQuantity',
      title: '出库总数量',
      width: 120,
      align: 'right',
    },
    {
      field: 'totalBoxCount',
      title: '总箱数',
      width: 100,
      align: 'right',
    },
    {
      field: 'shipmentCount',
      title: '发货次数',
      width: 100,
      align: 'center',
    },
    {
      field: 'lastShipmentDate',
      title: '最后发货时间',
      width: 180,
      formatter: 'formatDate',
    },
  ];
}
