Commit e9606252 by zhangxw

营销活动bug修复

1 parent 810d3af2
......@@ -416,8 +416,6 @@ export default {
this.directPackages = list.map(item => ({
...item,
productType: item.packageCode ? 0 : 1,
// 套餐字段映射:优先使用 packageId(接口返回字段),其次 packageCode
packageId: item.packageId || item.packageCode,
packageName: item.packageName || "",
tabName: item.tabName || item.packageName || "",
packageCode: item.packageCode || "",
......@@ -469,8 +467,6 @@ export default {
const packages = (series.packageList || []).map(item => ({
...item,
productType: 0,
// 套餐字段映射:优先使用 packageId(接口返回字段),其次 packageCode
packageId: item.packageId || item.packageCode,
packageName: item.packageName || "",
tabName: item.tabName || "",
packageCode: item.packageCode || "",
......@@ -644,10 +640,10 @@ export default {
const currentPackages = this.seriesPackages[seriesId] || [];
this.tempSelectedItems = currentPackages.map((item) => {
if (item.productType === 0) {
// 套餐:优先使用 packageId(来自选择弹窗接口数据),其次尝试 packageCode 或 code
// 套餐
return {
...item,
packageId: item.packageId || item.packageCode || item.code,
packageCode: item.packageCode,
productType: 0,
productName: item.packageName || item.productName || "",
};
......@@ -671,18 +667,18 @@ export default {
return;
}
// 按车系模式:用 packageId/goodsCode 做唯一匹配,保留已编辑数据
// 按车系模式:用 packageCode/goodsCode 做唯一匹配,保留已编辑数据
const existingList = this.seriesPackages[this.currentSeriesId] || [];
const existingMap = {};
existingList.forEach((item) => {
const key = item.productType == 0 ? (item.packageId) : (item.goodsCode);
const key = item.productType == 0 ? (item.packageCode) : (item.goodsCode);
if (key)
existingMap[key] = item;
});
const newList = selectedItems.map((item) => {
// 唯一匹配key:套餐用 packageId,商品用 goodsCode
const matchKey = item.productType === 0 ? (item.packageId) : item.goodsCode;
// 唯一匹配key:套餐用 packageCode,商品用 goodsCode
const matchKey = item.productType === 0 ? (item.packageCode) : item.goodsCode;
if (matchKey && existingMap[matchKey]) {
// 已存在:保留原有编辑数据,但同步最新门店数
const merged = { ...existingMap[matchKey] };
......@@ -748,17 +744,17 @@ export default {
// 执行添加直接模式套餐/商品(公共逻辑)
doAddDirectPackages(selectedItems) {
// 用 packageId/goodsCode 做唯一匹配,保留已编辑数据
// 用 packageCode/goodsCode 做唯一匹配,保留已编辑数据
const existingMap = {};
this.directPackages.forEach((item) => {
const key = item.productType === 0 ? (item.packageId || item.packageCode || item.code) : (item.goodsCode || item.code);
const key = item.productType === 0 ? (item.packageCode) : (item.goodsCode);
if (key)
existingMap[key] = item;
});
this.directPackages = selectedItems.map((item) => {
// 唯一匹配key:套餐用 packageId,商品用 goodsCode
const matchKey = item.productType === 0 ? (item.packageId || item.packageCode) : item.goodsCode;
// 唯一匹配key:套餐用 packageCode,商品用 goodsCode
const matchKey = item.productType === 0 ? (item.packageCode) : item.goodsCode;
if (matchKey && existingMap[matchKey]) {
// 已存在:保留原有编辑数据,但同步最新门店数
const merged = { ...existingMap[matchKey] };
......@@ -1073,7 +1069,7 @@ export default {
productType: 0,
productName: item.packageName || item.productName,
productAlias: item.productAlias,
packageCode: item.packageId,
packageCode: item.packageCode,
sortOrder: i + 1,
tabName: item.tabName,
tabDescription: item.tabDescription,
......@@ -1174,10 +1170,10 @@ export default {
return;
}
this.currentSeriesId = ""; // 标记为直接模式
// 提取原始标识字段用于弹窗回显,确保 packageId/goodsCode 字段存在
// 提取原始标识字段用于弹窗回显,确保 packageCode/goodsCode 字段存在
this.tempSelectedItems = (this.directPackages || []).map((item) => {
if (item.productType === 0) {
return { ...item, productType: 0, packageId: item.packageId || item.packageCode || item.code, productName: item.packageName || item.productName || "" };
return { ...item, productType: 0, packageCode: item.packageCode, productName: item.packageName || item.productName || "" };
}
return { ...item, productType: 1, goodsCode: item.goodsCode || item.code, productName: item.productName || "" };
});
......
......@@ -54,14 +54,14 @@
<!-- 手风琴列表(Sortable 拖拽整个 item) -->
<el-collapse v-model="activeNames" class="package-collapse">
<el-collapse-item v-for="(pkg, index) in localList"
:key="pkg.packageId"
:key="pkg.packageCode"
class="package-item"
:name="pkg.packageId">
:name="pkg.packageCode">
<!-- 标题行:模拟表格的一行数据 -->
<template slot="title">
<div class="collapse-row"
:class="{ 'is-expanded': activeNames.includes(pkg.packageId) }"
:class="{ 'is-expanded': activeNames.includes(pkg.packageCode) }"
@click.stop
@keydown.stop
@keyup.stop>
......@@ -70,8 +70,8 @@
</span>
<span class="col col-index"
style="cursor: pointer;"
@click.stop="toggleExpand(pkg.packageId)">
<i :class="[activeNames.includes(pkg.packageId) ? 'el-icon-arrow-down' : 'el-icon-arrow-right']"></i>
@click.stop="toggleExpand(pkg.packageCode)">
<i :class="[activeNames.includes(pkg.packageCode) ? 'el-icon-arrow-down' : 'el-icon-arrow-right']"></i>
{{ index + 1 }}
</span>
<span class="col col-name"
......@@ -83,7 +83,7 @@
size="mini"
:class="{ 'is-error': pkg.tabNameError }"
@input="clearError(pkg, 'tabNameError')" />
<div class="sub-text">{{ pkg.packageId }}</div>
<div class="sub-text">{{ pkg.packageCode }}</div>
</span>
<span class="col col-tabDescription"
@keydown.stop
......@@ -223,7 +223,7 @@
</template>
<!-- 展开内容:子商品 div 模拟表格 -->
<div v-loading="packageLoadingMap[pkg.packageId]"
<div v-loading="packageLoadingMap[pkg.packageCode]"
class="collapse-content">
<!-- 子商品表头 -->
<div class="sub-table-header">
......@@ -325,35 +325,35 @@ export default {
* 切换套餐项展开/收起(只有点击箭头/排序号区域才触发)
* 展开时若套餐无子商品数据,自动请求接口获取
*/
toggleExpand(packageId) {
const idx = this.activeNames.indexOf(packageId);
toggleExpand(packageCode) {
const idx = this.activeNames.indexOf(packageCode);
if (idx > -1) {
this.activeNames.splice(idx, 1);
} else {
this.activeNames.push(packageId);
this.activeNames.push(packageCode);
// 展开时检查是否需要加载子商品
this.loadPackageProducts(packageId);
this.loadPackageProducts(packageCode);
}
},
/**
* 加载套餐子商品数据(每次展开时调用,合并新旧数据保留用户输入)
*/
loadPackageProducts(packageId) {
const idx = this.localList.findIndex(p => p.packageId === packageId);
loadPackageProducts(packageCode) {
const idx = this.localList.findIndex(p => p.packageCode === packageCode);
if (idx < 0)
return;
const pkg = this.localList[idx];
if (!pkg.packageId)
if (!pkg.packageCode)
return;
// 设置loading状态
this.$set(this.packageLoadingMap, packageId, true);
this.$set(this.packageLoadingMap, packageCode, true);
// 保存旧的子商品数据(用于合并)
const oldItems = pkg.packageItems || [];
getGoodsDataByPackage({ packageId: pkg.packageId }).then((res) => {
getGoodsDataByPackage({ packageId: pkg.packageCode }).then((res) => {
if (!res || !res.length) {
// 如果新数据为空,清空子商品列表
pkg.packageItems = [];
......@@ -385,7 +385,7 @@ export default {
pkg.packageItems = mergedItems;
}).finally(() => {
// 清除loading状态
this.$set(this.packageLoadingMap, packageId, false);
this.$set(this.packageLoadingMap, packageCode, false);
});
},
......
......@@ -98,7 +98,7 @@
label="套餐ID"
width="200">
<template #default="scope">
{{ emptyFilter(scope.row.packageId) }}
{{ emptyFilter(scope.row.packageCode) }}
</template>
</el-table-column>
</template>
......@@ -193,7 +193,7 @@
套餐 ({{ packageItems.length }})
</div>
<div v-for="(item, index) in packageItems"
:key="`pkg_${item.packageId || index}`"
:key="`pkg_${item.packageCode || index}`"
class="selected-item">
<div class="item-info">
<div class="item-name">
......@@ -437,8 +437,9 @@ export default {
const tabKey = isPackage ? "package" : "product";
eventRequest(params)
.then((res) => {
const savedIds = (this.selectedMap[tabKey] || []).map(item => (isPackage ? item.packageId : item.goodsCode));
const savedIds = (this.selectedMap[tabKey] || []).map(item => (isPackage ? item.packageCode : item.goodsCode));
res?.list?.forEach((val) => {
val.packageCode = val.packageId;
val.productName = val.productName || val.packageName;
val.upgradeProductId = val.productId;
});
......@@ -448,7 +449,7 @@ export default {
this.$nextTick(() => {
if (this.$refs.tableRef) {
this.tableData.forEach((row) => {
if (savedIds.includes(isPackage ? row.packageId : row.goodsCode)) {
if (savedIds.includes(isPackage ? row.packageCode : row.goodsCode)) {
this.$refs.tableRef.toggleRowSelection(row, true);
}
});
......@@ -489,7 +490,7 @@ export default {
return;
}
const isPackage = this.activeTab === "0";
const idField = isPackage ? "packageId" : "goodsCode";
const idField = isPackage ? "packageCode" : "goodsCode";
const tabKey = isPackage ? "package" : "product";
// 当前页所有数据的 id 集合
const currentPageIds = this.tableData.map(row => row[idField]);
......@@ -511,13 +512,13 @@ export default {
// 移除已选项
handleRemoveItem(item) {
const tab = item.productType === 0 ? "package" : "product";
const idx = this.selectedMap[tab].findIndex(s => tab === "package" ? s.packageId === item.packageId : s.goodsCode === item.goodsCode);
const idx = this.selectedMap[tab].findIndex(s => tab === "package" ? s.packageCode === item.packageCode : s.goodsCode === item.goodsCode);
if (idx === -1)
return;
this.selectedMap[tab].splice(idx, 1);
// 取消表格中的选中状态
this.$nextTick(() => {
const row = this.tableData.find(s => tab === "package" ? s.packageId === item.packageId : s.goodsCode === item.goodsCode);
const row = this.tableData.find(s => tab === "package" ? s.packageCode === item.packageCode : s.goodsCode === item.goodsCode);
if (row && this.$refs.tableRef) {
this.$refs.tableRef.toggleRowSelection(row, false);
}
......
......@@ -83,7 +83,7 @@ export default {
getMerchantData() {
const params = {
goodsCode: this.storeRow.goodsCode,
packageCode: this.storeRow.packageId,
packageCode: this.storeRow.packageCode,
activityId: this.storeRow?.activityId,
merchantIds: this.merchantList?.map((val) => {
return val.merchantId;
......
......@@ -98,7 +98,7 @@
<div class="card-content">
<!-- ========== 直接选择模式:套餐+商品都有时显示子tab ========== -->
<template v-if="detailData.configMode === 'direct' && directSplit.packages.length && directSplit.products.length">
<template v-if="detailData.configMode === 'direct' && directSplit.packages && directSplit.packages.length && directSplit.products && directSplit.products.length">
<el-tabs v-model="directSubActiveTab" class="sub-tabs direct-sub-tabs">
<el-tab-pane name="direct_package">
<template #label>
......@@ -116,7 +116,7 @@
</template>
<!-- 直接模式:只有套餐或只有商品 -->
<template v-else-if="detailData.configMode === 'direct' && detailData.directPackages.length">
<template v-else-if="detailData.configMode === 'direct' && detailData.directPackages && detailData.directPackages.length">
<MixedDetailTable :list="detailData.directPackages" />
</template>
......@@ -131,7 +131,7 @@
:name="String(series.carSeriesId)">
<!-- 该车系同时有套餐和商品:显示子tabs -->
<template v-if="series.packageList.length && series.goodsList.length">
<template v-if="series.packageList && series.packageList.length && series.goodsList && series.goodsList.length">
<el-tabs class="sub-tabs" :value="getSeriesSubTabId(series.carSeriesId)">
<el-tab-pane :name="`package_${series.carSeriesId}`">
<template #label>
......@@ -150,7 +150,7 @@
<!-- 该车系只有套餐或只有商品:单表展示 -->
<template v-else>
<MixedDetailTable :list="series.packageList.length ? series.packageList : series.goodsList.length ? series.goodsList : []" />
<MixedDetailTable :list="series.packageList && series.packageList.length ? series.packageList : series.goodsList && series.goodsList.length ? series.goodsList : []" />
</template>
</el-tab-pane>
</el-tabs>
......@@ -426,6 +426,7 @@ export default {
getActivityCarSeries() {
this.startLoading();
getMarketingActivityCarSeries({ activityId: this.activityId, includeDetail: true, pageSize: 999 }).then((res) => {
console.log(res, "222222");
this.activeSeriesId = String(res?.[0]?.carSeriesId || "");
this.detailData.seriesList = res || [];
}).finally(() => this.endLoading());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!