mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 05:09:21 +08:00
fix(ecom-dmb): 修复推广管理和刷单管理表单模态框问题
This commit is contained in:
+40
-35
@@ -8,7 +8,7 @@ import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
@@ -50,16 +50,23 @@ interface Emits {
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 创建 vben modal
|
||||
// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[800px]',
|
||||
destroyOnClose: false,
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleOk();
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
emit('update:open', false);
|
||||
resetFormData();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
@@ -120,41 +127,42 @@ const brushTimeValue = computed({
|
||||
},
|
||||
});
|
||||
|
||||
// 监听props变化
|
||||
// 监听 props.open:先准备好表单再 open,关闭时同步 modalApi
|
||||
watch(
|
||||
() => props.open,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
modalApi.open();
|
||||
isEdit.value = !!props.brushOrderData;
|
||||
if (props.brushOrderData) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
shopId: props.brushOrderData.shopId,
|
||||
productId: props.brushOrderData.productId,
|
||||
productSpecId: props.brushOrderData.productSpecId,
|
||||
brushAmount: props.brushOrderData.brushAmount,
|
||||
brushTime: props.brushOrderData.brushTime
|
||||
? dayjs(props.brushOrderData.brushTime).format('YYYY-MM-DD HH:mm:ss')
|
||||
: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
platformOrderNo: props.brushOrderData.platformOrderNo,
|
||||
quantity: props.brushOrderData.quantity || 1,
|
||||
remark: props.brushOrderData.remark,
|
||||
};
|
||||
// 如果有商品ID,加载商品和规格选项
|
||||
if (props.brushOrderData.productId) {
|
||||
searchProducts('');
|
||||
if (props.brushOrderData.productSpecId) {
|
||||
searchProductSpecs('');
|
||||
}
|
||||
async (newVal) => {
|
||||
if (!newVal) {
|
||||
modalApi.close();
|
||||
return;
|
||||
}
|
||||
isEdit.value = !!props.brushOrderData;
|
||||
if (props.brushOrderData) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
shopId: props.brushOrderData.shopId,
|
||||
productId: props.brushOrderData.productId,
|
||||
productSpecId: props.brushOrderData.productSpecId,
|
||||
brushAmount: props.brushOrderData.brushAmount,
|
||||
brushTime: props.brushOrderData.brushTime
|
||||
? dayjs(props.brushOrderData.brushTime).format('YYYY-MM-DD HH:mm:ss')
|
||||
: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
platformOrderNo: props.brushOrderData.platformOrderNo,
|
||||
quantity: props.brushOrderData.quantity || 1,
|
||||
remark: props.brushOrderData.remark,
|
||||
};
|
||||
if (props.brushOrderData.productId) {
|
||||
searchProducts('');
|
||||
if (props.brushOrderData.productSpecId) {
|
||||
searchProductSpecs('');
|
||||
}
|
||||
} else {
|
||||
// 新增模式,重置表单数据
|
||||
resetFormData();
|
||||
}
|
||||
} else {
|
||||
modalApi.close();
|
||||
resetFormData();
|
||||
}
|
||||
await nextTick();
|
||||
modalApi.open();
|
||||
await nextTick();
|
||||
formRef.value?.clearValidate?.();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
@@ -290,7 +298,6 @@ const handleOk = async () => {
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
} catch (error) {
|
||||
if ((error as any)?.errorFields) {
|
||||
// 表单验证错误
|
||||
@@ -301,12 +308,10 @@ const handleOk = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 取消操作
|
||||
// 取消:关闭与重置由 onOpenChange 统一处理
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
resetFormData();
|
||||
};
|
||||
|
||||
// 组件挂载时加载数据
|
||||
|
||||
+38
-35
@@ -47,16 +47,23 @@ interface Emits {
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 创建 vben modal
|
||||
// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[800px]',
|
||||
destroyOnClose: false,
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleOk();
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
emit('update:open', false);
|
||||
resetFormData();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
@@ -110,41 +117,40 @@ const shopListLoading = ref(false);
|
||||
const feeTypeList = ref<PromotionFeeTypeVO.Info[]>([]);
|
||||
const feeTypeListLoading = ref(false);
|
||||
|
||||
// 监听props变化
|
||||
// 监听 props.open:先准备好表单再 open,关闭时同步 modalApi
|
||||
watch(
|
||||
() => props.open,
|
||||
async (newVal) => {
|
||||
if (newVal) {
|
||||
// 等渲染周期完成后再 open,避免 Slot 依赖追踪失效
|
||||
await nextTick();
|
||||
modalApi.open();
|
||||
isEdit.value = !!props.promotionFeeData;
|
||||
if (props.promotionFeeData) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
shopId: props.promotionFeeData.shopId,
|
||||
feeTypeId: props.promotionFeeData.feeTypeId,
|
||||
feeName: props.promotionFeeData.feeName,
|
||||
platform: props.promotionFeeData.platform,
|
||||
campaignName: props.promotionFeeData.campaignName || '',
|
||||
feeAmount: props.promotionFeeData.feeAmount,
|
||||
baseAmount: props.promotionFeeData.baseAmount,
|
||||
feeRate: props.promotionFeeData.feeRate,
|
||||
clickCount: props.promotionFeeData.clickCount,
|
||||
impressionCount: props.promotionFeeData.impressionCount,
|
||||
conversionCount: props.promotionFeeData.conversionCount,
|
||||
feeDate: props.promotionFeeData.feeDate
|
||||
? dayjs(props.promotionFeeData.feeDate)
|
||||
: undefined,
|
||||
remark: props.promotionFeeData.remark || '',
|
||||
};
|
||||
} else {
|
||||
// 新增模式,重置表单数据
|
||||
resetFormData();
|
||||
}
|
||||
} else {
|
||||
if (!newVal) {
|
||||
modalApi.close();
|
||||
return;
|
||||
}
|
||||
isEdit.value = !!props.promotionFeeData;
|
||||
if (props.promotionFeeData) {
|
||||
formData.value = {
|
||||
shopId: props.promotionFeeData.shopId,
|
||||
feeTypeId: props.promotionFeeData.feeTypeId,
|
||||
feeName: props.promotionFeeData.feeName,
|
||||
platform: props.promotionFeeData.platform,
|
||||
campaignName: props.promotionFeeData.campaignName || '',
|
||||
feeAmount: props.promotionFeeData.feeAmount,
|
||||
baseAmount: props.promotionFeeData.baseAmount,
|
||||
feeRate: props.promotionFeeData.feeRate,
|
||||
clickCount: props.promotionFeeData.clickCount,
|
||||
impressionCount: props.promotionFeeData.impressionCount,
|
||||
conversionCount: props.promotionFeeData.conversionCount,
|
||||
feeDate: props.promotionFeeData.feeDate
|
||||
? dayjs(props.promotionFeeData.feeDate)
|
||||
: undefined,
|
||||
remark: props.promotionFeeData.remark || '',
|
||||
};
|
||||
} else {
|
||||
resetFormData();
|
||||
}
|
||||
await nextTick();
|
||||
modalApi.open();
|
||||
await nextTick();
|
||||
formRef.value?.clearValidate?.();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -218,19 +224,16 @@ const handleOk = async () => {
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
} catch (error) {
|
||||
console.error('操作失败:', error);
|
||||
message.error(isEdit.value ? '更新失败' : '创建失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 取消操作
|
||||
// 取消:关闭与重置由 onOpenChange 统一处理
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
resetFormData();
|
||||
};
|
||||
|
||||
// 组件挂载时加载数据
|
||||
|
||||
Reference in New Issue
Block a user