import type { VbenFormProps } from '#/adapter/form';

import dayjs from 'dayjs';
import {getOrderStatusOption} from "#/views/business/order/product-order/api";
import {getStoreOption} from "#/views/system/store/api";

export const formOptions: VbenFormProps = {
  // 默认展开
  collapsed: false,
  schema: [
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '输入订单号',
      },
      defaultValue: '',
      fieldName: 'order_no',
      label: '订单号',
    },
    {
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        filterOption: true,
        // showSearch: true,
        // 菜单接口转options格式
        afterFetch: (data: { id: number; name: string }[]) => {
          return data.map((item: any) => ({
            label: `${item.name}【${item.id}】`,
            value: item.id,
          }));
        },
        api: getStoreOption,
        placeholder: '请选择',
      },
      fieldName: 'store_id',
      label: '门店',
    },
    {
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        filterOption: true,
        // showSearch: true,
        // 菜单接口转options格式
        afterFetch: (data: { id: number; name: string }[]) => {
          return data.map((item: any) => ({
            label: item.name,
            value: item.id,
          }));
        },
        api: getOrderStatusOption,
        placeholder: '请选择',
      },
      fieldName: 'status',
      label: '订单状态',
    },
    {
      component: 'VbenSelect',
      componentProps: {
        allowClear: true,
        filterOption: true,
        showSearch: true,
        options: [
          {
            label: '快递到家',
            value: 0,
          },
          {
            label: '诊所自提',
            value: 1,
          },
        ],
        placeholder: '请选择',
      },
      fieldName: 'delivery_method',
      label: '发货方式',
    },
    {
      component: 'VbenSelect',
      componentProps: {
        allowClear: true,
        filterOption: true,
        showSearch: true,
        options: [
          {
            label: '中药',
            value: 1,
          },
          {
            label: '西药',
            value: 2,
          },
          {
            label: '中成药',
            value: 3,
          },
          {
            label: '产品服务包',
            value: 5,
          },
        ],
        placeholder: '请选择',
      },
      fieldName: 'prescription_type',
      label: '订单类型',
    },
    {
      component: 'RangePicker',
      componentProps: {
        format: 'YYYY-MM-DD', // 确保格式与你需要的一致
      },
      defaultValue: [dayjs().startOf('month'), dayjs()],
      fieldName: 'search_time',
      label: '时间范围',
    },
  ],
  // 控制表单是否显示折叠按钮
  showCollapseButton: true,
  submitButtonOptions: {
    content: '查询',
  },
  // 是否在字段值改变时提交表单
  // submitOnChange: true,
  // submitOnChange: true,
  // 按下回车时是否提交表单
  submitOnEnter: false,
};
