import { BasicColumn, FormSchema, render, JVxeTypes, JVxeColumn } from '@jdlinker/ui';
export const columns: BasicColumn[] = [
  {
    title: '表类型',
    dataIndex: 'tableType',
    width: 120,
    customRender: ({ text }) => {
      return render.renderDict(text, 'table_type');
    }
  },
  {
    title: '表名',
    dataIndex: 'tableName',
    width: 150
  },
  {
    title: '表描述',
    dataIndex: 'tableTxt',
    width: 200
  },
  {
    title: '版本',
    dataIndex: 'tableVersion',
    width: 80
  },
  {
    title: '同步状态',
    dataIndex: 'isDbSynch',
    width: 80,
    sorter: true,
    customRender: ({ record }) => {
      const color = record.isDbSynch == 'Y' ? 'green' : 'red';
      const text = record.isDbSynch ? (record.isDbSynch == 'Y' ? '已同步' : '未同步') : '';
      return render.renderTag(text, color);
    }
  },
  {
    title: '创建时间',
    width: 150,
    dataIndex: 'createTime'
  }
];

export const dabaseColumns: BasicColumn[] = [
  {
    title: '表名',
    dataIndex: 'id'
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '表名',
    field: 'tableName',
    component: 'Input',
    colProps: { span: 6 }
  },
  {
    label: '表类型',
    field: 'tableType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'table_type',
      placeholder: '请选择表类型',
      stringToNumber: true
    },
    colProps: { span: 6 }
  }
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false
  },
  {
    label: '表名',
    field: 'tableName',
    required: true,
    component: 'Input',
    colProps: {
      span: 6
    }
  },
  {
    label: '表描述',
    field: 'tableTxt',
    required: true,
    component: 'Input',
    colProps: {
      span: 6
    }
  },
  // {
  //   label: '作者',
  //   field: 'author',
  //   defaultValue: 'juload',
  //   component: 'Input',
  //   colProps: {
  //     span: 6,
  //   },
  // },
  {
    label: '表类型',
    field: 'tableType',
    component: 'JDictSelectTag',
    colProps: {
      span: 6
    },
    defaultValue: 0,
    componentProps: {
      dictCode: 'table_type',
      stringToNumber: true
    }
  },
  {
    label: '映射关系',
    field: 'relationType',
    component: 'Select',
    colProps: {
      span: 6
    },
    show: ({ values }) => {
      return values.tableType === 3;
    },
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: '一对一',
          value: 1
        },
        {
          label: '一对多',
          value: 0
        }
      ]
    }
  },
  {
    label: '序号',
    field: 'tabOrderNum',
    component: 'InputNumber',
    colProps: {
      span: 6
    },
    show: ({ values }) => {
      return values.tableType === 3;
    }
  },
  {
    label: '主键策略',
    field: 'idType',
    component: 'Select',
    colProps: {
      span: 6
    },
    defaultValue: 'UUID',
    componentProps: {
      options: [
        {
          label: 'ID_WORKER(分布式自增)',
          value: 'UUID'
        }
      ]
    }
  },
  {
    label: '显示复选框',
    field: 'isCheckbox',
    component: 'Select',
    colProps: {
      span: 6
    },
    defaultValue: 'Y',
    componentProps: {
      options: [
        {
          label: '是',
          value: 'Y'
        },
        {
          label: '否',
          value: 'N'
        }
      ]
    }
  },
  {
    label: '主题模板',
    field: 'themeTemplate',
    component: 'Select',
    colProps: {
      span: 6
    },
    defaultValue: 'normal',
    componentProps: {
      options: [
        {
          label: '默认主题',
          value: 'normal'
        },
        {
          label: 'ERP主题(一对多)',
          value: 'erp'
        },
        {
          label: '内嵌子表主题(一对多)',
          value: 'innerTable'
        },
        {
          label: 'TAB主题(一对多)',
          value: 'tab'
        }
      ]
    }
  },
  {
    label: '表单风格',
    field: 'formTemplate',
    component: 'Select',
    colProps: {
      span: 6
    },
    defaultValue: '1',
    componentProps: {
      options: [
        {
          label: '一列',
          value: '1'
        },
        {
          label: '两列',
          value: '2'
        },
        {
          label: '三列',
          value: '3'
        },
        {
          label: '四列',
          value: '4'
        }
      ]
    }
  },
  {
    label: '滚动条',
    field: 'scroll',
    component: 'Select',
    colProps: {
      span: 6
    },
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: '有',
          value: 1
        },
        {
          label: '无',
          value: 0
        }
      ]
    }
  },
  {
    label: '是否分页',
    field: 'isPage',
    component: 'Select',
    colProps: {
      span: 6
    },
    defaultValue: 'Y',
    componentProps: {
      options: [
        {
          label: '是',
          value: 'Y'
        },
        {
          label: '否',
          value: 'N'
        }
      ]
    }
  },
  {
    label: '是否树',
    field: 'isTree',
    component: 'Select',
    colProps: {
      span: 6
    },
    defaultValue: 'N',
    componentProps: {
      options: [
        {
          label: '是',
          value: 'Y'
        },
        {
          label: '否',
          value: 'N'
        }
      ]
    }
  }
  // {
  //   label: '附表',
  //   field: 'subTableStr',
  //   required: true,
  //   component: 'Input',
  //   colProps: {
  //     span: 12
  //   },
  //   dynamicDisabled: true
  // }
  //
  // {
  //   label: '表单类型',
  //   field: 'formType',
  //   component: 'Select',
  //   colProps: {
  //     span: 6,
  //   },
  //   required: true,
  //   defaultValue: 'drawer',
  //   componentProps: {
  //     options: [
  //       {
  //         label: 'Drawer抽屉',
  //         value: 'drawer',
  //       },
  //       {
  //         label: 'Modal对话框',
  //         value: 'modal',
  //       },
  //     ],
  //   },
  // },
  // {
  //   label: '生成方法',
  //   field: 'genMethod',
  //   component: 'JCheckbox',
  //   defaultValue: 'page,detail,add,update,del,batchDel,import,export',
  //   required: true,
  //   colProps: {
  //     span: 18,
  //   },
  //   componentProps: {
  //     options: [
  //       { label: '分页', value: 'page' },
  //       { label: '详情', value: 'detail' },
  //       { label: '新增', value: 'add' },
  //       { label: '修改', value: 'update' },
  //       { label: '删除', value: 'del' },
  //       { label: '批量删除', value: 'batchDel' },
  //       { label: '导入', value: 'import' },
  //       { label: '导出', value: 'export' },
  //     ],
  //   },
  // },
];

export const dbInfoColumn: JVxeColumn[] = [
  {
    title: 'ID',
    key: 'id',
    type: JVxeTypes.hidden
  },
  {
    title: '字段名称',
    key: 'dbFieldName',
    type: JVxeTypes.input,
    defaultValue: '',
    validateRules: [
      {
        required: true,
        message: '请输入${title}'
      }
    ]
  },
  {
    title: '字段备注',
    key: 'dbFieldTxt',
    type: JVxeTypes.input,
    defaultValue: '',
    placeholder: '请输入${title}',
    validateRules: [
      {
        required: true,
        message: '请输入${title}'
      }
    ]
  },
  {
    title: '字段长度',
    key: 'dbLength',
    type: JVxeTypes.inputNumber,
    defaultValue: 32,
    validateRules: [
      {
        required: true,
        message: '请输入${title}'
      }
    ]
  },
  {
    title: '小数点',
    key: 'dbPointLength',
    type: JVxeTypes.inputNumber,
    defaultValue: 0
  },
  {
    title: '默认值',
    key: 'dbDefaultVal',
    type: JVxeTypes.input,
    defaultValue: '',
    placeholder: '请输入${title}'
  },
  {
    title: '字段类型',
    key: 'dbType',
    type: JVxeTypes.select,
    defaultValue: 'string',
    options: [
      { title: 'String', value: 'string' },
      { title: 'Integer', value: 'int' },
      { title: 'Double', value: 'double' },
      { title: 'Boolean', value: 'boolean' },
      { title: 'Date', value: 'date' },
      { title: 'DateTime', value: 'datetime' },
      { title: 'BigDecimal', value: 'bigDecimal' },
      { title: 'Text', value: 'text' },
      { title: 'Blob', value: 'blob' }
    ],
    placeholder: '请选择'
  },
  {
    title: '主键',
    key: 'dbIsKey',
    type: JVxeTypes.checkbox,
    customValue: [1, 0],
    defaultChecked: false
  },
  {
    title: '允许空值',
    key: 'dbIsNull',
    type: JVxeTypes.checkbox,
    defaultValue: true,
    customValue: [1, 0],
    defaultChecked: true
  }
];

export const vueInfoColumn: JVxeColumn[] = [
  {
    title: 'ID',
    key: 'id',
    type: JVxeTypes.hidden
  },
  {
    title: '字段名称',
    key: 'dbFieldName',
    type: JVxeTypes.normal
  },
  {
    title: '字段备注',
    key: 'dbFieldTxt',
    type: JVxeTypes.normal
  },
  {
    title: '表单显示',
    key: 'isShowForm',
    type: JVxeTypes.checkbox,
    customValue: [1, 0],
    defaultChecked: false
  },
  {
    title: '列表显示',
    key: 'isShowList',
    type: JVxeTypes.checkbox,
    customValue: [1, 0],
    defaultChecked: false
  },
  {
    title: '是否排序',
    key: 'sortFlag',
    type: JVxeTypes.checkbox,
    customValue: [1, 0],
    defaultChecked: false
  },
  {
    title: '是否只读',
    key: 'isReadOnly',
    type: JVxeTypes.checkbox,
    customValue: [1, 0],
    defaultChecked: true
  },
  {
    title: '控件类型',
    key: 'fieldShowType',
    type: JVxeTypes.select,
    defaultValue: 'text',
    options: [
      { title: '文本', value: 'text' },
      { title: '密码', value: 'password' },
      { title: '下拉框', value: 'list' },
      { title: '单选框', value: 'radio' },
      { title: '多选框', value: 'checkbox' },
      { title: '开关', value: 'switch' },
      { title: '日期', value: 'date' },
      { title: '日期-时间', value: 'datetime' },
      { title: '时间', value: 'time' },
      { title: '文件', value: 'file' },
      { title: '图片', value: 'image' },
      { title: '多行文本', value: 'textarea' },
      { title: '下拉框多选', value: 'list_multi' },
      { title: 'Popup弹框', value: 'popup' },
      { title: '分类字典树', value: 'cat_tree' },
      { title: '部门选择', value: 'sel_depart' },
      { title: '用户选择', value: 'sel_user' },
      { title: '富文本', value: 'umeditor' },
      { title: 'MarkDown', value: 'markdown' },
      { title: '省市区组件', value: 'pca' },
      { title: '联动组件', value: 'link_down' },
      { title: '自定义树控件', value: 'sel_tree' }
    ],
    placeholder: '请选择',
    validateRules: [
      {
        required: true,
        message: '请选择${title}'
      }
    ]
  },
  {
    title: '控件长度',
    key: 'fieldLength',
    type: JVxeTypes.inputNumber,
    defaultValue: 120,
    validateRules: [
      {
        required: true,
        message: '请选择${title}'
      }
    ]
  },
  {
    title: '是否查询',
    key: 'isQuery',
    type: JVxeTypes.checkbox,
    customValue: [1, 0],
    defaultChecked: false
  },
  {
    title: '查询类型',
    key: 'queryMode',
    type: JVxeTypes.select,
    customValue: [1, 0],
    defaultValue: 'single',
    options: [
      { title: '普通查询', value: 'single' },
      { title: '范围查询', value: 'group' }
    ],
    placeholder: '请选择',
    validateRules: [
      {
        required: true,
        message: '请选择${title}'
      }
    ]
  },
  {
    title: '控件默认值',
    key: 'fieldDefaultValue',
    type: JVxeTypes.input
  },
  {
    title: '扩展参数',
    key: 'fieldExtendJson',
    type: JVxeTypes.input
  },
  {
    title: '自定义转化器',
    key: 'converter',
    type: JVxeTypes.input,
    width: 150
  }
];

export const checkInfoColumn: JVxeColumn[] = [
  {
    title: 'ID',
    key: 'id',
    type: JVxeTypes.hidden
  },
  {
    title: '字段名称',
    key: 'dbFieldName',
    type: JVxeTypes.normal
  },
  {
    title: '字段备注',
    key: 'dbFieldTxt',
    type: JVxeTypes.normal
  },
  {
    title: '字段Href',
    key: 'fieldHref',
    type: JVxeTypes.textarea
  },
  {
    title: '验证规则',
    key: 'fieldValidType',
    type: JVxeTypes.select,
    defaultValue: '',
    options: [
      { title: '空', value: '' },
      { title: '唯一校验', value: 'only' },
      { title: '6到16位数字', value: 'n6-16' },
      { title: '6到16位任意字符', value: '*6-16' },
      { title: '网址', value: 'url' },
      { title: '电子邮件', value: 'e' },
      { title: '手机号码', value: 'm' },
      { title: '邮政编码', value: 'p' },
      { title: '字母', value: 's' },
      { title: '整数', value: 'z' },
      { title: '非空', value: '*' },
      { title: '6到18位字符串', value: 's6-18' },
      { title: '金额', value: 'money' }
    ],
    placeholder: '请选择'
  },
  {
    title: '校验必填',
    key: 'fieldMustInput',
    type: JVxeTypes.checkbox,
    customValue: [1, 0],
    defaultChecked: false
  },
  {
    title: '字典table',
    key: 'dictTable',
    type: JVxeTypes.input,
    customValue: [1, 0],
    defaultChecked: true
  },
  {
    title: '字典code',
    key: 'dictField',
    type: JVxeTypes.input
  },
  {
    title: '字典Text',
    key: 'dictText',
    type: JVxeTypes.input
  }
];

export const foreignInfoColumn: JVxeColumn[] = [
  {
    title: 'ID',
    key: 'id',
    type: JVxeTypes.hidden
  },
  {
    title: '字段名称',
    key: 'dbFieldName',
    type: JVxeTypes.normal
  },
  {
    title: '字段备注',
    key: 'dbFieldTxt',
    type: JVxeTypes.normal
  },
  {
    title: '主表名',
    key: 'mainTable',
    type: JVxeTypes.input
  },
  {
    title: '主表字段',
    key: 'mainField',
    type: JVxeTypes.input
  }
];

export const indexInfoColumn: JVxeColumn[] = [
  {
    title: 'ID',
    key: 'id',
    type: JVxeTypes.hidden
  },
  {
    title: '索引名称',
    key: 'indexName',
    type: JVxeTypes.input,
    validateRules: [
      {
        required: true,
        message: '请选择${title}'
      }
    ]
  },
  {
    title: '索引拦位',
    key: 'indexField',
    type: JVxeTypes.select,
    validateRules: [
      {
        required: true,
        message: '请选择${title}'
      }
    ]
  },
  {
    title: '索引类型',
    key: 'indexType',
    type: JVxeTypes.select,
    options: [
      { title: 'normal', value: 'normal' },
      { title: 'unique', value: 'unique' }
    ],
    placeholder: '请选择',
    validateRules: [
      {
        required: true,
        message: '请选择${title}'
      }
    ]
  }
];

export const searchInfoColumn: JVxeColumn[] = [
  {
    title: 'ID',
    key: 'id',
    type: JVxeTypes.hidden
  },
  {
    title: '字段名称',
    key: 'dbFieldName',
    type: JVxeTypes.normal
  },
  {
    title: '字段备注',
    key: 'dbFieldTxt',
    type: JVxeTypes.normal
  },
  {
    title: '控件类型',
    key: 'queryShowType',
    type: JVxeTypes.select,
    options: [
      { title: '文本框', value: 'text' },
      { title: '日期(yyyy-MM-dd)', value: 'date' },
      { title: '日期(yyyy-MM-dd hh:mm:ss)', value: 'datetime' },
      { title: '时间(HH:mm:ss)', value: 'time' },
      { title: '下拉框', value: 'list' },
      { title: '下拉框多选', value: 'list_multi' },
      { title: '下拉框搜索框', value: 'sel_search' },
      { title: '分类字典树', value: 'cat_tree' },
      { title: 'Popup弹框', value: 'popup' },
      { title: '部门选择', value: 'sel_depart' },
      { title: '用户选择', value: 'sel_user' },
      { title: '省市区组件', value: 'pca' },
      { title: '自定义树控件', value: 'sel_tree' }
    ],
    placeholder: '请选择'
  },
  {
    title: '字典table',
    key: 'queryDictTable',
    type: JVxeTypes.input
  },
  {
    title: '字典Code',
    key: 'queryDictField',
    type: JVxeTypes.input
  },
  {
    title: '字典Text',
    key: 'queryDictText',
    type: JVxeTypes.input
  },
  {
    title: '默认值',
    key: 'queryDefVal',
    type: JVxeTypes.input
  },
  {
    title: '是否启用',
    key: 'queryConfigFlag',
    type: JVxeTypes.checkbox,
    customValue: [1, 0],
    defaultChecked: false
  }
];

export const subInfoColumn: JVxeColumn[] = [
  {
    title: 'ID',
    key: 'id',
    type: JVxeTypes.hidden
  },
  {
    title: '子表名',
    key: 'tableName',
    type: JVxeTypes.normal
  },
  {
    title: '子表实体',
    key: 'entityName',
    type: JVxeTypes.normal
  },
  {
    title: '功能说明',
    key: 'tableTxt',
    type: JVxeTypes.normal
  }
];
