import { connect } from 'dva'
import PageConfigShowBaseComponent from "../Lib/PageConfigShowBaseComponent"
import { guid, extendRule } from "../../../utils/common"

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

  onRowDropDownFilter (params) {
    this.onEditFilter(params)
  }

  onEditFilter = (params) => {
    const { params: selectParams, colConfig } = params
    if (colConfig.field === 'Nav_ParamScheme.NAME') {
      extendRule(selectParams, 'ENABLE_STATUS', 1, 0)
    }
  }

  onGetTableConfig () {
    const tableConfig = {
      sort: 'NUM',
      order: 0,
      api: 'PF/PageTable/OrderPaged',
      columns: [
        { field: 'LABEL_NAME', label: '显示名称', isRequire: true },
        { field: 'CODE', label: '编码', isRequire: true },
        { field: 'NUM', label: '顺序索引' },
        { field: 'TABLE_CONDITION', label: '列表显示条件' },
      ],
      deleteApi: 'PF/PageTable/Delete',
      editConfig: {
        data: {
          'ORG_ID': this.props.orgId,
          'PAGE_FORM_ID': this.props.formId,
          'NUM': 0,
          'SEND_TYPE': '2',
          'QUERY_SEND_TYPE': '2',
          'PARENT_ID': this.props.parentId
        },
        columns: [
          { controlType: 1, field: 'LABEL_NAME', label: '显示名称', isRequire: true },
          { controlType: 1, field: 'CODE', label: '编码', isRequire: true },
          { controlType: 1, field: 'NUM', label: '顺序索引' },
          { controlType: 1, field: 'TABLE_CONDITION', label: '列表显示条件', promptInfo: '格式：菜单参数1|菜单参数2，多个使用|或者&隔开' },
        ],
        getApi: 'PF/PageTable/Get',
        saveApi: 'PF/PageTable/Update',
        onFilter: this.onEditFilter,
      },
      rule: {
        rules: [
          { field: 'PAGE_FORM_ID', operator: 1, value: this.props.formId },
          { field: 'PARENT_ID', operator: 1, value: this.props.parentId },
        ]
      },
      rowBtns: [
        { id: guid(), btnType: 7, code: 'edit' },
        { id: guid(), btnType: 4, code: 'delete' },
      ]
    }
    return [tableConfig]
  }

  onTableBtnParam (params) {
    return super.onTableBtnParam(params)
  }
}

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