/**
 * 项目：-
 * 模型分组：订单管理
 * 模型名称：产品商品关联表
 * @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: 'ProductGoodsRelation',
  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: 'productId',
      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: 'quantity',
      label: '数量',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: '数量',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入数量！' }],
      },
      table: {
      },
    },
  ],
};

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

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),
  );
