<template>
  <BasicDrawer @register="registerBaseDrawer" title="评估结果" width="1024" destroyOnClose>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">

    <template #tableTitle>
          
          <a-button  type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出报表</a-button>
          
      </template>
      
      
    </BasicTable>
    
  </BasicDrawer>
</template>
<script lang="ts" setup>
  import { ref, defineProps, watch, unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/src/components/Table';
  import { BasicDrawer, useDrawer, useDrawerInner } from '/src/components/Drawer';
  import { useModal } from '/src/components/Modal';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import {resColumns} from '../RateTask.data';
  import {domainResScorelist,getExporRestUrl,getQueScoreByTaskid} from '../RateTask.api';
 

   const sumzf= ref(0);
  const sumdf= ref(0);

  const sumkf = ref(0);
  const sumdfkey= ref(0);

  const emit = defineEmits(['register', 'hideUserList']);
  const checkedKeys = ref<Array<string | number>>([]);
  const taskid = ref('');
  const [registerBaseDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
    taskid.value = data.id;
    getQueScoreByTaskid({taskid:taskid.value}).then(rep=>{
              
            // console.log('-----------rep: ', rep.ratescore);
             sumdfkey.value= rep.ratescore;
             
            })

    setProps({ searchInfo: { taskid: data.id } });
    reload();
  });

 


  function handleSummary(tableData: Recordable[]) {
    sumzf.value = 0;
        const totalkeyitemscore = tableData.reduce((prev3, next) => {
          sumzf.value = sumzf.value+parseFloat(next.keyitemscore)
          return sumzf;
        }, 0);
       
    sumdf.value = 0;
        const totalinputscore = tableData.reduce((prev, next) => {
         
          sumdf.value = sumdf.value+parseFloat(next.score)
         

          return sumdf;
        }, 0);
        
        sumkf.value =0;
        const totalinputscoreof = tableData.reduce((prev2, next) => {
         
          sumkf.value = sumkf.value+parseFloat(next.scoreof)
         
          return sumkf;
        }, 0);
        return [
          {
            _row: '合计',
            keyitemscore: sumzf.value,
            score: sumdfkey.value,
            scoreof: sumkf.value,
          },
          
        ];
      }
  
  const [registerTable, { reload, updateTableDataRecord, setProps }] = useTable({
    title: '列表',
    api: domainResScorelist,
    columns: resColumns,
    formConfig: {
      labelWidth: 120,
      actionColOptions: { pull: 1 },
    },
    striped: true,
    useSearchForm: false,
    showTableSetting: true,
    clickToRowSelect: false,
    bordered: true,
    showIndexColumn: false,
    tableSetting: { fullScreen: true },
    canResize: false,
    rowKey: 'id',
    pagination:false,
    showSummary: true,
    summaryFunc: handleSummary,
    
  });

  /**
   * 选择列配置
   */
  const rowSelection = {
    type: 'checkbox',
    columnWidth: 50,
    selectedRowKeys: checkedKeys,
    onChange: onSelectChange,
  };

  /**
   * 选择事件
   */
  function onSelectChange(selectedRowKeys: (string | number)[], selectionRows) {
    checkedKeys.value = selectedRowKeys;
  }

  function onExportXls(){
 
  getExporRestUrl({"taskid":taskid.value});

  
  }


</script>
