/**
 * 项目：-
 * 模型分组：系统管理
 * 模型名称：经销商产品线表
 * @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: 'DistributorProductLine',
  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: 'distributorId',
      label: '经销商表id',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: '经销商表id',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入经销商表id！' }],
      },
      table: {},
    },
    {
      field: 'name',
      label: '名称',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: '名称',
        },
        colProps,
        component: 'Input',
        rules: [{ required: true, message: '请输入名称！' }],
      },
      table: {},
    },
    {
      field: 'thirdId',
      label: '关联第三方id',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: true,
          placeholder: '关联第三方id',
        },
        colProps,
        component: 'Input',
      },
      table: {},
    },
    {
      field: 'remark',
      label: '描述',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: true,
          placeholder: '描述',
        },
        colProps,
        component: 'Input',
      },
      table: {},
    },
    {
      field: 'createTime',
      label: '创建时间',
      defaultValue: undefined,
      form: {
        colProps,
        componentProps: {
          allowClear: false,
          placeholder: ['开始时间', '结束时间'],
          format: 'YYYY-MM-DD',
          showTime: false,
        },
        component: 'RangePicker',
        rules: [{ required: true, message: '请输入CreateTime！' }],
      },
      table: {},
    },
    {
      field: 'updateTime',
      label: '更新时间',
      defaultValue: undefined,
      form: {
        colProps,
        componentProps: {
          allowClear: false,
          placeholder: ['开始时间', '结束时间'],
          format: 'YYYY-MM-DD',
          showTime: false,
        },
        component: 'RangePicker',
        rules: [{ required: true, message: '请输入UpdateTime！' }],
      },
      table: {},
    },
  ],
};

const queryFields = ['id', 'distributorId', 'name', 'thirdId', 'remark', 'createTime', 'updateTime'];
const editFields = ['distributorId', 'name', 'thirdId', 'remark'];
const tableFields = ['id', 'distributorId', 'name', 'thirdId', 'remark', 'createTime', 'updateTime'];
const descriptionFields = ['id', 'distributorId', 'name', 'thirdId', 'remark', 'createTime', 'updateTime'];

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