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

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

  onGetTableConfig() {
    const tableConfig = {
      sort: 'NUM',
      order: 0,
      api: 'PF/FormQuery/OrderPaged',
      columns: [
        {field: 'LABEL', label: '显示名称', isRequire: true},
        {field: 'CODE', label: '编码'},
        {field: 'FORM_QUERY_SHOW_TYPE', label: '查询显示类型', data: {enumName: 'PFFormQueryShowTypeEnum'}},
        {field: 'INPUT_FILTER_ORG_TYPE', label: '组织过滤类型', data: {enumName: 'PFFilterOrgTypeEnum'}},
        {field: 'TABLE_NAME', label: '表名'},
        {field: 'NUM', label: '顺序索引'},
        {field: 'SHARE_KEY', label: '共享键值'},
        {field: 'IS_REMEMBER', label: '记忆查询', isBool: true},
      ],
      deleteApi: 'PF/FormQuery/Delete',
      editConfig: {
        data: {
          'ORG_ID': this.props.orgId,
          'PAGE_FORM_ID': this.props.formId,
          'NUM': 0,
          'FORM_QUERY_SHOW_TYPE': 0,
        },
        columns: [
          {controlType: 1, field: 'LABEL', label: '显示名称', isRequire: true},
          {controlType: 1, field: 'CODE', label: '编码'},
          {controlType: 3, field: 'FORM_QUERY_SHOW_TYPE', label: '数据类型', data: {enumName: 'PFFormQueryShowTypeEnum'}},
          {controlType: 3, field: 'INPUT_FILTER_ORG_TYPE', label: '组织过滤类型', data: {enumName: 'PFFilterOrgTypeEnum'}},
          {controlType: 1, field: 'TABLE_NAME', label: '表名'},
          {controlType: 1, field: 'NUM', label: '顺序索引'},
          {controlType: 1, field: 'SHARE_KEY', label: '共享键值'},
          {controlType: 4, field: 'IS_REMEMBER', label: '记忆查询'},
        ],
        getApi: 'PF/FormQuery/Get',
        saveApi: 'PF/FormQuery/Update',
      },
      rule: {
        rules: [
          {field: 'PAGE_FORM_ID', operator: 1, value: this.props.formId},
        ]
      },
      rowBtns:[
        {id:guid(),btnType:7,code:'edit'},
        {id:guid(),btnType:4,code:'delete'},
        {id:guid(),btnType:7,code:'query'},
      ]
    };
    return [tableConfig];
  }
  
  onTableBtnParam(params){
    const {btnConfig,record}=params?params:{};
    if(btnConfig.code==='query') {
      return {
        content: <QueryShowPage orgId={this.props.orgId} formQueryId={record.ID}
                              formId={this.props.formId}>
          <Button icon={'search'} css={'default'} size={'small'} title={'字段'}/>
        </QueryShowPage>
      };
    }
    
    return super.onTableBtnParam(params);
  }

}

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