Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
88 lines
2.7 KiB
Vue
88 lines
2.7 KiB
Vue
<script lang="ts" setup>
|
||
import { ref } from 'vue';
|
||
|
||
import { useVbenModal } from '@vben/common-ui';
|
||
|
||
import { message } from 'ant-design-vue';
|
||
|
||
import { useVbenForm } from '#/adapter/form';
|
||
// 导入药店管理的表单配置
|
||
import { modalFormProps } from '#/views/system/pharmacy/config/form';
|
||
|
||
// 直接使用store的API接口
|
||
import { createStore, updateStore } from '#/views/system/store/api';
|
||
import dayjs from "dayjs";
|
||
|
||
// 是否为更新模式(true=编辑,false=新增)
|
||
const isUpdate = ref(false);
|
||
// 表格API引用,用于刷新表格数据
|
||
const gridApi = ref();
|
||
|
||
// 初始化表单
|
||
const [Form, formApi] = useVbenForm(modalFormProps);
|
||
|
||
// 初始化弹窗
|
||
const [Modal, modalApi] = useVbenModal({
|
||
fullscreenButton: false, // 不显示全屏按钮
|
||
draggable: true, // 可拖拽
|
||
// 取消按钮回调
|
||
onCancel() {
|
||
modalApi.close();
|
||
},
|
||
// 确认按钮回调(提交表单)
|
||
onConfirm: async () => {
|
||
// 验证表单
|
||
formApi.validate().then(async (e: any) => {
|
||
if (e.valid) {
|
||
// 获取表单值
|
||
const values = await formApi.getValues();
|
||
// 设置加载状态
|
||
modalApi.setState({ loading: true, confirmLoading: true });
|
||
// 根据是否为更新模式选择不同的API
|
||
const submitApi = isUpdate.value ? updateStore : createStore;
|
||
// 提交数据
|
||
submitApi(values)
|
||
.then(() => {
|
||
message.success('保存成功');
|
||
// 刷新表格数据
|
||
gridApi.value?.reload();
|
||
// 关闭弹窗
|
||
modalApi.close();
|
||
})
|
||
.finally(() => {
|
||
// 取消加载状态
|
||
modalApi.setState({ loading: false, confirmLoading: false });
|
||
});
|
||
}
|
||
});
|
||
await formApi.validateAndSubmitForm();
|
||
},
|
||
// 弹窗打开/关闭状态变化回调
|
||
onOpenChange(isOpen: boolean) {
|
||
// 获取表格API引用
|
||
gridApi.value = isOpen ? modalApi.getData()?.gridApi : null;
|
||
if (isOpen) {
|
||
// 获取传入的数据
|
||
const { values, update } = modalApi.getData<Record<string, any>>();
|
||
if (values) {
|
||
// 设置是否为更新模式
|
||
isUpdate.value = update;
|
||
// 处理地址字段(转换为数组格式)
|
||
values.address = [values.province_id, values.city_id];
|
||
// 设置表单值,并处理时间字段(转换为dayjs对象)
|
||
formApi.setValues({
|
||
...values,
|
||
start_time: dayjs(values.start_time, 'HH:mm'),
|
||
end_time: dayjs(values.end_time, 'HH:mm')
|
||
});
|
||
}
|
||
}
|
||
},
|
||
});
|
||
</script>
|
||
<template>
|
||
<Modal :title="`${isUpdate === true ? '编辑' : '新增'}药店`" class="w-[50%]">
|
||
<Form />
|
||
</Modal>
|
||
</template>
|