<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" >

       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'fileUploadPath'">
          <JEllipsisFormat :isLink="true"  :value="'相关文件'" :length="60" @click="goToCa(record)"/>
        </template>
     </template>
    <!-- 表单区域 -->

    </BasicTable>
    <StProjectExecTwoModal @register="registerModal" @success="handleSuccess"></StProjectExecTwoModal>
    <StProjectExecTowConfig @register="registerConfigModal" @success="handleSuccess"></StProjectExecTowConfig>  </div>
</template>

<script lang="ts" name="compliane.item-StProjectExecTwo" setup>
  import { ref } from 'vue';
import { batchDelete, deleteOne, getExportUrl, getImportUrl, list } from './StProjectExecTwo.api';
import { columns, searchFormSchema } from './StProjectExecTwo.data';
import StProjectExecTwoModal from './components/StProjectExecTwoModal.vue';
import StProjectExecTowConfig from './components/StProjectExecTowConfig.vue';
import JEllipsisFormat from './components/JEllipsisFormat.vue';
import { useModal } from '/@/components/Modal';
import { BasicTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { downloadFile } from '/@/utils/common/renderUtils';
  //注册model
  const [registerModal, {openModal}] = useModal();
  const [registerConfigModal, {openModal:openConfigModal}] = useModal();


function goToCa(record){
     openConfigModal(true, {
       record,
       isUpdate: true,
       showFooter: false,
     });
}
  const showBtn = ref(false)
  const props = defineProps({
    complianeInfoRecord: {}
  });
  const emit = defineEmits(['success']);
  const checkedKeys = ref<Array<string | number>>([]);
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '',
           api: list,
           columns,
           canResize:false,
           showTableSetting: false,
           useSearchForm: false,
           immediate: false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 160,
               fixed:'right'
            },
      },
       exportConfig: {
            name:"合规处罚",
            url: getExportUrl,
          },
          importConfig: {
            url: getImportUrl,
            success: handleSuccess
          },
  })

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

   /**
    * 新增事件
    */
  function handleAdd() {
     openModal(true, {
      complianeNo: props.complianeInfoRecord.complianeNo,
       isUpdate: false,
       showFooter: true,
     });
  }
   /**
    * 编辑事件
    */
  function handleEdit(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: true,
     });
   }
   /**
    * 详情
   */
  function handleDetail(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: false,
     });
   }
   /**
    * 删除事件
    */
  async function handleDelete(record) {
     await deleteOne({id: record.id}, handleSuccess);
   }
   /**
    * 批量删除事件
    */
  async function batchHandleDelete() {
     await batchDelete({ids: selectedRowKeys.value}, handleSuccess);
   }
   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
      emit('success')
   }
   /**
      * 操作栏
      */
  function getTableAction(record){
       return [
         {
           label: '检查',
           onClick: handleEdit.bind(null, record),
         },
         {
           label: '查看',
           onClick: handleDetail.bind(null, record),
         }, 
       ]
   }
     /**
        * 下拉操作栏
        */
  function getDropDownAction(record){
       return [
        //  {
        //    label: '详情',
        //    onClick: handleDetail.bind(null, record),
        //  }, 
       ]
   }

   defineExpose({setProps,reload})
</script>

<style scoped>

</style>