mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 12:29:20 +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 { ShopVO } from '#/api/ecommerce/shop/types';
|
||||||
import type { PageQueryDTO } from '#/types/common';
|
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';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
@@ -50,16 +50,23 @@ interface Emits {
|
|||||||
(e: 'cancel'): void;
|
(e: 'cancel'): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建 vben modal
|
// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
draggable: true,
|
draggable: true,
|
||||||
class: 'w-[800px]',
|
class: 'w-[800px]',
|
||||||
|
destroyOnClose: false,
|
||||||
onCancel() {
|
onCancel() {
|
||||||
handleCancel();
|
handleCancel();
|
||||||
},
|
},
|
||||||
onConfirm() {
|
onConfirm() {
|
||||||
handleOk();
|
handleOk();
|
||||||
},
|
},
|
||||||
|
onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
emit('update:open', false);
|
||||||
|
resetFormData();
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 响应式数据
|
// 响应式数据
|
||||||
@@ -120,41 +127,42 @@ const brushTimeValue = computed({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听props变化
|
// 监听 props.open:先准备好表单再 open,关闭时同步 modalApi
|
||||||
watch(
|
watch(
|
||||||
() => props.open,
|
() => props.open,
|
||||||
(newVal) => {
|
async (newVal) => {
|
||||||
if (newVal) {
|
if (!newVal) {
|
||||||
modalApi.open();
|
modalApi.close();
|
||||||
isEdit.value = !!props.brushOrderData;
|
return;
|
||||||
if (props.brushOrderData) {
|
}
|
||||||
// 编辑模式,填充表单数据
|
isEdit.value = !!props.brushOrderData;
|
||||||
formData.value = {
|
if (props.brushOrderData) {
|
||||||
shopId: props.brushOrderData.shopId,
|
// 编辑模式,填充表单数据
|
||||||
productId: props.brushOrderData.productId,
|
formData.value = {
|
||||||
productSpecId: props.brushOrderData.productSpecId,
|
shopId: props.brushOrderData.shopId,
|
||||||
brushAmount: props.brushOrderData.brushAmount,
|
productId: props.brushOrderData.productId,
|
||||||
brushTime: props.brushOrderData.brushTime
|
productSpecId: props.brushOrderData.productSpecId,
|
||||||
? dayjs(props.brushOrderData.brushTime).format('YYYY-MM-DD HH:mm:ss')
|
brushAmount: props.brushOrderData.brushAmount,
|
||||||
: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
brushTime: props.brushOrderData.brushTime
|
||||||
platformOrderNo: props.brushOrderData.platformOrderNo,
|
? dayjs(props.brushOrderData.brushTime).format('YYYY-MM-DD HH:mm:ss')
|
||||||
quantity: props.brushOrderData.quantity || 1,
|
: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
remark: props.brushOrderData.remark,
|
platformOrderNo: props.brushOrderData.platformOrderNo,
|
||||||
};
|
quantity: props.brushOrderData.quantity || 1,
|
||||||
// 如果有商品ID,加载商品和规格选项
|
remark: props.brushOrderData.remark,
|
||||||
if (props.brushOrderData.productId) {
|
};
|
||||||
searchProducts('');
|
if (props.brushOrderData.productId) {
|
||||||
if (props.brushOrderData.productSpecId) {
|
searchProducts('');
|
||||||
searchProductSpecs('');
|
if (props.brushOrderData.productSpecId) {
|
||||||
}
|
searchProductSpecs('');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 新增模式,重置表单数据
|
|
||||||
resetFormData();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
modalApi.close();
|
resetFormData();
|
||||||
}
|
}
|
||||||
|
await nextTick();
|
||||||
|
modalApi.open();
|
||||||
|
await nextTick();
|
||||||
|
formRef.value?.clearValidate?.();
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
@@ -290,7 +298,6 @@ const handleOk = async () => {
|
|||||||
|
|
||||||
emit('success');
|
emit('success');
|
||||||
modalApi.close();
|
modalApi.close();
|
||||||
emit('update:open', false);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if ((error as any)?.errorFields) {
|
if ((error as any)?.errorFields) {
|
||||||
// 表单验证错误
|
// 表单验证错误
|
||||||
@@ -301,12 +308,10 @@ const handleOk = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 取消操作
|
// 取消:关闭与重置由 onOpenChange 统一处理
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
emit('cancel');
|
emit('cancel');
|
||||||
modalApi.close();
|
modalApi.close();
|
||||||
emit('update:open', false);
|
|
||||||
resetFormData();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 组件挂载时加载数据
|
// 组件挂载时加载数据
|
||||||
|
|||||||
+38
-35
@@ -47,16 +47,23 @@ interface Emits {
|
|||||||
(e: 'cancel'): void;
|
(e: 'cancel'): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建 vben modal
|
// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
draggable: true,
|
draggable: true,
|
||||||
class: 'w-[800px]',
|
class: 'w-[800px]',
|
||||||
|
destroyOnClose: false,
|
||||||
onCancel() {
|
onCancel() {
|
||||||
handleCancel();
|
handleCancel();
|
||||||
},
|
},
|
||||||
onConfirm() {
|
onConfirm() {
|
||||||
handleOk();
|
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 feeTypeList = ref<PromotionFeeTypeVO.Info[]>([]);
|
||||||
const feeTypeListLoading = ref(false);
|
const feeTypeListLoading = ref(false);
|
||||||
|
|
||||||
// 监听props变化
|
// 监听 props.open:先准备好表单再 open,关闭时同步 modalApi
|
||||||
watch(
|
watch(
|
||||||
() => props.open,
|
() => props.open,
|
||||||
async (newVal) => {
|
async (newVal) => {
|
||||||
if (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 {
|
|
||||||
modalApi.close();
|
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');
|
emit('success');
|
||||||
modalApi.close();
|
modalApi.close();
|
||||||
emit('update:open', false);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('操作失败:', error);
|
console.error('操作失败:', error);
|
||||||
message.error(isEdit.value ? '更新失败' : '创建失败');
|
message.error(isEdit.value ? '更新失败' : '创建失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 取消操作
|
// 取消:关闭与重置由 onOpenChange 统一处理
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
emit('cancel');
|
emit('cancel');
|
||||||
modalApi.close();
|
modalApi.close();
|
||||||
emit('update:open', false);
|
|
||||||
resetFormData();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 组件挂载时加载数据
|
// 组件挂载时加载数据
|
||||||
|
|||||||
Reference in New Issue
Block a user