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


class ChartShowPage extends PageConfigShowBaseComponent {
  constructor(props) {
    super(props);
    this.state = {
      data: {},
      paginationIndex:1,
      paginationTotalCount: 0,
      rowData:{},
      visible:false,
      selectedRowKeys: []
    };
  };
  onGetTableConfig(){
    const tableConfig={
      sort: 'NUM',
      order: 0,
      api:'PF/PageChart/OrderPaged',
      columns: [
        {label: '表头', field: 'LABEL',},
        {label: '编号', field: 'CODE',},
        {label: '图表类型', field: 'CHART_TYPE', data:{enumName:'PFChartTypeEnum'}},
        {label: 'API', field: 'API_URL'},
        {label: '分割占比', field: 'SPAN'},
        {label: '最小宽度', field: 'MIN_WIDTH'},
        {label: '是否显示数据', field: 'IS_SHOW_DATA',isBool:true},
        {label: '顺序索引', field: 'NUM',},
      ],
      deleteApi:'PF/PageChart/Delete',
      editConfig:{
        data: {
          ORG_ID: this.props.orgId,
          PAGE_FORM_ID: this.props.formId,
          NUM: 0,
        },
        columns:[
          {controlType:1,field:'CODE',label:'编号'},
          {controlType:1,field:'LABEL',label:'标题',isRequire:true},
          {controlType:3,field:'CHART_TYPE',label:'图表类型',data:{enumName:'PFChartTypeEnum'}},
          {controlType:1,field:'API_URL',label:'API',isRequire:true},
          {controlType:3,field:'SPAN',label:'分割占比',data:{options:'请选择:0,12:12,24:24'}},
          {controlType:7,field:'MIN_WIDTH',label:'最小宽度',},
          {controlType:4,field:'IS_SHOW_DATA',label:'是否显示数据',},
          {controlType:1,field:'NUM',label:'顺序索引',},
          {controlType:4,field:'IGNORE_ORG_RULE',label:'忽略组织权限',},
        ],
        getApi:'PF/PageChart/Get',
        saveApi:'PF/PageChart/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:'param'},
      ]
    };
    return [tableConfig];
  }

  onTableBtnParam(params){
    const {btnConfig,record}=params?params:{};
    if(btnConfig.code==='param') {
      return {
        content: <ChartParamShowPage pageChartId={record.ID}  orgId={this.props.orgId}
                                     formId={this.props.formId}>
          <Button icon={'info'} css={'default'} size={'small'} title={'参数'}/>
        </ChartParamShowPage>
      };
    }

    return super.onTableBtnParam(params);
  }
  getRowOtherBtns({record}){
    return <>
      <ChartParamShowPage pageChartId={record.ID}  orgId={this.props.orgId}
                          formId={this.props.formId}>
        <Button icon={'info'} css={'default'}>参数</Button>
      </ChartParamShowPage>
      </>
  }
}

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