<template>
    <BasicTable @register="registerTable" :rowSelection="rowSelection" @selection-change="handlerRowClick">
        <!-- update-begin-author:taoyan date:2022-5-25 for: VUEN-1112一对多 用户选择 未显示选择条数，及清空 -->
        <template #tableTitle></template>
        <!-- update-end-author:taoyan date:2022-5-25 for: VUEN-1112一对多 用户选择 未显示选择条数，及清空 -->
    </BasicTable>
</template>
<script setup>
import { toRaw } from 'vue';
import { listDepart } from '../../StProjectConfig.api';
import { BasicTable } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
const props = defineProps({
    actCheckbox: {},
});
const columns = [
   {
    title: '组织名称',
    align:"left",
    dataIndex: 'departName'
   },
   {
    title: '说明',
    align:"left",
    dataIndex: 'description'
   },
];
const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '',
           api: listDepart,
           columns,
           canResize:false,
           useSearchForm: false,
           scroll: { x: false,y:250 },
           actionColumn: {ifShow: false},
           clickToRowSelect: true,
           rowSelection: { 
                onSelect: handlerChecked,
            },
        //    actionColumn: {
        //        width: 160
        //     },
            showTableSetting: false,
            beforeFetch(params) {
              params = Object.assign(params,{ column: 'departOrder', order: 'desc',orgCategory:'1'})
            },
      },
  })
  const [registerTable, {setProps,reload},{ rowSelection, selectedRowKeys }] = tableContext

  function handlerChecked(record, selected, selectedRows, nativeEvent){
    if(selected){
        let item = {}
        item[record.id] = true
        Object.assign(props.actCheckbox,item)
    }else{
        let item = {}
        item[record.id] = false
        Object.assign(props.actCheckbox,item)
    }
  }
  function initActCheckbox(){
    let actInfo = toRaw(props.actCheckbox)
    let item = {}
    for(let k in actInfo){
        if(!k){
            continue
        }
        item[k] = false
    }
    Object.assign(props.actCheckbox,item)
  }
  function handlerRowClick({keys,rows}){
    initActCheckbox()
    if(keys.length>0){
        let item = {}
        for(var i=0;i<keys.length;i++){
            item[rows[i].id] = true
        }
        Object.assign(props.actCheckbox,item)
    }
  }
</script>