<script lang="ts" setup>
|
import type { OaNoticeApi } from '#/api/bpm/oa/notice';
|
|
import { computed, ref } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { message } from 'ant-design-vue';
|
|
import { useVbenForm } from '#/adapter/form';
|
import { createNotice, getNotice, updateNotice } from '#/api/bpm/oa/notice';
|
import { $t } from '#/locales';
|
import UserSelect from '#/views/system/user/components/select.vue';
|
|
import { SEND_SCOPE, useFormSchema } from '../data';
|
|
const emit = defineEmits(['success']);
|
const formData = ref<OaNoticeApi.NoticeVO>();
|
const selectedUserIds = ref<number[]>([]);
|
const currentSendScope = ref<number>(SEND_SCOPE.ALL);
|
|
const getTitle = computed(() => {
|
return formData.value?.id
|
? $t('ui.actionTitle.edit', ['通知公告'])
|
: $t('ui.actionTitle.create', ['通知公告']);
|
});
|
|
const [Form, formApi] = useVbenForm({
|
commonConfig: {
|
componentProps: {
|
class: 'w-full',
|
},
|
formItemClass: 'col-span-2',
|
labelWidth: 80,
|
},
|
layout: 'horizontal',
|
schema: useFormSchema(),
|
showDefaultActions: false,
|
handleValuesChange: (values) => {
|
currentSendScope.value = (values.sendScope as number) ?? SEND_SCOPE.ALL;
|
},
|
});
|
|
const [Modal, modalApi] = useVbenModal({
|
async onConfirm() {
|
const { valid } = await formApi.validate();
|
if (!valid) {
|
return;
|
}
|
// 发送范围为指定人时校验
|
if (currentSendScope.value === SEND_SCOPE.SPECIFIC && selectedUserIds.value.length === 0) {
|
message.warning('请选择指定人员');
|
return;
|
}
|
modalApi.lock();
|
const data = (await formApi.getValues()) as OaNoticeApi.NoticeSaveReqVO;
|
// 合并指定人员
|
if (currentSendScope.value === SEND_SCOPE.SPECIFIC) {
|
data.userIds = selectedUserIds.value;
|
}
|
try {
|
await (formData.value?.id ? updateNotice(data) : createNotice(data));
|
await modalApi.close();
|
emit('success');
|
message.success($t('ui.actionMessage.operationSuccess'));
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
async onOpenChange(isOpen: boolean) {
|
if (!isOpen) {
|
formData.value = undefined;
|
selectedUserIds.value = [];
|
currentSendScope.value = SEND_SCOPE.ALL;
|
return;
|
}
|
const data = modalApi.getData<OaNoticeApi.NoticeVO>();
|
if (!data || !data.id) {
|
return;
|
}
|
modalApi.lock();
|
try {
|
formData.value = await getNotice(data.id);
|
await formApi.setValues(formData.value);
|
selectedUserIds.value = formData.value.userIds ?? [];
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
});
|
</script>
|
|
<template>
|
<Modal :title="getTitle" class="w-1/2">
|
<Form class="mx-4" />
|
<div
|
v-if="currentSendScope === SEND_SCOPE.SPECIFIC"
|
class="mx-4 mt-4"
|
>
|
<div class="mb-2 text-sm text-gray-700">指定人员</div>
|
<UserSelect
|
v-model:value="selectedUserIds"
|
:multiple="true"
|
placeholder="请选择指定人员"
|
/>
|
</div>
|
</Modal>
|
</template>
|