import type { FormSchema } from '@/components/core/schema-form/';
import { DictEnum } from '@/enums/dictEnum';
import { useDictStore } from '@/store/modules/dict';
const { getDictItemsByCode } = useDictStore();
export const formSchemas: FormSchema<API.SaleQuotationComponentEntity>[] = [
  {
    field: 'name',
    component: 'Input',
    label: '配件名称',
    rules: [{ required: true, type: 'string' }],
    colProps: {
      span: 12,
    },
  },
  {
    field: 'componentSpecification',
    component: 'Input',
    label: '配件规格',
    colProps: {
      span: 12,
    },
  },
  {
    label: '单位',
    component: 'Select',
    field: 'unitId',
    colProps: {
      span: 12,
    },
    componentProps: ({ formInstance, schema, formModel }) => ({
      showSearch: true,
      filterOption: (input: string, option: any) => {
        return option.label.indexOf(input) >= 0;
      },
      fieldNames: {
        label: 'label',
        value: 'value',
      },
      options: getDictItemsByCode(DictEnum.Unit).map((item) => ({
        value: item.id,
        label: item.label,
      })),

      getPopupContainer: () => document.body,
      defaultActiveFirstOption: true,
    }),
  },
  {
    label: '单价',
    field: 'unitPrice',
    component: 'InputNumber',
    colProps: {
      span: 12,
    },
    helpMessage: ({ formModel }) => {
      return '成本价';
    },
  },
  {
    field: 'remark',
    component: 'InputTextArea',
    label: '备注',
    colProps: {
      span: 24,
    },
  },
];
