<template> <BasicModal v-bind="$attrs" @register="register" title="修改应付款日期" width="500px" :bodyStyle="{ height: '240px' }" @visible-change="handleShow" @ok="handleOk" > 请选择日期: <a-date-picker v-model:value="date" /> <div style="height: 10px"></div> </BasicModal> </template> <script lang="ts" setup> import { BasicModal, useModalInner } from '@/components/Modal'; import { ref } from 'vue'; import { getSetPayedDate } from '@/api/project/invoice'; import { useMessage } from '/@/hooks/web/useMessage'; const id = ref(); const date = ref(); const emit = defineEmits(['success']); const { createMessage } = useMessage(); const { error } = createMessage; const [register, { closeModal }] = useModalInner(async (data) => { id.value = data.data.id; }); function formatDate(input: string): string { // 创建一个 Date 对象 const date = new Date(input); // 获取年月日 const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始,所以要加 1 const day = String(date.getDate()).padStart(2, '0'); // 返回格式化后的日期字符串 return `${year}-${month}-${day}`; } const isDisabled = ref(false); async function handleOk() { if (isDisabled.value) { error('请勿连续点击生成按钮,需要等待三秒再点击生成'); return; } const formattedDate = formatDate(date.value); isDisabled.value = true; setTimeout(() => { isDisabled.value = false; }, 3000); getSetPayedDate({ id: id.value, payedDate: formattedDate }); emit('success'); closeModal(); } function handleShow(visible: boolean) { if (!visible) { date.value = null; } } </script>