<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection" >
     <!--插槽:table标题-->
      <template #tableTitle>
           
      </template>
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{text}">
         <div v-html="text"></div>
      </template>
      <!--省市区字段回显插槽-->
      <template #pcaSlot="{text}">
         {{ getAreaTextByCode(text) }}
      </template>
      <template #fileSlot="{text}">
         <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
         <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
    <!--角色用户表格-->
    <RateUserTable @register="rateUserDrawer" />
    <RateStatiTable @register="rateStatiDrawer" />
    <!-- 表单区域 -->
    <RateTaskModal @register="registerModal" @success="handleSuccess"></RateTaskModal>
  </div>
</template>

<script lang="ts" name="rate-rateTask" setup>
  import {ref, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { useDrawer } from '/@/components/Drawer';
  import { useListPage } from '/@/hooks/system/useListPage'
  import RateTaskModal from './components/RateTaskModal.vue'
  import {columns, searchFormSchema} from './RateTaskRateRes.data';
  import {rateReslist} from './RateTask.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import { useMessage } from '/@/hooks/web/useMessage';
  const { createMessage } = useMessage();
  import { useRouter } from 'vue-router';
  import { useUserStore } from '/@/store/modules/user';
  import RateUserTable from './components/RateResTable.vue';
  import RateStatiTable from './components/RateStatiTable.vue';
  const router = useRouter();
  const userStore = useUserStore();
  const checkedKeys = ref<Array<string | number>>([]);
  //注册model
  const [registerModal, {openModal}] = useModal();
  const [rateUserDrawer, { openDrawer: openRateUserDrawer }] = useDrawer();
  const [rateStatiDrawer, { openDrawer: openRateStatiDrawer }] = useDrawer();
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '评估结果',
           api: rateReslist,
           columns,
           canResize:false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
      },
          
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext


   /**
    * 详情
   */
  function handleDetail(record: Recordable) {
     router.push({path: '/rate/rateRateView',query:{id:record.id}})
   }

   /**
    * 评估结果
   */
  function handleResDetail(record: Recordable) {
    openRateUserDrawer(true, record);
    //router.push({path: '/rate/rateTaskRateResTabList',query:{id:record.id}})
   }

  /**
    * 统计表
   */
  function handleTjDetail(record: Recordable) {
    openRateStatiDrawer(true, record);
   
   }


   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }

 

   /**
      * 操作栏
      */
  function getTableAction(record){
       return [

        {
           label: '评估结果',
           onClick: handleResDetail.bind(null, record),
           
         },
         {
           label: '|',
   
           
         },
        
         {
           label: '统计表',
           onClick: handleTjDetail.bind(null, record),
           
         }, 
        
       ]
   }
     /**
        * 下拉操作栏
        */
  function getDropDownAction(record){
       return [ /**
         {
           label: '详情',
           onClick: handleDetail.bind(null, record),
         },  */
       ]
   }



</script>

<style scoped>

</style>