/**
 * 项目：-
 * 模型分组：订单管理
 * 模型名称：商品分类关联表
 * @Author: xiongwei
 * @Date: 2022-06-28 11:50:00
 */

import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import get from 'lodash.get';


const colProps = { xs: { span: 24 }, sm: { span: 24 }, lg: { span: 8 } };
const colPropsInDrawer = { span: 24 };

export const schema = {
  model: 'GoodsCategoryRelation',
  viewInPage: false,
  properties: [
    {
      field: 'id',
      label: 'ID系统自动生成',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: 'ID系统自动生成',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入ID系统自动生成！' }],
      },
      table: {
      },
    },
    {
      field: 'goodsId',
      label: '商品id',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: '商品id',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入商品id！' }],
      },
      table: {
      },
    },
    {
      field: 'goodsCategoryId',
      label: '商品分类id',
      defaultValue: 0,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: '商品分类id',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入商品分类id！' }],
      },
      table: {
      },
    },
  ],
};

const queryFields = ['id','goodsId','goodsCategoryId'];
const editFields = ['goodsId','goodsCategoryId'];
const tableFields = ['id','goodsId','goodsCategoryId'];
const descriptionFields = ['id','goodsId','goodsCategoryId'];

export const searchFormSchema: FormSchema[] = schema.properties.filter(item => queryFields.includes(item.field))
  .map(
    ({ field, label, form: { rules = [], ...formProps } }) =>
      ({
        field,
        label,
        defaultValue: undefined,
        rules: rules.filter((r) => !r.required),
        ...formProps,
      } as FormSchema),
  );

export const formSchema: FormSchema[] = schema.properties.filter(item => editFields.includes(item.field))
  .map(
    ({ field, label, defaultValue, form }) =>
      ({
        field,
        label,
        defaultValue,
        ...form,
        colProps: colPropsInDrawer,
      } as FormSchema),
  );

export const columns: BasicColumn[] = schema.properties.filter(item => tableFields.includes(item.field))
  .map(
    ({ field, label, table }) =>
      ({
        dataIndex: field,
        title: label,
        ...table,
      } as BasicColumn)
  );

export const descriptionColumns: BasicColumn[] = schema.properties.filter(item => descriptionFields.includes(item.field))
  .map(
    ({ field, label, table }) =>
      ({
        dataIndex: field,
        title: label,
        ...table,
      } as BasicColumn),
  );
