<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable"   :rowSelection="rowSelection">
       <template #tableTitle>
            <a-button type="primary" @click="batchHandleConfirm" >批量分配</a-button>
            <a-button type="primary" @click="loadPro" >导出问题清单</a-button>
       </template>
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
      </BasicTable>
    <!-- 表单区域 -->
    <StProjectExecFourModal @register="registerModal" @success="handleSuccess"></StProjectExecFourModal>
    <StProjectExecFourModalc @register="registerModalc" @success="handleSuccess"></StProjectExecFourModalc>
     <StProjectExecFourConfig @register="registerModalConfig" @success="handleSuccess"></StProjectExecFourConfig>
  </div>
</template>

<script lang="ts" name="project.report-StProjectExecFour" setup>
  import {ref, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import StProjectExecFourModal from './components/StProjectExecFourModal.vue'
  import StProjectExecFourModalc from './components/StProjectExecFourModalc.vue'
  import StProjectExecFourConfig from './components/StProjectExecFourConfig.vue'

  import {columns, searchFormSchema} from './StProjectExecFour.data';
  import {list, deleteOne, batchDelete, getImportUrl,getExportUrl} from './StProjectExecFour.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  const checkedKeys = ref<Array<string | number>>([]);
  const [registerModal, {openModal}] = useModal();
  const [registerModalc, {openModal:openModalc}] = useModal();
  const [registerModalConfig, {openModal:openModalcon}] = useModal();

  //注册model
  //注册model
  const props = defineProps({
    complianeInfoRecord: {}
  });
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '',
           api: list,
           columns,
           canResize:false,
           showTableSetting: false,
           useSearchForm: false,
           immediate: false,
           actionColumn: {
               width: 220,
               fixed:'right'
            },
      },
       exportConfig: {
            name:"项目问题清单",
            url: getExportUrl,
          },
          importConfig: {
            url: getImportUrl,
            success: handleSuccess
          },
  })

  const [registerTable, {reload,setProps},{ rowSelection, selectedRowKeys }] = tableContext
  
  async function batchHandleConfirm() {
      openModalc(true, {
       record:{ ids: selectedRowKeys.value },
       batchFlag:true,
       confirmFlag:true,
       isUpdate: true,
       showFooter: true,
     });
  }
   /**
    * 新增事件
    */
  function loadPro() {
    console.log(props.complianeInfoRecord);
     openModalcon(true, {
      complianeInfoRecord:props.complianeInfoRecord,
       isUpdate: false,
       showFooter: true,
     });
  }
   /**
    * 编辑事件
    */
  function handleConfirm(record: Recordable) {
    console.log(record);
     openModalc(true, {
       record,
       confirmFlag:true,
       isUpdate: true,
       showFooter: true,
     });
   }
      /**
    * 编辑事件
    */
  function handleAdvice(record: Recordable) {
     openModal(true, {
       record,
       adviceFlag: true,
       isUpdate: true,
       showFooter: true,
     });
   }
      /**
    * 编辑事件
    */
  function handleEdit(record: Recordable) {
     openModal(true, {
       record,
       editFlag: true,
       isUpdate: true,
       showFooter: true,
     });
   }
   /**
    * 详情
   */
  function handleDetail(record: Recordable) {
     openModal(true, {
       record,
       isDetail: true,
       isUpdate: false,
       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();
   }
   /**
      * 操作栏
      */
  function getTableAction(record){
       return [
         {
           label: '分配',
           onClick: handleConfirm.bind(null, record),
           disabled: record['confirmStatus']=='1',
         },
                  {
           label: '修改',
           onClick: handleEdit.bind(null, record),
           disabled:record['trueStatus']!='0',
         },
                  {
           label: '确认',
           onClick: handleAdvice.bind(null, record),
           disabled: record['trueStatus']=='0'||record['trueStatus']==1|| record['confirmStatus']=='0'
           ||record['handleAdviceDis']=='0',
         },
         {
           label: '查看',
           onClick: handleDetail.bind(null, record),
         }
       ]
   }
     /**
        * 下拉操作栏
        */
  function getDropDownAction(record){
       return [
         
       ]
   }

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

<style scoped>

</style>