Ver Fonte

fix: 配合后台修改活动类型字段

sgc há 2 meses atrás
pai
commit
af80319ee6

+ 24 - 9
src/views/operationManagement/activityDetail.vue

@@ -37,7 +37,7 @@
           </div>
 
           <!-- 评论有礼相关字段 -->
-          <template v-if="activityModel.activityType == 2">
+          <template v-if="activityModel.activityType == 'COMMENT'">
             <!-- 用户可参与次数 -->
             <div class="detail-item">
               <div class="detail-label">用户可参与次数</div>
@@ -72,7 +72,7 @@
           </template>
 
           <!-- 营销活动相关字段 -->
-          <template v-if="activityModel.activityType == 1">
+          <template v-if="activityModel.activityType == 'MARKETING'">
             <!-- 报名时间 -->
             <div class="detail-item">
               <div class="detail-label">报名时间</div>
@@ -210,8 +210,8 @@ const id = ref<string>("");
 
 // ==================== 活动信息数据模型 ====================
 const activityModel = ref<any>({
-  // 活动类型:1-评论有礼,2-营销活动
-  activityType: 1,
+  // 活动类型:'COMMENT'-评论有礼,'MARKETING'-营销活动
+  activityType: "MARKETING",
   // 活动名称
   activityName: "",
   // 活动开始时间
@@ -299,6 +299,13 @@ const loadDetailData = async () => {
         rewardType = data.couponType === 4 ? "VOUCHER" : "COUPON";
       }
 
+      // 兼容旧数据:如果后端返回的是数字 activityType,转换为新格式
+      if (data.activityType == 1 || data.activityType == "1") {
+        data.activityType = "MARKETING";
+      } else if (data.activityType == 2 || data.activityType == "2") {
+        data.activityType = "COMMENT";
+      }
+
       // 合并数据,并根据 rewardType 设置对应字段
       activityModel.value = { ...activityModel.value, ...data, rewardType };
     } else {
@@ -336,12 +343,20 @@ const formatDateTime = (dateTime: string) => {
 /**
  * 获取活动类型标签
  */
-const getActivityTypeLabel = (activityType: number) => {
-  const typeMap: Record<number, string> = {
-    1: "营销活动",
-    2: "评论有礼"
+const getActivityTypeLabel = (activityType: string | number) => {
+  // 兼容旧数据:如果传入的是数字,转换为字符串
+  let typeValue = activityType;
+  if (typeValue == 1 || typeValue == "1") {
+    typeValue = "MARKETING";
+  } else if (typeValue == 2 || typeValue == "2") {
+    typeValue = "COMMENT";
+  }
+
+  const typeMap: Record<string, string> = {
+    MARKETING: "营销活动",
+    COMMENT: "评论有礼"
   };
-  return typeMap[activityType] || "--";
+  return typeMap[typeValue] || "--";
 };
 
 /**

+ 12 - 5
src/views/operationManagement/activityList.vue

@@ -230,8 +230,8 @@ const statusEnum = [
 
 // 活动类型选项(用于搜索)
 const activityTypeEnum = [
-  { label: "评论有礼", value: 2 },
-  { label: "营销活动", value: 1 }
+  { label: "评论有礼", value: "COMMENT" },
+  { label: "营销活动", value: "MARKETING" }
 ];
 
 // 操作按钮权限配置(根据状态-操作映射表)
@@ -313,7 +313,14 @@ const columns = reactive<ColumnProps<any>[]>([
       order: 1
     },
     render: (scope: any) => {
-      return scope.row.activityType == 1 ? "营销活动" : "评论有礼";
+      // 兼容旧数据:如果后端返回的是数字,转换为字符串
+      const activityType = scope.row.activityType;
+      if (activityType == 1 || activityType == "1") {
+        return "营销活动";
+      } else if (activityType == 2 || activityType == "2") {
+        return "评论有礼";
+      }
+      return activityType == "MARKETING" ? "营销活动" : "评论有礼";
     }
   },
   {
@@ -391,10 +398,10 @@ const getTableList = async (params: any) => {
       pageSize: params.pageSize ? String(params.pageSize) : undefined,
       status: params.status !== undefined && params.status !== null && params.status !== "" ? Number(params.status) : undefined,
       storeId: params.storeId ? String(params.storeId) : undefined,
-      // 处理 activityType:如果存在且不为空,转换为 number 类型
+      // 处理 activityType:如果存在且不为空,保持字符串类型('MARKETING' 或 'COMMENT')
       activityType:
         params.activityType !== undefined && params.activityType !== null && params.activityType !== ""
-          ? Number(params.activityType)
+          ? String(params.activityType)
           : undefined
     };
     const result = await getActivityList(newParams);

+ 40 - 26
src/views/operationManagement/newActivity.vue

@@ -12,8 +12,8 @@
             <!-- 活动类型 -->
             <el-form-item label="活动类型" prop="activityType">
               <el-select v-model="activityModel.activityType" class="form-input" clearable placeholder="请选择">
-                <el-option label="评论有礼" :value="2" />
-                <el-option label="营销活动" :value="1" />
+                <el-option label="评论有礼" value="COMMENT" />
+                <el-option label="营销活动" value="MARKETING" />
               </el-select>
             </el-form-item>
 
@@ -38,7 +38,7 @@
             </el-form-item>
 
             <!-- 评论有礼相关字段 -->
-            <template v-if="activityModel.activityType === 2">
+            <template v-if="activityModel.activityType === 'COMMENT'">
               <!-- 用户可参与次数 -->
               <el-form-item label="用户可参与次数" prop="participationLimit">
                 <el-input v-model="activityModel.participationLimit" placeholder="请输入" maxlength="4" />
@@ -88,7 +88,7 @@
             </template>
 
             <!-- 营销活动相关字段 -->
-            <template v-if="activityModel.activityType === 1">
+            <template v-if="activityModel.activityType === 'MARKETING'">
               <!-- 报名时间 -->
               <el-form-item class="activity-time-item" label="报名时间" prop="signupTimeRange">
                 <el-date-picker
@@ -315,7 +315,7 @@ const rules = reactive({
         callback();
         // 活动时间验证通过后,重新验证报名时间(如果已设置)
         if (
-          activityModel.value.activityType === 1 &&
+          activityModel.value.activityType === "MARKETING" &&
           activityModel.value.signupTimeRange &&
           Array.isArray(activityModel.value.signupTimeRange) &&
           activityModel.value.signupTimeRange.length === 2
@@ -332,7 +332,7 @@ const rules = reactive({
     { required: true, message: "请输入用户可参与次数", trigger: "blur" },
     {
       validator: (rule: any, value: any, callback: any) => {
-        if (activityModel.value.activityType === 2) {
+        if (activityModel.value.activityType === "COMMENT") {
           if (!value) {
             callback(new Error("请输入用户可参与次数"));
             return;
@@ -356,7 +356,7 @@ const rules = reactive({
   couponId: [
     {
       validator: (rule: any, value: any, callback: any) => {
-        if (activityModel.value.activityType === 2 && activityModel.value.rewardType === "COUPON") {
+        if (activityModel.value.activityType === "COMMENT" && activityModel.value.rewardType === "COUPON") {
           if (!value) {
             callback(new Error("请选择优惠券"));
             return;
@@ -370,7 +370,7 @@ const rules = reactive({
   couponQuantity: [
     {
       validator: (rule: any, value: any, callback: any) => {
-        if (activityModel.value.activityType === 2 && activityModel.value.rewardType === "COUPON") {
+        if (activityModel.value.activityType === "COMMENT" && activityModel.value.rewardType === "COUPON") {
           if (!value) {
             callback(new Error("请输入优惠券发放数量"));
             return;
@@ -393,7 +393,7 @@ const rules = reactive({
   voucherId: [
     {
       validator: (rule: any, value: any, callback: any) => {
-        if (activityModel.value.activityType === 2 && activityModel.value.rewardType === "VOUCHER") {
+        if (activityModel.value.activityType === "COMMENT" && activityModel.value.rewardType === "VOUCHER") {
           if (!value) {
             callback(new Error("请选择代金券"));
             return;
@@ -407,7 +407,7 @@ const rules = reactive({
   voucherQuantity: [
     {
       validator: (rule: any, value: any, callback: any) => {
-        if (activityModel.value.activityType === 2 && activityModel.value.rewardType === "VOUCHER") {
+        if (activityModel.value.activityType === "COMMENT" && activityModel.value.rewardType === "VOUCHER") {
           if (!value) {
             callback(new Error("请输入代金券发放数量"));
             return;
@@ -431,7 +431,7 @@ const rules = reactive({
     { required: true, message: "请选择报名时间", trigger: "change" },
     {
       validator: (rule: any, value: any, callback: any) => {
-        if (activityModel.value.activityType === 1) {
+        if (activityModel.value.activityType === "MARKETING") {
           if (!value || !Array.isArray(value) || value.length !== 2) {
             callback(new Error("请选择报名时间"));
             return;
@@ -478,7 +478,7 @@ const rules = reactive({
     { required: true, message: "请输入活动详情", trigger: ["blur", "change"] },
     {
       validator: (rule: any, value: any, callback: any) => {
-        if (activityModel.value.activityType === 1) {
+        if (activityModel.value.activityType === "MARKETING") {
           if (!value || value.trim() === "") {
             callback(new Error("请输入活动详情"));
             return;
@@ -541,8 +541,8 @@ const rules = reactive({
 
 // ==================== 活动信息数据模型 ====================
 const activityModel = ref<any>({
-  // 活动类型:1-营销活动,2-评论有礼
-  activityType: 1,
+  // 活动类型:'MARKETING'-营销活动,'COMMENT'-评论有礼
+  activityType: "MARKETING",
   // 活动宣传图(包含标题和详情)
   promotionImages: null,
   // 活动标题图片
@@ -1007,7 +1007,7 @@ const handlePictureCardPreview = (file: any) => {
  * 根据券类型加载优惠券/代金券列表
  */
 const loadCouponList = async () => {
-  if (activityModel.value.activityType !== 2) return;
+  if (activityModel.value.activityType !== "COMMENT") return;
 
   try {
     const params = {
@@ -1049,7 +1049,15 @@ watch(
     if (newVal === oldVal) return;
 
     nextTick(() => {
-      if (newVal === 1) {
+      // 兼容旧数据:如果传入的是数字,转换为字符串
+      let typeValue = newVal;
+      if (typeValue == 1 || typeValue == "1") {
+        typeValue = "MARKETING";
+      } else if (typeValue == 2 || typeValue == "2") {
+        typeValue = "COMMENT";
+      }
+
+      if (typeValue === "MARKETING") {
         // 切换到营销活动:清除评论有礼相关字段
         activityModel.value.participationLimit = "";
         activityModel.value.rewardType = "COUPON";
@@ -1069,7 +1077,7 @@ watch(
           "voucherId",
           "voucherQuantity"
         ]);
-      } else if (newVal === 2) {
+      } else if (typeValue === "COMMENT") {
         // 切换到评论有礼:清除营销活动相关字段
         activityModel.value.signupTimeRange = [];
         activityModel.value.activityLimitPeople = "";
@@ -1092,7 +1100,7 @@ watch(
   (newVal, oldVal) => {
     if (oldVal === undefined) return; // 初始化时不处理
     if (newVal === oldVal) return;
-    if (activityModel.value.activityType !== 2) return; // 只有评论有礼才处理
+    if (activityModel.value.activityType !== "COMMENT") return; // 只有评论有礼才处理
 
     nextTick(() => {
       // 清空已选券(根据类型清空对应字段)
@@ -1159,7 +1167,7 @@ watch(
     if (oldVal === undefined || oldVal === null) return;
 
     // 只有营销活动才需要检查报名时间
-    if (activityModel.value.activityType !== 1) return;
+    if (activityModel.value.activityType !== "MARKETING") return;
 
     // 如果活动时间已选择且报名时间已选择
     if (
@@ -1202,7 +1210,7 @@ onMounted(async () => {
   type.value = (route.query.type as string) || "";
 
   // 如果是评论有礼类型,初始化时加载优惠券列表
-  if (activityModel.value.activityType === 2) {
+  if (activityModel.value.activityType === "COMMENT") {
     await loadCouponList();
   }
 
@@ -1211,9 +1219,15 @@ onMounted(async () => {
     try {
       const res: any = await getActivityDetail({ id: id.value });
       if (res && res.code == 200) {
-        // 先设置 activityType 为数字类型,确保下拉框正确显示
+        // 兼容旧数据:如果后端返回的是数字,转换为字符串
         if (res.data.activityType !== undefined) {
-          activityModel.value.activityType = Number(res.data.activityType);
+          let activityTypeValue = res.data.activityType;
+          if (activityTypeValue == 1 || activityTypeValue == "1") {
+            activityTypeValue = "MARKETING";
+          } else if (activityTypeValue == 2 || activityTypeValue == "2") {
+            activityTypeValue = "COMMENT";
+          }
+          activityModel.value.activityType = activityTypeValue;
         }
 
         // 合并其他数据
@@ -1228,7 +1242,7 @@ onMounted(async () => {
         }
 
         // 根据活动类型加载对应字段
-        if (activityModel.value.activityType === 1) {
+        if (activityModel.value.activityType === "MARKETING") {
           // 营销活动:加载报名时间、活动限制人数、活动详情
           if (res.data.signupStartTime && res.data.signupEndTime) {
             // 只取日期部分(去掉时分秒)
@@ -1246,7 +1260,7 @@ onMounted(async () => {
           }
           // 加载活动详情
           activityModel.value.activityDetails = res.data.activityDetails || "";
-        } else if (activityModel.value.activityType === 2) {
+        } else if (activityModel.value.activityType === "COMMENT") {
           // 评论有礼:加载活动规则、券类型、优惠券/代金券、发放数量、用户可参与次数
           // 加载券类型('COUPON'-优惠券,'VOUCHER'-代金券)
           // 兼容旧数据:如果后端返回的是数字,转换为新格式
@@ -1392,7 +1406,7 @@ const handleSubmit = async () => {
       };
 
       // 根据活动类型添加不同的字段,确保只提交对应类型的字段
-      if (activityModel.value.activityType === 1) {
+      if (activityModel.value.activityType === "MARKETING") {
         // 营销活动:只添加营销活动相关字段
         const [signupStartTime, signupEndTime] = activityModel.value.signupTimeRange || [];
         params.signupStartTime = signupStartTime;
@@ -1404,7 +1418,7 @@ const handleSubmit = async () => {
         delete params.rewardType;
         delete params.couponId;
         delete params.couponQuantity;
-      } else if (activityModel.value.activityType === 2) {
+      } else if (activityModel.value.activityType === "COMMENT") {
         // 评论有礼:只添加评论有礼相关字段
         params.participationLimit = activityModel.value.participationLimit;
         params.rewardType = activityModel.value.rewardType; // 'COUPON'-优惠券,'VOUCHER'-代金券