import { BasicColumn } from '@jdlinker/ui';
import { FormSchema } from '@jdlinker/ui';
import { Tag } from 'ant-design-vue';
import { h } from 'vue';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '参数名',
    align: 'center',
    dataIndex: 'configName'
  },
  {
    title: '参数键',
    align: 'center',
    dataIndex: 'configKey'
  },
  {
    title: '参数值',
    align: 'center',
    dataIndex: 'configValue',
    width: 140
  },
  {
    title: '系统内置',
    align: 'center',
    dataIndex: 'isSys',
    width: 120,
    customRender: ({ record }) => {
      const status = record.isSys;
      const enable = ~~status === 1;
      const color = enable ? 'green' : 'red';
      const text = enable ? '是' : '否';
      return h(Tag, { color: color }, () => text);
    }
  }
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '参数名',
    field: 'configName',
    component: 'JInput',
    colProps: { span: 8 }
  },
  {
    label: '参数键',
    field: 'configKey',
    component: 'JInput',
    colProps: { span: 8 }
  }
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '参数名',
    field: 'configName',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: '请输入名称!' }];
    }
  },
  {
    label: '参数键',
    field: 'configKey',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: '请输入参数键!' }];
    }
  },
  {
    label: '参数值',
    field: 'configValue',
    component: 'Input'
  },
  {
    label: '系统内置',
    field: 'isSys',
    component: 'RadioGroup',
    componentProps: {
      options: [
        {
          label: '是',
          value: '1'
        },
        {
          label: '否',
          value: '0'
        }
      ]
    },
    defaultValue: '1',
    required: true
  },
  {
    label: '备注信息',
    field: 'remarks',
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
      rows: 4
    },
    colProps: { lg: 24, md: 24 }
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  }
];
