|
|
@@ -19,7 +19,6 @@
|
|
|
<template #operation="scope">
|
|
|
<el-button link type="primary" @click="editRow(scope.row)"> 编辑 </el-button>
|
|
|
<el-button link type="primary" @click="deleteRow(scope.row)"> 删除 </el-button>
|
|
|
- <el-button v-if="scope.row.status === 0" link type="primary" @click="handleApprove(scope.row)"> 同意 </el-button>
|
|
|
</template>
|
|
|
</ProTable>
|
|
|
|
|
|
@@ -30,6 +29,13 @@
|
|
|
<el-input v-model="formData.acName" placeholder="请输入" clearable />
|
|
|
</el-form-item>
|
|
|
|
|
|
+ <el-form-item label="赠送类型">
|
|
|
+ <el-radio-group v-model="formData.distributeType" @change="onDistributeTypeChange">
|
|
|
+ <el-radio :label="1"> 满减券 </el-radio>
|
|
|
+ <el-radio :label="2"> 折扣券 </el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
<el-form-item label="消费门槛金额(¥)">
|
|
|
<div style="display: flex; gap: 10px; align-items: center; width: 100%">
|
|
|
<el-form-item prop="moneyLow" style="flex: 1; margin-bottom: 0">
|
|
|
@@ -64,35 +70,37 @@
|
|
|
|
|
|
<el-form-item label="来源商家及优惠券">
|
|
|
<div class="merchant-coupon-list">
|
|
|
- <div v-for="(item, index) in formData.details" :key="index" class="merchant-coupon-item">
|
|
|
+ <div v-for="(item, index) in formData.coupons" :key="index" class="merchant-coupon-item">
|
|
|
<el-select
|
|
|
- v-model="item.friendStoreUserId"
|
|
|
+ v-model="item.merchant"
|
|
|
placeholder="选择商家"
|
|
|
style="width: 200px; margin-right: 10px"
|
|
|
+ filterable
|
|
|
@change="handleMerchantChange(index)"
|
|
|
>
|
|
|
<el-option
|
|
|
- v-for="merchant in merchantList"
|
|
|
- :key="merchant.couponId"
|
|
|
- :label="merchant.storeName"
|
|
|
- :value="merchant.couponId"
|
|
|
+ v-for="(m, idx) in effectiveMerchantOptions"
|
|
|
+ :key="m.label ? `${String(m.value)}_${m.label}_${idx}` : String(m.value)"
|
|
|
+ :label="m.label"
|
|
|
+ :value="m.value"
|
|
|
/>
|
|
|
</el-select>
|
|
|
<el-select
|
|
|
- v-model="item.couponId"
|
|
|
- placeholder="选择优惠券"
|
|
|
+ v-model="item.coupon"
|
|
|
+ :placeholder="formData.distributeType === 2 ? '选择折扣券' : '选择满减券'"
|
|
|
style="width: 200px; margin-right: 10px"
|
|
|
+ filterable
|
|
|
@change="handleCouponChange(index)"
|
|
|
>
|
|
|
<el-option
|
|
|
- v-for="coupon in item.couponList"
|
|
|
- :key="coupon.couponId || coupon.id"
|
|
|
- :label="coupon.couponName"
|
|
|
- :value="coupon.couponId || coupon.id"
|
|
|
+ v-for="c in getCouponOptions(formData.distributeType)"
|
|
|
+ :key="c.value"
|
|
|
+ :label="c.label"
|
|
|
+ :value="c.value"
|
|
|
/>
|
|
|
</el-select>
|
|
|
- <el-input v-model="item.remainingCount" placeholder="剩余张数1000张" style="width: 180px; margin-right: 10px" />
|
|
|
- <el-button type="danger" link @click="removeMerchantCoupon(index)" v-if="formData.details.length > 1">
|
|
|
+ <span v-if="item.coupon" class="remaining-text">剩余{{ item.remaining }}张</span>
|
|
|
+ <el-button type="danger" link @click="removeMerchantCoupon(index)" v-if="formData.coupons.length > 1">
|
|
|
删除
|
|
|
</el-button>
|
|
|
</div>
|
|
|
@@ -126,9 +134,11 @@ import { localGet } from "@/utils";
|
|
|
import {
|
|
|
getRuleList,
|
|
|
saveFriendCouponRule,
|
|
|
- getReceivedFriendCouponList,
|
|
|
+ getMutualAttention,
|
|
|
delFriendCouponRule,
|
|
|
- getRuleById
|
|
|
+ getRuleById,
|
|
|
+ getVoucherList,
|
|
|
+ getIssueCouponList
|
|
|
} from "@/api/modules/newLoginApi";
|
|
|
|
|
|
// ProTable 实例
|
|
|
@@ -143,19 +153,60 @@ const currentEditId = ref("");
|
|
|
// 表单引用
|
|
|
const formRef = ref<FormInstance>();
|
|
|
|
|
|
-// 商家列表
|
|
|
-const merchantList = ref<any[]>([]);
|
|
|
+// 商家列表(互相关注接口,仅显示 phoneId 带 store 的商家)
|
|
|
+const merchantList = ref<Array<{ value: string | number; label: string; raw?: any }>>([]);
|
|
|
+const merchantListRaw = ref<any[]>([]);
|
|
|
+
|
|
|
+// 优惠券/折扣券选项缓存 key: '1-couponList' | '2-couponList'
|
|
|
+const couponOptionsMap = ref<Record<string, Array<{ value: string; label: string }>>>({});
|
|
|
+const couponDataMap = ref<Record<string, any[]>>({});
|
|
|
+
|
|
|
+const normalizeCouponValue = (v: any) => (v != null && v !== "" ? String(v) : "");
|
|
|
+
|
|
|
+// 编辑时合并详情中的 storeName,使商家下拉能正确显示;按 label 去重,避免同一商家出现多次
|
|
|
+const effectiveMerchantOptions = computed(() => {
|
|
|
+ const base = merchantList.value || [];
|
|
|
+ const fromDetail = (formData.coupons || [])
|
|
|
+ .filter((c: any) => c.merchant != null && c.merchant !== "" && c.storeName)
|
|
|
+ .map((c: any) => ({ value: c.merchant, label: c.storeName }));
|
|
|
+ const seenValue = new Set(base.map((o: any) => o.value));
|
|
|
+ const extra = fromDetail.filter((o: any) => {
|
|
|
+ if (seenValue.has(o.value)) return false;
|
|
|
+ seenValue.add(o.value);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ const merged = [...base, ...extra];
|
|
|
+ // 按 label(店名)去重:同一店名只保留一项,优先保留在 form 中已选中的 value,避免下拉重复显示
|
|
|
+ const usedValues = new Set((formData.coupons || []).map((c: any) => c.merchant).filter((v: any) => v != null && v !== ""));
|
|
|
+ const byLabel = new Map<string, { value: string | number; label: string }>();
|
|
|
+ for (const o of merged) {
|
|
|
+ const label = o.label || "";
|
|
|
+ const existing = byLabel.get(label);
|
|
|
+ if (!existing) {
|
|
|
+ byLabel.set(label, o);
|
|
|
+ } else if (usedValues.has(o.value) && !usedValues.has(existing.value)) {
|
|
|
+ byLabel.set(label, o);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Array.from(byLabel.values());
|
|
|
+});
|
|
|
+
|
|
|
+const getCouponOptions = (distributeType: number) => {
|
|
|
+ const key = distributeType === 2 ? "2-couponList" : "1-couponList";
|
|
|
+ return couponOptionsMap.value[key] || [];
|
|
|
+};
|
|
|
|
|
|
// 表单数据
|
|
|
const formData = reactive({
|
|
|
acName: "",
|
|
|
+ distributeType: 1 as 1 | 2, // 1-满减券 2-折扣券
|
|
|
moneyLow: "" as string | number,
|
|
|
moneyHigh: "" as string | number,
|
|
|
- details: [] as Array<{
|
|
|
- friendStoreUserId: string | number;
|
|
|
- couponId: string | number;
|
|
|
- couponList: any[]; // 当前商家的优惠券列表
|
|
|
- remainingCount: number; // 剩余张数
|
|
|
+ coupons: [] as Array<{
|
|
|
+ merchant: string | number | null;
|
|
|
+ coupon: string | null;
|
|
|
+ remaining: number;
|
|
|
+ storeName?: string;
|
|
|
}>
|
|
|
});
|
|
|
|
|
|
@@ -278,10 +329,12 @@ const initParam = reactive({
|
|
|
storeId: localGet("createdId") || ""
|
|
|
});
|
|
|
|
|
|
-// 数据回调处理:兼容接口返回数组或 { records/list, total } 格式,确保有数据时分页显示正确总数
|
|
|
+// 数据回调处理:兼容接口返回数组或 { records/list, total } 格式,确保有数据时分页显示正确总数(iOS 上 total 需为明确数字)
|
|
|
const dataCallback = (data: any) => {
|
|
|
const list = Array.isArray(data) ? data : (data?.records ?? data?.list ?? []);
|
|
|
- const total = typeof data?.total === "number" ? data.total : list.length;
|
|
|
+ const totalNum =
|
|
|
+ typeof data?.total === "number" && Number.isFinite(data.total) ? data.total : Array.isArray(list) ? list.length : 0;
|
|
|
+ const total = Math.max(0, Math.floor(Number(totalNum)) || 0);
|
|
|
return {
|
|
|
list,
|
|
|
total
|
|
|
@@ -313,34 +366,55 @@ const getStatusType = (status: number): "success" | "warning" | "info" | "danger
|
|
|
return typeMap[status] || "info";
|
|
|
};
|
|
|
|
|
|
-// 获取商家列表(选择商家)
|
|
|
-const getMerchantList = async () => {
|
|
|
+// 获取商家列表(互相关注接口,仅显示 phoneId 带 store 的商家)- 与 group_merchant eachOtherInterest 参数一致
|
|
|
+const loadAddActivityMerchants = async () => {
|
|
|
+ const phone = localGet("iphone") || localGet("geeker-user")?.userInfo?.phone || "";
|
|
|
try {
|
|
|
- const res: any = await getReceivedFriendCouponList({
|
|
|
- storeId: localGet("createdId") || ""
|
|
|
+ const res: any = await getMutualAttention({
|
|
|
+ page: 1,
|
|
|
+ size: 1000,
|
|
|
+ fansId: `store_${phone}`
|
|
|
});
|
|
|
- if (res.code == 200) {
|
|
|
- merchantList.value = res.data;
|
|
|
- console.log(merchantList.value);
|
|
|
- }
|
|
|
+ const data = res?.data || res;
|
|
|
+ const records = data?.records || data?.list || (Array.isArray(data) ? data : []);
|
|
|
+ const list = Array.isArray(records) ? records : [];
|
|
|
+ const merchantListFiltered = list.filter((item: any) => {
|
|
|
+ const pid = String(item.phoneId ?? item.id ?? "");
|
|
|
+ return pid.includes("store");
|
|
|
+ });
|
|
|
+ merchantListRaw.value = merchantListFiltered;
|
|
|
+ // 按 value(id/storeId/phoneId)去重,避免同一商家在接口中多次返回导致下拉重复
|
|
|
+ const seen = new Set<string | number>();
|
|
|
+ merchantList.value = merchantListFiltered
|
|
|
+ .map((item: any) => ({
|
|
|
+ value: item.id ?? item.storeId ?? item.phoneId,
|
|
|
+ label: item.storeName ?? item.name ?? "",
|
|
|
+ raw: item
|
|
|
+ }))
|
|
|
+ .filter((o: any) => {
|
|
|
+ if (seen.has(o.value)) return false;
|
|
|
+ seen.add(o.value);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
} catch (error) {
|
|
|
console.error("获取商家列表失败", error);
|
|
|
+ merchantList.value = [];
|
|
|
+ merchantListRaw.value = [];
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 打开添加对话框
|
|
|
const openAddDialog = async () => {
|
|
|
isEdit.value = false;
|
|
|
- await getMerchantList();
|
|
|
- // 初始化一个空的商家优惠券项
|
|
|
- formData.details = [
|
|
|
- {
|
|
|
- friendStoreUserId: "",
|
|
|
- couponId: "",
|
|
|
- couponList: [],
|
|
|
- remainingCount: 0
|
|
|
- }
|
|
|
- ];
|
|
|
+ currentEditId.value = "";
|
|
|
+ await loadAddActivityMerchants();
|
|
|
+ couponOptionsMap.value = {};
|
|
|
+ couponDataMap.value = {};
|
|
|
+ formData.distributeType = 1;
|
|
|
+ formData.coupons = [{ merchant: null, coupon: null, remaining: 0 }];
|
|
|
+ formData.acName = "";
|
|
|
+ formData.moneyLow = "";
|
|
|
+ formData.moneyHigh = "";
|
|
|
dialogVisible.value = true;
|
|
|
};
|
|
|
|
|
|
@@ -362,175 +436,154 @@ const closeDialog = () => {
|
|
|
formRef.value?.resetFields();
|
|
|
Object.assign(formData, {
|
|
|
acName: "",
|
|
|
+ distributeType: 1,
|
|
|
moneyLow: "",
|
|
|
moneyHigh: "",
|
|
|
- details: []
|
|
|
+ coupons: []
|
|
|
});
|
|
|
currentEditId.value = "";
|
|
|
};
|
|
|
|
|
|
// 添加商家优惠券
|
|
|
const addMerchantCoupon = () => {
|
|
|
- formData.details.push({
|
|
|
- friendStoreUserId: "",
|
|
|
- couponId: "",
|
|
|
- couponList: [],
|
|
|
- remainingCount: 0
|
|
|
+ formData.coupons.push({
|
|
|
+ merchant: null,
|
|
|
+ coupon: null,
|
|
|
+ remaining: 0
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 移除商家优惠券
|
|
|
const removeMerchantCoupon = (index: number) => {
|
|
|
- formData.details.splice(index, 1);
|
|
|
+ formData.coupons.splice(index, 1);
|
|
|
};
|
|
|
|
|
|
-// 商家选择改变时,获取该商家的优惠券列表(选择优惠券)
|
|
|
-const handleMerchantChange = async (index: number) => {
|
|
|
- const item = formData.details[index];
|
|
|
- item.couponId = ""; // 重置优惠券选择
|
|
|
- item.remainingCount = 0; // 重置剩余张数
|
|
|
-
|
|
|
- if (!item.friendStoreUserId) {
|
|
|
- item.couponList = [];
|
|
|
- return;
|
|
|
- }
|
|
|
+// 赠送类型切换:清空选项缓存并重置行内选择(与 group_merchant setDistributeType 一致)
|
|
|
+const onDistributeTypeChange = () => {
|
|
|
+ couponOptionsMap.value = {};
|
|
|
+ couponDataMap.value = {};
|
|
|
+ formData.coupons = formData.coupons.map(() => ({
|
|
|
+ merchant: null,
|
|
|
+ coupon: null,
|
|
|
+ remaining: 0
|
|
|
+ }));
|
|
|
+ if (formData.coupons.length !== 1) formData.coupons = [{ merchant: null, coupon: null, remaining: 0 }];
|
|
|
+ loadAddActivityMerchants();
|
|
|
+};
|
|
|
|
|
|
- // item.friendStoreUserId 存储的是商家的 couponId,需要找到对应商家的 friendStoreUserId
|
|
|
- const merchant = merchantList.value.find((m: any) => m.couponId === item.friendStoreUserId);
|
|
|
- if (!merchant) {
|
|
|
- item.couponList = [];
|
|
|
- return;
|
|
|
+// 加载当前类型下的优惠券/折扣券选项
|
|
|
+const loadCouponOptionsByType = async (distributeType: number) => {
|
|
|
+ const key = distributeType === 2 ? "2-couponList" : "1-couponList";
|
|
|
+ if (couponOptionsMap.value[key]?.length) return;
|
|
|
+ const storeId = localGet("createdId") || "";
|
|
|
+ if (distributeType === 1) {
|
|
|
+ try {
|
|
|
+ const res: any = await getIssueCouponList({
|
|
|
+ storeId,
|
|
|
+ tab: 1,
|
|
|
+ size: 100,
|
|
|
+ page: 1,
|
|
|
+ couponName: "",
|
|
|
+ couponsFromType: 1
|
|
|
+ });
|
|
|
+ const records = res?.data?.records ?? res?.data ?? [];
|
|
|
+ const list = Array.isArray(records) ? records : [];
|
|
|
+ couponDataMap.value[key] = list;
|
|
|
+ couponOptionsMap.value[key] = list.map((item: any) => ({
|
|
|
+ value: String(item.id ?? item.couponId ?? ""),
|
|
|
+ label: item.couponName ?? item.name ?? ""
|
|
|
+ }));
|
|
|
+ } catch (e) {
|
|
|
+ couponDataMap.value[key] = [];
|
|
|
+ couponOptionsMap.value[key] = [];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ const res: any = await getVoucherList({ storeId, status: 5, size: 100, page: 1 });
|
|
|
+ const records = res?.data?.records ?? res?.data ?? [];
|
|
|
+ const list = Array.isArray(records) ? records : [];
|
|
|
+ couponDataMap.value[key] = list;
|
|
|
+ couponOptionsMap.value[key] = list.map((item: any) => ({
|
|
|
+ value: String(item.id ?? item.voucherId ?? item.couponId ?? ""),
|
|
|
+ label: item.name ?? item.couponName ?? ""
|
|
|
+ }));
|
|
|
+ } catch (e) {
|
|
|
+ couponDataMap.value[key] = [];
|
|
|
+ couponOptionsMap.value[key] = [];
|
|
|
+ }
|
|
|
}
|
|
|
+};
|
|
|
|
|
|
- try {
|
|
|
- const res: any = await getReceivedFriendCouponList({
|
|
|
- storeId: localGet("createdId") || "",
|
|
|
- friendStoreUserId: merchant.friendStoreUserId
|
|
|
- });
|
|
|
- if (res.code == 200) {
|
|
|
- item.couponList = res.data;
|
|
|
- } else {
|
|
|
- item.couponList = [];
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error("获取优惠券列表失败", error);
|
|
|
- item.couponList = [];
|
|
|
+// 商家选择改变
|
|
|
+const handleMerchantChange = async (index: number) => {
|
|
|
+ const item = formData.coupons[index];
|
|
|
+ item.coupon = null;
|
|
|
+ item.remaining = 0;
|
|
|
+ if (item.merchant) {
|
|
|
+ const raw = merchantListRaw.value.find(
|
|
|
+ (m: any) => (m.id ?? m.friendStoreUserId) === item.merchant || (m.storeId ?? m.phoneId) === item.merchant
|
|
|
+ );
|
|
|
+ if (raw) item.remaining = raw.singleQty ?? raw.couponNum ?? 0;
|
|
|
+ await loadCouponOptionsByType(formData.distributeType);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 优惠券选择改变时,更新剩余张数
|
|
|
+// 优惠券/折扣券选择改变
|
|
|
const handleCouponChange = (index: number) => {
|
|
|
- const item = formData.details[index];
|
|
|
- const coupon = item.couponList.find((c: any) => (c.couponId || c.id) === item.couponId);
|
|
|
- if (coupon) {
|
|
|
- item.remainingCount = coupon.couponNum || 0; // 使用 getReceivedFriendCouponList 返回的 couponNum
|
|
|
+ const item = formData.coupons[index];
|
|
|
+ const key = formData.distributeType === 2 ? "2-couponList" : "1-couponList";
|
|
|
+ const list = couponDataMap.value[key] || [];
|
|
|
+ const idKey = formData.distributeType === 2 ? "voucherId" : "couponId";
|
|
|
+ if (item.coupon && list.length) {
|
|
|
+ const found = list.find((c: any) => String(c[idKey] ?? c.couponId ?? c.id ?? "") === String(item.coupon));
|
|
|
+ if (found) item.remaining = found.singleQty ?? found.couponNum ?? 0;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 编辑行数据
|
|
|
+// 编辑行数据(与 group_merchant editActivity 逻辑及 getRuleById 回显一致)
|
|
|
const editRow = async (row: any) => {
|
|
|
isEdit.value = true;
|
|
|
currentEditId.value = row.id;
|
|
|
+ const id = row.id;
|
|
|
+ if (!id) return;
|
|
|
|
|
|
- try {
|
|
|
- // 1. 获取商家列表
|
|
|
- await getMerchantList();
|
|
|
-
|
|
|
- // 2. 调用 getRuleById 获取活动详情
|
|
|
- const res: any = await getRuleById({ id: row.id });
|
|
|
-
|
|
|
- if (res.code == 200 && res.data) {
|
|
|
- const detailData = res.data;
|
|
|
- console.log("getRuleById 返回的数据:", detailData);
|
|
|
-
|
|
|
- // 3. 处理 lifeDiscountCouponFriendRuleDetailVos 数据
|
|
|
- let details: Array<{
|
|
|
- friendStoreUserId: string | number;
|
|
|
- couponId: string | number;
|
|
|
- couponList: any[];
|
|
|
- remainingCount: number;
|
|
|
- }> = [];
|
|
|
-
|
|
|
- const detailVos = detailData.lifeDiscountCouponFriendRuleDetailVos || detailData.details || [];
|
|
|
-
|
|
|
- if (detailVos && Array.isArray(detailVos) && detailVos.length > 0) {
|
|
|
- details = await Promise.all(
|
|
|
- detailVos.map(async (item: any) => {
|
|
|
- console.log("detail item:", item);
|
|
|
-
|
|
|
- // 根据 couponId 在商家列表中找到对应的商家
|
|
|
- const matchedMerchant = merchantList.value.find((m: any) => m.couponId === item.couponId);
|
|
|
- console.log("匹配到的商家:", matchedMerchant);
|
|
|
-
|
|
|
- // 如果没有匹配到商家,返回默认值
|
|
|
- if (!matchedMerchant) {
|
|
|
- return {
|
|
|
- friendStoreUserId: item.couponId, // 商家选择框绑定的是 couponId
|
|
|
- couponId: "",
|
|
|
- couponList: [],
|
|
|
- remainingCount: 0
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- // 获取该商家的优惠券列表
|
|
|
- let couponList: any[] = [];
|
|
|
- try {
|
|
|
- const couponRes: any = await getReceivedFriendCouponList({
|
|
|
- storeId: localGet("createdId") || "",
|
|
|
- friendStoreUserId: matchedMerchant.friendStoreUserId
|
|
|
- });
|
|
|
- if (couponRes.code == 200) {
|
|
|
- couponList = couponRes.data || [];
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error("获取优惠券列表失败", error);
|
|
|
- }
|
|
|
-
|
|
|
- // 在优惠券列表中找到匹配的优惠券
|
|
|
- let matchedCoupon = couponList.find((c: any) => c.couponId === item.couponId);
|
|
|
- console.log("匹配到的优惠券:", matchedCoupon);
|
|
|
-
|
|
|
- // 如果没有在列表中找到,使用 lifeDiscountCouponFriendRuleDetailVos 中的数据创建一个临时对象
|
|
|
- if (!matchedCoupon && item.couponId) {
|
|
|
- matchedCoupon = {
|
|
|
- couponId: item.couponId,
|
|
|
- couponName: item.couponName, // 使用 getRuleById 返回的 couponName
|
|
|
- couponNum: item.couponNum || 0 // 使用 getRuleById 返回的 couponNum
|
|
|
- };
|
|
|
- // 将这个临时对象添加到列表中,以便下拉框可以显示
|
|
|
- couponList = [matchedCoupon, ...couponList];
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- friendStoreUserId: item.couponId, // 商家选择框的值是商家的 couponId
|
|
|
- couponId: matchedCoupon?.couponId || item.couponId || "", // 优惠券选择框的值使用 couponId
|
|
|
- couponList: couponList,
|
|
|
- remainingCount: matchedCoupon?.couponNum || 0 // 使用 getReceivedFriendCouponList 返回的 couponNum
|
|
|
- };
|
|
|
- })
|
|
|
- );
|
|
|
- } else {
|
|
|
- details = [
|
|
|
- {
|
|
|
- friendStoreUserId: "",
|
|
|
- couponId: "",
|
|
|
- couponList: [],
|
|
|
- remainingCount: 0
|
|
|
- }
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- Object.assign(formData, {
|
|
|
- acName: detailData.acName,
|
|
|
- moneyLow: detailData.moneyLow,
|
|
|
- moneyHigh: detailData.moneyHigh,
|
|
|
- details: details
|
|
|
- });
|
|
|
+ await loadAddActivityMerchants();
|
|
|
+ const type = row.type === 2 ? 2 : 1;
|
|
|
+ formData.distributeType = type;
|
|
|
+ couponOptionsMap.value = {};
|
|
|
+ couponDataMap.value = {};
|
|
|
|
|
|
- dialogVisible.value = true;
|
|
|
- } else {
|
|
|
+ try {
|
|
|
+ const res: any = await getRuleById({ id });
|
|
|
+ if (res.code != 200 || !res.data) {
|
|
|
ElMessage.error(res.msg || "获取活动详情失败");
|
|
|
+ return;
|
|
|
}
|
|
|
+ const d = res.data;
|
|
|
+ formData.acName = d.acName;
|
|
|
+ formData.moneyLow = d.moneyLow;
|
|
|
+ formData.moneyHigh = d.moneyHigh;
|
|
|
+ formData.distributeType = d.couponType;
|
|
|
+ formData.coupons = (d.lifeDiscountCouponFriendRuleDetailVos || []).map((vo: any) => ({
|
|
|
+ merchant: vo.friendStoreUserId ?? null,
|
|
|
+ coupon: normalizeCouponValue(vo.couponId ?? vo.voucherId),
|
|
|
+ remaining: vo.singleQty ?? vo.couponNum ?? 0,
|
|
|
+ storeName: vo.storeName ?? ""
|
|
|
+ }));
|
|
|
+ if (formData.coupons.length === 0) {
|
|
|
+ formData.coupons = [{ merchant: null, coupon: null, remaining: 0 }];
|
|
|
+ }
|
|
|
+ await loadCouponOptionsByType(formData.distributeType);
|
|
|
+ // 编辑回显:从已加载的券列表中按券 id 同步剩余张数,避免详情接口未返回 singleQty/couponNum 时一直显示 0
|
|
|
+ const key = formData.distributeType === 2 ? "2-couponList" : "1-couponList";
|
|
|
+ const list = couponDataMap.value[key] || [];
|
|
|
+ const idKey = formData.distributeType === 2 ? "voucherId" : "couponId";
|
|
|
+ formData.coupons.forEach((row: any) => {
|
|
|
+ if (!row.coupon) return;
|
|
|
+ const found = list.find((c: any) => String(c[idKey] ?? c.couponId ?? c.id ?? "") === String(row.coupon));
|
|
|
+ if (found) row.remaining = found.singleQty ?? found.couponNum ?? 0;
|
|
|
+ });
|
|
|
+ dialogVisible.value = true;
|
|
|
} catch (error: any) {
|
|
|
ElMessage.error(error?.msg || "获取活动详情失败");
|
|
|
}
|
|
|
@@ -561,72 +614,53 @@ const deleteRow = (row: any) => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-// 同意好友申请(此页面可能不需要)
|
|
|
-const handleApprove = async (row: any) => {
|
|
|
- try {
|
|
|
- ElMessage.success("操作成功");
|
|
|
- proTable.value?.getTableList();
|
|
|
- } catch (error) {
|
|
|
- ElMessage.error("操作失败");
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-// 提交表单
|
|
|
+// 提交表单(与 group_merchant saveActivity 请求参数一致)
|
|
|
const handleSubmit = async () => {
|
|
|
if (!formRef.value) return;
|
|
|
|
|
|
await formRef.value.validate(async (valid: boolean) => {
|
|
|
- if (valid) {
|
|
|
- // 验证是否至少添加了一个商家优惠券
|
|
|
- if (!formData.details.length) {
|
|
|
- ElMessage.warning("请至少添加一个商家优惠券");
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!valid) return;
|
|
|
|
|
|
- // 验证所有商家优惠券项是否都已选择
|
|
|
- const hasEmpty = formData.details.some(item => !item.friendStoreUserId || !item.couponId);
|
|
|
- if (hasEmpty) {
|
|
|
- ElMessage.warning("请完善所有商家优惠券信息");
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!formData.coupons.length) {
|
|
|
+ ElMessage.warning("请至少添加一个商家优惠券");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const hasEmpty = formData.coupons.some((item: any) => !item.merchant || !item.coupon);
|
|
|
+ if (hasEmpty) {
|
|
|
+ ElMessage.warning("请完善所有商家优惠券信息");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- try {
|
|
|
- // 转换数据:item.friendStoreUserId 存储的是商家的 couponId,item.couponId 存储的是优惠券的 couponId
|
|
|
- const details = formData.details.map(item => {
|
|
|
- // 找到对应的商家
|
|
|
- const merchant = merchantList.value.find((m: any) => m.couponId === item.friendStoreUserId);
|
|
|
- // 找到对应的优惠券
|
|
|
- const coupon = item.couponList.find((c: any) => (c.couponId || c.id) === item.couponId);
|
|
|
-
|
|
|
- return {
|
|
|
- couponId: item.couponId, // 直接使用选中的 couponId
|
|
|
- friendStoreUserId: merchant?.friendStoreUserId || "" // 使用商家的真实 friendStoreUserId
|
|
|
- };
|
|
|
- });
|
|
|
-
|
|
|
- const params = {
|
|
|
- storeId: localGet("createdId") || "",
|
|
|
- acName: formData.acName,
|
|
|
- moneyHigh: Number(formData.moneyHigh),
|
|
|
- moneyLow: Number(formData.moneyLow),
|
|
|
- details: details,
|
|
|
- id: currentEditId.value
|
|
|
- };
|
|
|
-
|
|
|
- console.log("提交参数:", params);
|
|
|
-
|
|
|
- const res: any = await saveFriendCouponRule(params);
|
|
|
+ const isVoucher = formData.distributeType === 2;
|
|
|
+ const details = formData.coupons.map((item: any) =>
|
|
|
+ isVoucher
|
|
|
+ ? { voucherId: item.coupon, friendStoreUserId: item.merchant }
|
|
|
+ : { couponId: item.coupon, friendStoreUserId: item.merchant }
|
|
|
+ );
|
|
|
|
|
|
- if (res.code == 200) {
|
|
|
- ElMessage.success(isEdit.value ? "编辑成功" : "添加成功");
|
|
|
- closeDialog();
|
|
|
- proTable.value?.getTableList();
|
|
|
- } else {
|
|
|
- ElMessage.error(res.msg || "操作失败");
|
|
|
- }
|
|
|
- } catch (error: any) {
|
|
|
- ElMessage.error(error?.msg || (isEdit.value ? "编辑失败" : "添加失败"));
|
|
|
+ const requestData: any = {
|
|
|
+ storeId: localGet("createdId") || "",
|
|
|
+ acName: formData.acName.trim(),
|
|
|
+ couponType: formData.distributeType,
|
|
|
+ moneyHigh: Number(formData.moneyHigh),
|
|
|
+ moneyLow: Number(formData.moneyLow),
|
|
|
+ details
|
|
|
+ };
|
|
|
+ if (isEdit.value && currentEditId.value) {
|
|
|
+ requestData.id = currentEditId.value;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const res: any = await saveFriendCouponRule(requestData);
|
|
|
+ if (res.code == 200) {
|
|
|
+ ElMessage.success(isEdit.value ? "编辑成功" : "添加成功");
|
|
|
+ closeDialog();
|
|
|
+ proTable.value?.getTableList();
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.msg || "操作失败");
|
|
|
}
|
|
|
+ } catch (error: any) {
|
|
|
+ ElMessage.error(error?.msg || (isEdit.value ? "编辑失败" : "添加失败"));
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
@@ -649,6 +683,11 @@ onMounted(() => {
|
|
|
align-items: center;
|
|
|
margin-bottom: 10px;
|
|
|
}
|
|
|
+ .remaining-text {
|
|
|
+ margin-right: 10px;
|
|
|
+ font-size: 13px;
|
|
|
+ color: var(--el-text-color-regular);
|
|
|
+ }
|
|
|
}
|
|
|
.dialog-footer {
|
|
|
display: flex;
|