<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="950" @ok="handleSubmit">
    <BasicTable @register="registerTable" :rowSelection="rowSelection" style="width:100%">
      
      </BasicTable>
   </BasicModal>
   
</template>

<script lang="ts" setup>
import {defHttp} from '/@/utils/http/axios';
import { onMounted, ref, toRaw } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { columns, searchFormSchema,columnsProject } from '/@/views/standardlib/controlactivity/StCaMainCollection.data';
import { BasicTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';

const emit = defineEmits(['register','success']);
 const apilist = '/act.collection/stCaMainCollection/list';
 const isUpdate = ref(true);
 const isDetail = ref(false);

 const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
        setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter});
        isUpdate.value = !!data?.isUpdate;
        isDetail.value = !data?.showFooter;
    });

  const checkedKeys = ref<Array<string | number>>([]);
    
 
  //注册table数据
  const { prefixCls,tableContext } = useListPage({
      tableProps:{
           title: '',
           api: list(),
           columns:columnsProject,
           canResize:true,
           scroll:{y:250},
           showActionColumn: false,

           formConfig: {
              // labelWidth: 200,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
  
            showTableSetting: false,
            beforeFetch(params) {
              params = Object.assign(params,{ column: 'updatedTime', order: 'desc', })
            },
      }
  })

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

   function list() {
    const list = (params) =>defHttp.get({url: apilist, params});
    return list;
   }

  async function handleSubmit() {
    try {
        closeModal();
        let tmpAry = []
        for(let i=0;i<rowSelection.selectedRows.length;i++){
          let tmpno = rowSelection.selectedRows[i]['collectionNo']
          tmpAry.push(tmpno)
        }
        emit('success',tmpAry);
    } finally {
        setModalProps({confirmLoading: false});
    }
}


</script>

<style scoped>

</style>