import React from 'react'
import { connect } from 'dva'
import PageConfigShowBaseComponent from "../Lib/PageConfigShowBaseComponent"
import { guid } from "../../../utils/common"
import { message } from 'antd'

class QueryShowPage extends PageConfigShowBaseComponent {
  constructor(props) {
    super(props)
    this.state = {
      data: {},
      paginationIndex: 1,
      paginationTotalCount: 0,
      rowData: {},
      visible: false,
    }
  };

  onEditVisible = (data) => {
    const controlType = data ? data.DATA_TYPE : 0
    const visible = {}

    /**
     * DATA_TYPE
     * 8: 级联组件
     * 11: 分页下拉
     */
    visible['INPUT_DATA_LEVEL'] = controlType === 8 || controlType === 14
    visible['IS_ONLY_CHECK_LEAF'] = controlType === 8 || controlType === 14
    visible['MULTIPLE_CHOICE'] = controlType === 14
    visible['SELECT_CONDITION'] = controlType === 14

    visible['INPUT_DATA_API'] = controlType === 8 || controlType === 11 || controlType === 14 ||controlType === 24
    visible['INPUT_ID_FIELD'] = controlType === 11||controlType === 24
    visible['INPUT_SAVE_FIELD'] = controlType === 11||controlType === 24
    visible['INPUT_NAV_FIELD'] = controlType === 11||controlType === 24
    visible['INPUT_FILTER_FIELD'] = controlType === 11||controlType === 24
    visible['INPUT_LABEL_FIELD'] = controlType === 11||controlType === 24
    visible['SELECTD_LABEL_FIELD'] = controlType === 24
    visible['INPUT_SHOW_FIELD'] = controlType === 11||controlType === 24
    visible['INPUT_SORT_FIELD'] = controlType === 11||controlType === 24
    visible['INPUT_SORT_ORDER'] = controlType === 11||controlType === 24
    visible['INPUT_FILTER_ORG_TYPE'] = controlType === 11||controlType === 24
    visible['INPUT_KEEP_VALUE_BY_NO_SRC'] = controlType === 11||controlType === 24
    visible['DATETIME_FORMATE'] = controlType === 108
    return visible
  }

  onEditChange = (params) => {
    const { field, onSetVisible } = params
    if (field === 'DATA_TYPE') {
      onSetVisible()
    }
  }

  onGetTableConfig () {
    const tableConfig = {
      sort: 'NUM',
      order: 0,
      api: 'PF/Query/OrderPaged',
      columns: [
        { field: 'LABEL', label: '显示名称', isRequire: true },
        { field: 'CODE', label: '编码' },
        { field: 'QUERY_NAME', label: '字段名称' },
        { field: 'DATA_TYPE', label: '数据类型', data: { enumName: 'PFDataTypeEnum' } },
        { field: 'IS_DEFAULT_QUERY', label: '是否显示', isBool: true },
        { field: 'IS_CUSTOM', label: '是否自定义字段', isBool: true },
        { field: 'IS_SYS_PARAM', label: '是否系统参数', isBool: true },
        { field: 'IS_REQUIRE', label: '是否必填', isBool: true },
        { field: 'OP_DEFAULT', label: '条件操作符', data: { enumName: 'PFOperateEnum' } },
        { field: 'CASE', label: '大小写', data: { enumName: 'FMCaseProcEnum' } },
        { field: 'DATA_VALUE', label: '数值默认' },
        { field: 'ENUM_NAME', label: '枚举名称' },
        { field: 'NUM', label: '顺序索引' },
      ],
      deleteApi: 'PF/Query/Delete',
      editConfig: {
        data: {
          'ORG_ID': this.props.orgId,
          'PAGE_FORM_ID': this.props.formId,
          'PAGE_FORM_QUERY_ID': this.props.formQueryId,
          'NUM': 0,
          'DATA_TYPE': 1,
          'IS_DEFAULT_QUERY': true,
        },
        columns: [
          { controlType: 1, field: 'LABEL', label: '显示名称', isRequire: true },
          { controlType: 1, field: 'CODE', label: '编码' },
          { controlType: 1, field: 'QUERY_NAME', label: '字段名称', isRequire: true },
          { controlType: 3, field: 'DATA_TYPE', label: '数据类型', data: { enumName: 'PFDataTypeEnum' } },
          { controlType: 4, field: 'IS_DEFAULT_QUERY', label: '是否显示' },
          { controlType: 4, field: 'IS_CUSTOM', label: '是否自定义字段' },
          { controlType: 4, field: 'IS_SYS_PARAM', label: '是否参数字段' },
          { controlType: 4, field: 'IS_REQUIRE', label: '是否必填' },
          { controlType: 3, field: 'OP_DEFAULT', label: '条件操作符', data: { enumName: 'PFOperateEnum' } },
          { controlType: 1, field: 'INPUT_DATA_API', label: 'API' },
          { controlType: 1, field: 'INPUT_DATA_LEVEL', label: '显示几级' },
          { controlType: 4, field: 'IS_ONLY_CHECK_LEAF', label: '父级不可选' },
          { controlType: 4, field: 'MULTIPLE_CHOICE', label: '是否多选' },
          { controlType: 1, field: 'SELECT_CONDITION', label: '节点是否可选', promptInfo: '格式：FIELD1,OP,VALUE1|FIELD2,OP,VALUE2'},
          { controlType: 4, field: 'CHECK_STRICTLY', label: '父子不关联' },
          { controlType: 1, field: 'INPUT_ID_FIELD', label: '关联ID字段', promptInfo: '关联ID字段 配置保存主键ID的字段名称' },
          {
            controlType: 1, field: 'INPUT_SAVE_FIELD', label: '保存字段', promptInfo: '保存字段（多个字段,分隔）', span: { span: 24 }, formItemLayout: {
              labelCol: { span: 3 },
              wrapperCol: { span: 17 },
            }
          },
          {
            controlType: 1, field: 'INPUT_NAV_FIELD', label: '导航字段', promptInfo: '导航字段（多个字段,分隔）', span: { span: 24 }, formItemLayout: {
              labelCol: { span: 3 },
              wrapperCol: { span: 17 },
            }
          },
          { controlType: 1, field: 'INPUT_FILTER_FIELD', label: '过滤字段', promptInfo: '过滤字段（多个字段,分隔）' },
          { controlType: 1, field: 'INPUT_LABEL_FIELD', label: '显示字段', promptInfo: '显示字段（多个字段,分隔）' },
          { controlType: 1, field: 'INPUT_SHOW_FIELD', label: '下拉显示字段', promptInfo: '下拉显示字段（多个字段,分隔）' },
          { controlType: 1, field: 'SELECTD_LABEL_FIELD', label: '选择显示字段', promptInfo: '选择显示字段' },
          { controlType: 1, field: 'INPUT_SORT_FIELD', label: '排序字段', promptInfo: '排序字段(配置关联表的字段，多字段用,号分割）' },
          { controlType: 1, field: 'INPUT_SORT_ORDER', label: '排序方式', promptInfo: '排序方式(配置关联表的字段，多字段用,号分割）' },
          { controlType: 3, field: 'INPUT_FILTER_ORG_TYPE', label: '组织过滤类型', data: { enumName: 'PFFilterOrgTypeEnum' } },
          { controlType: 4, field: 'INPUT_KEEP_VALUE_BY_NO_SRC', label: '非法输入保留值' },
          { controlType: 3, field: 'CASE', label: '大小写', data: { enumName: 'FMCaseProcEnum' } },
          { controlType: 1, field: 'DATA_VALUE', label: '数值默认' },
          { controlType: 1, field: 'ENUM_NAME', label: '枚举名称' },
          { controlType: 1, field: 'NUM', label: '顺序索引' },
          { controlType: 4, field: 'IS_TITLE', label: '导出文件标题' },
          { controlType: 1, field: 'DATETIME_FORMATE', label: '时间格式' },
        ],
        getApi: 'PF/Query/Get',
        saveApi: 'PF/Query/Update',
        onChange: this.onEditChange,
        onVisible: this.onEditVisible,
        onCheckBeforeSave: (data) => {
          if (data.IS_REQUIRE && !data.DATA_VALUE) {
            message.warning('必填条件时,请设置默认值')
            return true
          }
        },
        promptInfo: '日期控件的默认值：{now,类型,间隔} 类型:d-日 M-月 y-年  间隔：可正可负的数值；例如：{now,d,1} 当前日期到当前日期加1天；{now,d,-1}当前日期减1天到当前日期；  {now,d,1}{now,d,2}:当前日期加1天到当前日期加2天;固定日期区间如：2021-01-01,2021-02-01'
      },
      rule: {
        rules: [
          { field: 'PAGE_FORM_ID', operator: 1, value: this.props.formId },
          { field: 'PAGE_FORM_QUERY_ID', operator: 1, value: this.props.formQueryId },
        ]
      },
      rowBtns: [
        { id: guid(), btnType: 7, code: 'edit' },
        { id: guid(), btnType: 4, code: 'delete' },
      ]
    }
    return [tableConfig]
  }

}

export default connect(({ login, app, loading, custom }) => ({ login, app, loading, custom }))(QueryShowPage)
