<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800">
       <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </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>
    <StPlanManTranceModal @register="registerModal1"></StPlanManTranceModal>
  </BasicModal>
</template>

<script lang="ts" setup>
import { computed, ref, unref } from 'vue';
import { trancelist } from '../StPlanMan.api';
import { columns, searchFormSchema } from '../StPlanManTrance.data';
import StPlanManTranceModal from './StPlanManTranceModal.vue';
import { BasicModal, useModal, useModalInner } from '/@/components/Modal';
import { BasicTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { downloadFile } from '/@/utils/common/renderUtils';
const [registerModal1, {openModal}] = useModal();
    // Emits声明
    const emit = defineEmits(['register','success']);
    const isUpdate = ref(true);
    const handleFlag = ref('')
    const planCode = ref('')
    const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
        setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter});
        isUpdate.value = !!data?.isUpdate;
        handleFlag.value =  data.planFlag
        planCode.value = data.record['planCode']
    });
     //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '',
           api: trancelist,
           columns,
           canResize:false,
           useSearchForm: false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 60,
               fixed:'right'
            },
            showTableSetting: false,
            beforeFetch(params) {
              params = Object.assign(params,{ column: 'updatedTime', order: 'desc',planCode:planCode.value})
            },
      }
  })

  const [registerTable, {setProps,reload},{ rowSelection, selectedRowKeys }] = tableContext
    //设置标题
    const title = computed(() => (!unref(isUpdate) ? '变更记录' : '变更记录'));

function handleDetail(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: false,
     });
   }
     /**
      * 操作栏
      */
  function getTableAction(record){
       return [
         {
           label: '详情',
           onClick: handleDetail.bind(null, record),
         }, 
       ]
   }
     /**
        * 下拉操作栏
        */
  function getDropDownAction(record){
       return [
       ]
   }
</script>

<style lang="less" scoped>
	/** 时间和数字输入框样式 */
  :deep(.ant-input-number){
		width: 100%
	}

	:deep(.ant-calendar-picker){
		width: 100%
	}
</style>