<template>
  <BasicDrawer @register="registerBaseDrawer" title="自评估结果" width="1024" destroyOnClose>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      
      
    </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 {userColumns} from '../RateTask.data';
  import {domainScorelist,getRateUserscore} from '../RateTask.api';
 

  

  const emit = defineEmits(['register', 'hideUserList']);
  const checkedKeys = ref<Array<string | number>>([]);
  const taskid = ref('');
   const sumzf= ref(0);
  const sumdf= ref(0);

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


  const [registerBaseDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
    taskid.value = data.rateTaskId;

    getRateUserscore({taskid:taskid.value}).then(rep=>{
              
             console.log('-----------rep: ', rep.inputscore);
             sumdfkey.vulue= rep.inputscore;
             
            })


    setProps({ searchInfo: { taskid: data.rateTaskId } });
    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.inputscore)
         console.log('-----------next.inputscore: ', next.inputscore);

          return sumdf;
        }, 0);
        sumkf.value =0;
        const totalinputscoreof = tableData.reduce((prev2, next) => {
         
          sumkf.value = sumkf.value+parseFloat(next.inputscoreof)
         
          return sumkf;
        }, 0);
        return [
          {
            _row: '合计',
            keyitemscore: sumzf.value,
            inputscore: sumdfkey.vulue,
            inputscoreof: sumkf.value,
          },
          
        ];
      }
  
  const [registerTable, { reload, updateTableDataRecord, setProps }] = useTable({
    title: '列表',
    api: domainScorelist,
    columns: userColumns,
    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;
  }


</script>
