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

class TreeShowPage 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/PageTree/OrderPaged',
      columns: [

        {field:'LABEL_NAME',label:'显示名称',isRequire:true},
        {field:'BATCH_DEL_API_URL',label:'删除API路径',isRequire:true},
        {field:'QUERY_API_URL',label:'查询API路径',isRequire:true},
        {field:'SORT',label:'排序字段',isRequire:true},
        {field:'ORDER',label:'排序方式'},
        {field:'RELATION_FIELD',label:'关联字段'},
        {field:'CUSTOM_PARAMS',label:'自定义参数',promptInfo:'自定义参数  格式：参数名称=参数值  多个参数时以||分割'},
        {field:'NUM',label:'顺序索引'},
      ],
      deleteApi:'PF/PageTree/Delete',
      editConfig:{
        data: {
          'ORG_ID': this.props.orgId,
          'PAGE_FORM_ID': this.props.formId,
          'NUM': 0,
          'BATCH_DEL_SEND_TYPE': '2',
          'QUERY_SEND_TYPE': '2'
        },
        columns:[
          {controlType:1,field:'LABEL_NAME',label:'显示名称',isRequire:true},
          {controlType:1,field:'BATCH_DEL_API_URL',label:'删除API路径',isRequire:true},
          {controlType:1,field:'QUERY_API_URL',label:'查询API路径',isRequire:true},
          {controlType:1,field:'SORT',label:'排序字段',isRequire:true},
          {controlType:1,field:'ORDER',label:'排序方式'},
          {controlType:1,field:'RELATION_FIELD',label:'关联字段'},
          {controlType:3,field:'FILTER_ORG_TYPE',label:'过滤组织类型',data:{enumName:'PFFilterOrgTypeEnum'}},
          {controlType:1,field:'CUSTOM_PARAMS',label:'自定义参数',promptInfo:'自定义参数  格式：参数名称=参数值  多个参数时以||分割'},
          {controlType:1,field:'NUM',label:'顺序索引'},
          {controlType:4,field:'CAN_ADD_NODE',label:'允许创建节点'},
          {controlType:1,field:'SHOW_MODEL',label:'展示类型',promptInfo:'默认0，1代表垂直展开的树形菜单'},
          {controlType:1,field:'LEVEL',label:'默认展开层级'},
          {controlType:4,field:'MULTI_CHECK',label:'允许多选'},
          {controlType:7,field:'MULTI_CHECK_COUNT',label:'最多可选节点数'},
          {controlType:4,field:'IGNORE_ORG_RULE',label:'忽略组织权限'},
        ],
        getApi:'PF/PageTree/Get',
        saveApi:'PF/PageTree/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:'column'},
      ]
    };
    if(!this.props.parentId) {
      tableConfig.rowBtns.push({id: guid(), btnType: 7, code: 'btn'})
    }
    return [tableConfig];
  }

  onTableBtnParam(params){
    const {btnConfig,record}=params?params:{};
    if(btnConfig.code==='column') {
      return {
        content:<TreeColumnShowPage orgId={this.props.orgId} pageTableId={record.ID}>
          <Button icon={'bars'} css={'default'} size={'small'} title={'字段'}/>
        </TreeColumnShowPage>
      };
    }
    else if(btnConfig.code==='btn') {
      return {
        content:  <BtnShowPage orgId={this.props.orgId} tableId={record.ID} btnPageType={1}>
          <Button icon={'star'} css={'default'} size={'small'} title={'按钮'}/>
        </BtnShowPage>
      };
    }
    return super.onTableBtnParam(params);
  }


  getRowOtherBtns({record}){
    return <>
      <TreeColumnShowPage orgId={this.props.orgId} pageTableId={record.ID}>
        <Button icon={'bars'} css={'default'}>字段</Button>
      </TreeColumnShowPage>

      {
        (()=>{
          if(!this.props.parentId){
            return <BtnShowPage orgId={this.props.orgId} tableId={record.ID} btnPageType={1}>
              <Button icon={'star'} css={'default'}>按钮</Button>
            </BtnShowPage>;
          }
        })()
      }
      </>
  }

}

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