import { FormProps, BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Form/index';
import { adapt } from '/@/utils/adapt';
import moment from 'moment';

const adaptWidth = adapt();

export const columns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'dues.id',
    editComponentProps: {
      prefix: '$',
    },
    width: 80,
    sorter: true,
  },
  {
    title: '会费年份',
    dataIndex: 'dues.year',
    width: 90,
    sorter: true,
  },
  {
    title: '会员职务',
    dataIndex: 'dues.duty',
    width: 130,
    customRender({ record }) {
      const options = ['会长', '副会长', '秘书长', '副秘书长', '理事', '会员'];
      return options[record['dues.duty']];
    },
    sorter: true,
  },
  {
    title: '金额',
    dataIndex: 'dues.money',
    width: 160,
    sorter: true,
  },
  {
    title: '操作员',
    dataIndex: 'admin.nickname',
    width: 150,
    sorter: true,
  },
  {
    title: '备注',
    dataIndex: 'dues.remark',
    width: 160,
    sorter: true,
  },
  {
    title: '创建日期',
    dataIndex: 'dues.createtime',
    width: 160,
    customRender({ record }) {
      return moment(record['dues.createtime'] * 1000).format('YYYY-MM-DD HH:mm:ss');
    },
    sorter: true,
  },
];

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      {
        field: `id`,
        label: `ID`,
        component: 'Input',
        componentProps: {
          placeholder: 'ID',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `year`,
        label: `会费年份`,
        component: 'Input',
        componentProps: {
          placeholder: '会费年份',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `duty`,
        label: `会员职务`,
        component: 'Select',
        componentProps: {
          options: [
            {
              label: '会长',
              value: 0,
            },
            {
              label: '副会长',
              value: 1,
            },
            {
              label: '秘书长',
              value: 2,
            },
            {
              label: '副秘书长',
              value: 3,
            },
            {
              label: '理事',
              value: 4,
            },
            {
              label: '会员',
              value: 5,
            },
          ],
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `remark`,
        label: `备注`,
        component: 'Input',
        componentProps: {
          placeholder: '备注',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `createdate`,
        label: `创建日期`,
        component: 'DatePicker',
        componentProps: {
          placeholder: '创建日期',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}

// =================popup================================
export const schemas: FormSchema[] = [
  {
    field: 'year',
    component: 'Input',
    label: '会费年份',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '会费年份',
    },
    required: true,
  },
  {
    field: 'duty',
    component: 'Select',
    label: '会员职务',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '会员职务',
      options: [
        {
          label: '会长',
          value: 0,
        },
        {
          label: '副会长',
          value: 1,
        },
        {
          label: '秘书长',
          value: 2,
        },
        {
          label: '副秘书长',
          value: 3,
        },
        {
          label: '理事',
          value: 4,
        },
        {
          label: '会员',
          value: 5,
        },
      ],
    },
    required: true,
  },
  {
    field: 'money',
    component: 'Input',
    label: '金额',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      type: 'number',
      placeholder: '金额',
    },
    required: true,
  },
  {
    field: 'remark',
    component: 'Input',
    label: '备注',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '备注',
    },
  },
];
