|
|
@@ -4,7 +4,7 @@
|
|
|
<!-- 表格 header 按钮 -->
|
|
|
<template #tableHeader="scope">
|
|
|
<div class="header-button">
|
|
|
- <el-button type="primary" @click="openAddDialog"> 添加好友 </el-button>
|
|
|
+ <el-button type="primary" @click="openAddDialog"> 添加活动 </el-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -23,52 +23,66 @@
|
|
|
</template>
|
|
|
</ProTable>
|
|
|
|
|
|
- <!-- 添加/编辑好友对话框 -->
|
|
|
+ <!-- 添加/编辑活动对话框 -->
|
|
|
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="700px" @close="closeDialog">
|
|
|
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="140px">
|
|
|
- <el-form-item label="好友名称" prop="friendName">
|
|
|
- <el-input v-model="formData.friendName" placeholder="请输入好友名称" clearable />
|
|
|
+ <el-form-item label="活动名称" prop="acName">
|
|
|
+ <el-input v-model="formData.acName" placeholder="请输入" clearable />
|
|
|
</el-form-item>
|
|
|
|
|
|
- <el-form-item label="好友手机号" prop="friendPhone">
|
|
|
- <el-input v-model="formData.friendPhone" placeholder="请输入手机号" maxlength="11" clearable />
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="好友备注" prop="remark">
|
|
|
- <el-input
|
|
|
- v-model="formData.remark"
|
|
|
- type="textarea"
|
|
|
- :rows="3"
|
|
|
- placeholder="请输入备注信息"
|
|
|
- maxlength="200"
|
|
|
- show-word-limit
|
|
|
- />
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="关系类型" prop="relationType">
|
|
|
- <el-select v-model="formData.relationType" placeholder="请选择关系类型" style="width: 100%">
|
|
|
- <el-option v-for="item in relationTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
|
|
|
- </el-select>
|
|
|
+ <el-form-item label="消费门槛金额(¥)" required>
|
|
|
+ <div style="display: flex; gap: 10px; align-items: center; width: 100%">
|
|
|
+ <el-form-item prop="moneyLow" style=" flex: 1;margin-bottom: 0">
|
|
|
+ <el-input v-model.number="formData.moneyLow" placeholder="0.00" clearable>
|
|
|
+ <template #prefix> ¥ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <span>~</span>
|
|
|
+ <el-form-item prop="moneyHigh" style=" flex: 1;margin-bottom: 0">
|
|
|
+ <el-input v-model.number="formData.moneyHigh" placeholder="0.00" clearable>
|
|
|
+ <template #prefix> ¥ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
</el-form-item>
|
|
|
|
|
|
- <el-form-item label="赠送优惠券" prop="couponList">
|
|
|
- <div class="coupon-list">
|
|
|
- <div v-for="(item, index) in formData.couponList" :key="index" class="coupon-item">
|
|
|
- <el-select v-model="item.couponId" placeholder="请选择优惠券" style="width: 300px; margin-right: 10px">
|
|
|
- <el-option v-for="coupon in availableCoupons" :key="coupon.id" :label="coupon.name" :value="coupon.id" />
|
|
|
+ <el-form-item label="来源商家及优惠券">
|
|
|
+ <div class="merchant-coupon-list">
|
|
|
+ <div v-for="(item, index) in formData.details" :key="index" class="merchant-coupon-item">
|
|
|
+ <el-select
|
|
|
+ v-model="item.friendStoreUserId"
|
|
|
+ placeholder="选择商家"
|
|
|
+ style="width: 200px; margin-right: 10px"
|
|
|
+ @change="handleMerchantChange(index)"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="merchant in merchantList"
|
|
|
+ :key="merchant.couponId"
|
|
|
+ :label="merchant.storeName"
|
|
|
+ :value="merchant.couponId"
|
|
|
+ />
|
|
|
</el-select>
|
|
|
- <el-input-number
|
|
|
- v-model="item.quantity"
|
|
|
- :min="1"
|
|
|
- :max="100"
|
|
|
- placeholder="数量"
|
|
|
- style="width: 120px; margin-right: 10px"
|
|
|
- />
|
|
|
- <el-button type="danger" link @click="removeCoupon(index)"> 删除 </el-button>
|
|
|
+ <el-select
|
|
|
+ v-model="item.couponId"
|
|
|
+ placeholder="选择优惠券"
|
|
|
+ style="width: 200px; margin-right: 10px"
|
|
|
+ @change="handleCouponChange(index)"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="coupon in item.couponList"
|
|
|
+ :key="coupon.couponId || coupon.id"
|
|
|
+ :label="coupon.couponName"
|
|
|
+ :value="coupon.couponId || coupon.id"
|
|
|
+ />
|
|
|
+ </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">
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
</div>
|
|
|
- <el-button type="primary" link @click="addCoupon" style="margin-top: 10px">
|
|
|
+ <el-button type="primary" link @click="addMerchantCoupon" style="margin-top: 10px">
|
|
|
<el-icon><Plus /></el-icon>
|
|
|
- 添加优惠券
|
|
|
+ 添加商家优惠券
|
|
|
</el-button>
|
|
|
</div>
|
|
|
</el-form-item>
|
|
|
@@ -92,100 +106,77 @@ import { Plus } from "@element-plus/icons-vue";
|
|
|
import ProTable from "@/components/ProTable/index.vue";
|
|
|
import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
|
|
|
import { localGet } from "@/utils";
|
|
|
-// import { getFriendRelationList, addFriendRelation, updateFriendRelation, deleteFriendRelation, approveFriend } from "@/api/modules/friendRelation";
|
|
|
+
|
|
|
+import {
|
|
|
+ getRuleList,
|
|
|
+ saveFriendCouponRule,
|
|
|
+ getReceivedFriendCouponList,
|
|
|
+ delFriendCouponRule,
|
|
|
+ getRuleById
|
|
|
+} from "@/api/modules/newLoginApi";
|
|
|
|
|
|
// ProTable 实例
|
|
|
const proTable = ref<ProTableInstance>();
|
|
|
|
|
|
// 对话框相关
|
|
|
const dialogVisible = ref(false);
|
|
|
-const dialogTitle = computed(() => (isEdit.value ? "编辑好友" : "添加好友"));
|
|
|
+const dialogTitle = computed(() => (isEdit.value ? "编辑活动" : "添加活动"));
|
|
|
const isEdit = ref(false);
|
|
|
const currentEditId = ref("");
|
|
|
|
|
|
// 表单引用
|
|
|
const formRef = ref<FormInstance>();
|
|
|
|
|
|
-// 关系类型选项
|
|
|
-const relationTypeOptions = [
|
|
|
- { label: "普通好友", value: 1 },
|
|
|
- { label: "亲密好友", value: 2 },
|
|
|
- { label: "商业伙伴", value: 3 }
|
|
|
-];
|
|
|
-
|
|
|
-// 可用优惠券列表(模拟数据)
|
|
|
-const availableCoupons = ref([
|
|
|
- { id: 1, name: "满100减20代金券" },
|
|
|
- { id: 2, name: "8折优惠券" },
|
|
|
- { id: 3, name: "满200减50代金券" }
|
|
|
-]);
|
|
|
+// 商家列表
|
|
|
+const merchantList = ref<any[]>([]);
|
|
|
|
|
|
// 表单数据
|
|
|
const formData = reactive({
|
|
|
- friendName: "",
|
|
|
- friendPhone: "",
|
|
|
- remark: "",
|
|
|
- relationType: "",
|
|
|
- couponList: [] as Array<{ couponId: string | number; quantity: number }>
|
|
|
+ acName: "",
|
|
|
+ moneyLow: undefined as number | undefined,
|
|
|
+ moneyHigh: undefined as number | undefined,
|
|
|
+ details: [] as Array<{
|
|
|
+ friendStoreUserId: string | number;
|
|
|
+ couponId: string | number;
|
|
|
+ couponList: any[]; // 当前商家的优惠券列表
|
|
|
+ remainingCount: number; // 剩余张数
|
|
|
+ }>
|
|
|
});
|
|
|
|
|
|
// 表单验证规则
|
|
|
const formRules = reactive<FormRules>({
|
|
|
- friendName: [{ required: true, message: "请输入好友名称", trigger: "blur" }],
|
|
|
- friendPhone: [
|
|
|
- { required: true, message: "请输入手机号", trigger: "blur" },
|
|
|
- {
|
|
|
- pattern: /^1[3-9]\d{9}$/,
|
|
|
- message: "请输入正确的手机号",
|
|
|
- trigger: "blur"
|
|
|
- }
|
|
|
- ],
|
|
|
- relationType: [{ required: true, message: "请选择关系类型", trigger: "change" }]
|
|
|
+ acName: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
|
|
|
+ moneyLow: [{ required: true, message: "请输入最低消费金额", trigger: "blur" }],
|
|
|
+ moneyHigh: [{ required: true, message: "请输入最高消费金额", trigger: "blur" }]
|
|
|
});
|
|
|
|
|
|
// 表格列配置
|
|
|
const columns = reactive<ColumnProps<any>[]>([
|
|
|
{
|
|
|
- prop: "friendName",
|
|
|
- label: "好友名称",
|
|
|
- search: {
|
|
|
- el: "input"
|
|
|
- }
|
|
|
+ prop: "acName",
|
|
|
+ label: "活动名称"
|
|
|
},
|
|
|
{
|
|
|
- prop: "friendPhone",
|
|
|
- label: "手机号"
|
|
|
+ prop: "endDate",
|
|
|
+ label: "有效期至"
|
|
|
},
|
|
|
{
|
|
|
prop: "relationType",
|
|
|
- label: "关系类型",
|
|
|
- search: {
|
|
|
- el: "select",
|
|
|
- props: { placeholder: "请选择" }
|
|
|
- },
|
|
|
- enum: relationTypeOptions,
|
|
|
- fieldNames: { label: "label", value: "value" },
|
|
|
+ label: "消费门槛",
|
|
|
render: (scope: any) => {
|
|
|
- const type = relationTypeOptions.find(item => item.value === scope.row.relationType);
|
|
|
- return type?.label || "--";
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- prop: "createTime",
|
|
|
- label: "添加时间",
|
|
|
- render: (scope: any) => {
|
|
|
- return scope.row.createTime?.replace(/-/g, "/") || "--";
|
|
|
+ return scope.row.moneyLow + "元" + "~" + scope.row.moneyHigh + "元";
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
prop: "status",
|
|
|
- label: "状态"
|
|
|
- },
|
|
|
- {
|
|
|
- prop: "remark",
|
|
|
- label: "备注",
|
|
|
+ label: "状态",
|
|
|
+ enum: [
|
|
|
+ { label: "启用中", value: "0" },
|
|
|
+ { label: "已停用", value: "1" }
|
|
|
+ ],
|
|
|
+ fieldNames: { label: "label", value: "value" },
|
|
|
render: (scope: any) => {
|
|
|
- return scope.row.remark || "--";
|
|
|
+ return scope.row.status == "0" ? "启用中" : "已停用";
|
|
|
}
|
|
|
},
|
|
|
{ prop: "operation", label: "操作", fixed: "right", width: 250 }
|
|
|
@@ -199,42 +190,14 @@ const initParam = reactive({
|
|
|
// 数据回调处理
|
|
|
const dataCallback = (data: any) => {
|
|
|
return {
|
|
|
- list: data?.records || [],
|
|
|
+ list: data || [],
|
|
|
total: data?.total || 0
|
|
|
};
|
|
|
};
|
|
|
|
|
|
// 获取表格列表
|
|
|
const getTableList = (params: any) => {
|
|
|
- // TODO: 集成真实接口时,取消下面的注释
|
|
|
- // return getFriendRelationList(params);
|
|
|
-
|
|
|
- // 临时方案:返回模拟数据
|
|
|
- return new Promise(resolve => {
|
|
|
- setTimeout(() => {
|
|
|
- const mockData = generateMockData();
|
|
|
- resolve({
|
|
|
- code: 200,
|
|
|
- data: {
|
|
|
- records: mockData,
|
|
|
- total: mockData.length
|
|
|
- }
|
|
|
- });
|
|
|
- }, 500);
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-// 生成模拟数据
|
|
|
-const generateMockData = () => {
|
|
|
- return Array.from({ length: 5 }, (_, i) => ({
|
|
|
- id: i + 1,
|
|
|
- friendName: `好友${i + 1}`,
|
|
|
- friendPhone: `138${String(i).padStart(8, "0")}`,
|
|
|
- relationType: (i % 3) + 1,
|
|
|
- createTime: "2025-03-01",
|
|
|
- status: i % 3, // 0-待同意, 1-已同意, 2-已拒绝
|
|
|
- remark: i % 2 === 0 ? `备注信息${i + 1}` : ""
|
|
|
- }));
|
|
|
+ return getRuleList(params);
|
|
|
};
|
|
|
|
|
|
// 获取状态文本
|
|
|
@@ -248,18 +211,43 @@ const getStatusText = (status: number) => {
|
|
|
};
|
|
|
|
|
|
// 获取状态类型
|
|
|
-const getStatusType = (status: number) => {
|
|
|
- const typeMap: Record<number, string> = {
|
|
|
+const getStatusType = (status: number): "success" | "warning" | "info" | "danger" => {
|
|
|
+ const typeMap: Record<number, "success" | "warning" | "info" | "danger"> = {
|
|
|
0: "warning",
|
|
|
1: "success",
|
|
|
2: "info"
|
|
|
};
|
|
|
- return typeMap[status] || "";
|
|
|
+ return typeMap[status] || "info";
|
|
|
+};
|
|
|
+
|
|
|
+// 获取商家列表(选择商家)
|
|
|
+const getMerchantList = async () => {
|
|
|
+ try {
|
|
|
+ const res: any = await getReceivedFriendCouponList({
|
|
|
+ storeId: localGet("createdId") || ""
|
|
|
+ });
|
|
|
+ if (res.code == 200) {
|
|
|
+ merchantList.value = res.data;
|
|
|
+ console.log(merchantList.value);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("获取商家列表失败", error);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
// 打开添加对话框
|
|
|
-const openAddDialog = () => {
|
|
|
+const openAddDialog = async () => {
|
|
|
isEdit.value = false;
|
|
|
+ await getMerchantList();
|
|
|
+ // 初始化一个空的商家优惠券项
|
|
|
+ formData.details = [
|
|
|
+ {
|
|
|
+ friendStoreUserId: "",
|
|
|
+ couponId: "",
|
|
|
+ couponList: [],
|
|
|
+ remainingCount: 0
|
|
|
+ }
|
|
|
+ ];
|
|
|
dialogVisible.value = true;
|
|
|
};
|
|
|
|
|
|
@@ -268,58 +256,199 @@ const closeDialog = () => {
|
|
|
dialogVisible.value = false;
|
|
|
formRef.value?.resetFields();
|
|
|
Object.assign(formData, {
|
|
|
- friendName: "",
|
|
|
- friendPhone: "",
|
|
|
- remark: "",
|
|
|
- relationType: "",
|
|
|
- couponList: []
|
|
|
+ acName: "",
|
|
|
+ moneyLow: undefined,
|
|
|
+ moneyHigh: undefined,
|
|
|
+ details: []
|
|
|
});
|
|
|
currentEditId.value = "";
|
|
|
};
|
|
|
|
|
|
-// 添加优惠券
|
|
|
-const addCoupon = () => {
|
|
|
- formData.couponList.push({
|
|
|
+// 添加商家优惠券
|
|
|
+const addMerchantCoupon = () => {
|
|
|
+ formData.details.push({
|
|
|
+ friendStoreUserId: "",
|
|
|
couponId: "",
|
|
|
- quantity: 1
|
|
|
+ couponList: [],
|
|
|
+ remainingCount: 0
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-// 移除优惠券
|
|
|
-const removeCoupon = (index: number) => {
|
|
|
- formData.couponList.splice(index, 1);
|
|
|
+// 移除商家优惠券
|
|
|
+const removeMerchantCoupon = (index: number) => {
|
|
|
+ formData.details.splice(index, 1);
|
|
|
+};
|
|
|
+
|
|
|
+// 商家选择改变时,获取该商家的优惠券列表(选择优惠券)
|
|
|
+const handleMerchantChange = async (index: number) => {
|
|
|
+ const item = formData.details[index];
|
|
|
+ item.couponId = ""; // 重置优惠券选择
|
|
|
+ item.remainingCount = 0; // 重置剩余张数
|
|
|
+
|
|
|
+ if (!item.friendStoreUserId) {
|
|
|
+ item.couponList = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // item.friendStoreUserId 存储的是商家的 couponId,需要找到对应商家的 friendStoreUserId
|
|
|
+ const merchant = merchantList.value.find((m: any) => m.couponId === item.friendStoreUserId);
|
|
|
+ if (!merchant) {
|
|
|
+ item.couponList = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 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 editRow = (row: any) => {
|
|
|
+const editRow = async (row: any) => {
|
|
|
isEdit.value = true;
|
|
|
currentEditId.value = row.id;
|
|
|
- Object.assign(formData, {
|
|
|
- friendName: row.friendName,
|
|
|
- friendPhone: row.friendPhone,
|
|
|
- remark: row.remark,
|
|
|
- relationType: row.relationType,
|
|
|
- couponList: []
|
|
|
- });
|
|
|
- dialogVisible.value = true;
|
|
|
+
|
|
|
+ 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
|
|
|
+ });
|
|
|
+
|
|
|
+ dialogVisible.value = true;
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.msg || "获取活动详情失败");
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ ElMessage.error(error?.msg || "获取活动详情失败");
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
// 删除行数据
|
|
|
const deleteRow = (row: any) => {
|
|
|
- ElMessageBox.confirm("确定要删除这个好友吗?", "提示", {
|
|
|
+ ElMessageBox.confirm("确定要删除这个活动吗?", "提示", {
|
|
|
confirmButtonText: "确定",
|
|
|
cancelButtonText: "取消",
|
|
|
type: "warning"
|
|
|
})
|
|
|
.then(async () => {
|
|
|
try {
|
|
|
- // TODO: 集成真实接口时,取消下面的注释
|
|
|
- // await deleteFriendRelation({ id: row.id });
|
|
|
-
|
|
|
- ElMessage.success("删除成功");
|
|
|
- proTable.value?.getTableList();
|
|
|
- } catch (error) {
|
|
|
- ElMessage.error("删除失败");
|
|
|
+ const res: any = await delFriendCouponRule({ id: row.id });
|
|
|
+ if (res.code == 200) {
|
|
|
+ ElMessage.success("删除成功");
|
|
|
+ proTable.value?.getTableList();
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.msg || "删除失败");
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ ElMessage.error(error?.msg || "删除失败");
|
|
|
}
|
|
|
})
|
|
|
.catch(() => {
|
|
|
@@ -327,13 +456,10 @@ const deleteRow = (row: any) => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-// 同意好友申请
|
|
|
+// 同意好友申请(此页面可能不需要)
|
|
|
const handleApprove = async (row: any) => {
|
|
|
try {
|
|
|
- // TODO: 集成真实接口时,取消下面的注释
|
|
|
- // await approveFriend({ id: row.id });
|
|
|
-
|
|
|
- ElMessage.success("已同意好友申请");
|
|
|
+ ElMessage.success("操作成功");
|
|
|
proTable.value?.getTableList();
|
|
|
} catch (error) {
|
|
|
ElMessage.error("操作失败");
|
|
|
@@ -346,24 +472,54 @@ const handleSubmit = async () => {
|
|
|
|
|
|
await formRef.value.validate(async (valid: boolean) => {
|
|
|
if (valid) {
|
|
|
+ // 验证是否至少添加了一个商家优惠券
|
|
|
+ if (!formData.details.length) {
|
|
|
+ ElMessage.warning("请至少添加一个商家优惠券");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证所有商家优惠券项是否都已选择
|
|
|
+ const hasEmpty = formData.details.some(item => !item.friendStoreUserId || !item.couponId);
|
|
|
+ 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 = {
|
|
|
- ...formData,
|
|
|
- id: isEdit.value ? currentEditId.value : undefined
|
|
|
+ storeId: localGet("createdId") || "",
|
|
|
+ acName: formData.acName,
|
|
|
+ moneyHigh: formData.moneyHigh,
|
|
|
+ moneyLow: formData.moneyLow,
|
|
|
+ details: details
|
|
|
};
|
|
|
|
|
|
- // TODO: 集成真实接口时,取消下面的注释
|
|
|
- // if (isEdit.value) {
|
|
|
- // await updateFriendRelation(params);
|
|
|
- // } else {
|
|
|
- // await addFriendRelation(params);
|
|
|
- // }
|
|
|
-
|
|
|
- ElMessage.success(isEdit.value ? "编辑成功" : "添加成功");
|
|
|
- closeDialog();
|
|
|
- proTable.value?.getTableList();
|
|
|
- } catch (error) {
|
|
|
- ElMessage.error(isEdit.value ? "编辑失败" : "添加失败");
|
|
|
+ console.log("提交参数:", params);
|
|
|
+
|
|
|
+ const res: any = await saveFriendCouponRule(params);
|
|
|
+
|
|
|
+ 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 ? "编辑失败" : "添加失败"));
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -380,8 +536,9 @@ onMounted(() => {
|
|
|
.header-button {
|
|
|
margin-bottom: 16px;
|
|
|
}
|
|
|
- .coupon-list {
|
|
|
- .coupon-item {
|
|
|
+ .merchant-coupon-list {
|
|
|
+ width: 100%;
|
|
|
+ .merchant-coupon-item {
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
margin-bottom: 10px;
|