Browse Source

feat(group-package): 实现团购信息草稿保存功能- 修改 API 接口 saveStoreInfo 为 saveDraft
- 更新团购管理页面字段显示逻辑,价格为空时显示 "--"- 调整开始售卖时间字段名称 saleTimeStr为 startTimeValue- 移除菜品图片字段 dishImage 的使用
- 新增团购提交时的前端验证逻辑- 优化时间选择器的验证规则与监听逻辑

congxuesong 1 month ago
parent
commit
2ba0af547e

+ 2 - 2
src/api/modules/groupPackageManagement.ts

@@ -9,8 +9,8 @@ import http from "@/api";
 export const getThaliList = params => {
   return http.get<ResPage<StoreUser.ResStoreUserList>>(PORT_NONE + `/PcGroupBuy/getThaliList`, params);
 };
-export const saveStoreInfo = (params: { id: string }) => {
-  return http.post(PORT_NONE + `/store/info/saveStoreInfo`, params);
+export const saveDraft = params => {
+  return http.post(PORT_NONE + `/PcGroupBuy/saveDraft`, params);
 };
 export const getUserByPhone = params => {
   return http.get(PORT_NONE + `/store/user/getUserByPhone`, params);

+ 3 - 3
src/views/groupPackageManagement/index.vue

@@ -237,21 +237,21 @@ const columns = reactive<ColumnProps<any>[]>([
     prop: "goodsId",
     label: "优惠价",
     render: (scope: any) => {
-      return `¥${scope.row.preferentialPrice}`;
+      return scope.row.preferentialPrice ? `¥${scope.row.preferentialPrice}` : "--";
     }
   },
   {
     prop: "costPrice",
     label: "成本价",
     render: (scope: any) => {
-      return `¥${scope.row.costPrice}`;
+      return scope.row.costPrice ? `¥${scope.row.costPrice}` : "--";
     }
   },
   {
     prop: "profit",
     label: "利润",
     render: (scope: any) => {
-      return `¥${scope.row.profit}`;
+      return scope.row.profit ? `¥${scope.row.profit}` : "--";
     }
   },
   {

+ 26 - 28
src/views/groupPackageManagement/newGroup.vue

@@ -44,9 +44,9 @@
               </el-radio-group>
             </el-form-item>
             <!-- 自定义开始售卖时间(当选择"设置售卖时间"时显示) -->
-            <el-form-item label="" prop="saleTimeStr" v-if="storeInfoModel.startTimeType == 1">
+            <el-form-item label="" prop="startTimeValue" v-if="storeInfoModel.startTimeType == 1">
               <el-date-picker
-                v-model="storeInfoModel.saleTimeStr"
+                v-model="storeInfoModel.startTimeValue"
                 format="YYYY/MM/DD"
                 value-format="YYYY-MM-DD"
                 placeholder="请选择开始售卖时间"
@@ -453,7 +453,7 @@ import { ref, reactive, onMounted, watch, nextTick, computed } from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
 import { Plus, Delete, ArrowDown, ArrowUp, Picture } from "@element-plus/icons-vue";
 import {
-  saveStoreInfo,
+  saveDraft,
   editStoreInfo,
   getDetail,
   getStoreDetail,
@@ -488,7 +488,7 @@ const rules = reactive({
   imageList: [{ required: true, message: "请上传图片" }],
   groupName: [{ required: true, message: "请填写团购名称" }],
   startTimeType: [{ required: true, message: "请选择开始售卖时间" }],
-  saleTimeStr: [
+  startTimeValue: [
     { required: true, message: "请选择开始售卖时间" },
     {
       validator: (rule: any, value: any, callback: any) => {
@@ -534,8 +534,8 @@ const rules = reactive({
           return;
         }
         // 如果开始时间已设置,验证结束时间必须晚于开始时间
-        if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
-          const startDate = new Date(storeInfoModel.value.saleTimeStr);
+        if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.startTimeValue) {
+          const startDate = new Date(storeInfoModel.value.startTimeValue);
           if (selectedDate <= startDate) {
             callback(new Error("结束售卖时间必须晚于开始售卖时间"));
             return;
@@ -811,7 +811,7 @@ const storeInfoModel = ref<any>({
   // 开始售卖时间设置方式:0-审核通过后立即开始,1-设置售卖时间
   startTimeType: 0,
   // 开始售卖时间(当storeStatus为1时必填)
-  saleTimeStr: "",
+  startTimeValue: "",
   // 结束售卖时间
   endTime: "",
   // 库存数量
@@ -910,7 +910,6 @@ const lifeGroupBuyThalis = ref([
         detailId: "", // 菜品ID
         dishName: "", // 菜品名称
         dishPrice: "", // 菜品价格
-        dishImage: "", // 菜品图片
         qty: "", // 数量
         dishesUnit: ""
       }
@@ -963,7 +962,7 @@ watch(
  * 当开始时间改变时,重新验证结束时间
  */
 watch(
-  () => storeInfoModel.value.saleTimeStr,
+  () => storeInfoModel.value.startTimeValue,
   () => {
     if (storeInfoModel.value.endTime) {
       nextTick(() => {
@@ -980,9 +979,9 @@ watch(
 watch(
   () => storeInfoModel.value.endTime,
   () => {
-    if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
+    if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.startTimeValue) {
       nextTick(() => {
-        ruleFormRef.value?.validateField("saleTimeStr");
+        ruleFormRef.value?.validateField("startTimeValue");
       });
     }
   }
@@ -1090,7 +1089,6 @@ onMounted(async () => {
               detailId: "",
               dishName: "",
               dishPrice: "",
-              dishImage: "",
               qty: "",
               dishesUnit: ""
             }
@@ -1266,7 +1264,6 @@ const addGroup = () => {
             detailId: "",
             dishName: "",
             dishPrice: "",
-            dishImage: "",
             qty: "",
             dishesUnit: ""
           }
@@ -1307,7 +1304,6 @@ const addGroup = () => {
           detailId: "",
           dishName: "",
           dishPrice: "",
-          dishImage: "",
           qty: "",
           dishesUnit: ""
         }
@@ -1437,7 +1433,6 @@ const addDish = (groupIndex: number) => {
         detailId: "",
         dishName: "",
         dishPrice: "",
-        dishImage: "",
         qty: "",
         dishesUnit: ""
       });
@@ -1469,7 +1464,6 @@ const addDish = (groupIndex: number) => {
         detailId: "",
         dishName: "",
         dishPrice: "",
-        dishImage: "",
         qty: "",
         dishesUnit: ""
       });
@@ -1504,7 +1498,6 @@ const addDish = (groupIndex: number) => {
       detailId: "",
       dishName: "",
       dishPrice: "",
-      dishImage: "",
       qty: "",
       dishesUnit: ""
     });
@@ -1572,7 +1565,6 @@ const confirmDishSelection = () => {
     dish.detailId = selectedDish.id;
     dish.dishName = selectedDish.dishName;
     dish.dishPrice = selectedDish.dishPrice;
-    dish.dishImage = selectedDish.imgUrl;
     dish.dishesUnit = selectedDish.dishesUnit;
     dishDialogVisible.value = false;
     // 重新验证对应的字段,如果验证通过,错误提示会消失
@@ -1722,13 +1714,8 @@ const packageFormRules = computed(() => {
  * 提交数据(新增/编辑)
  * 验证表单,通过后调用相应的API接口
  */
-const handleSubmit = (type?) => {
+const handleSubmit = async (type?) => {
   let params: any = { ...storeInfoModel.value };
-  if (params.effectiveDateType == 0) {
-    // params.couponCompDate = `用户购买${params.expirationDate}天内有效`;
-  } else {
-    params.expirationDateList = params.expirationDateList.join(",");
-  }
   if (params.disableDateType == 1) {
     params.disableDateValue = params.unavailableWeekdays.join(",") + ";" + params.unavailableHolidays.join(",");
     // params.disableDateValue = [params.unavailableWeekdays, params.unavailableHolidays];
@@ -1746,12 +1733,23 @@ const handleSubmit = (type?) => {
   //     dishPrice: dish.dishPrice
   //   }))
   // );
-  const paramsObj = {
+  const paramsObj: any = {
     lifeGroupBuyMain: params,
     lifeGroupBuyThalis: lifeGroupBuyThalis.value
   };
-  console.log(paramsObj);
   if (type) {
+    if (!storeInfoModel.value.groupName) {
+      ElMessage.error("请填写团购名称");
+      return;
+    }
+    paramsObj.lifeGroupBuyMain.status = "0";
+    paramsObj.lifeGroupBuyMain.groupType = 1;
+    paramsObj.lifeGroupBuyMain.storeId = id.value;
+    console.log(paramsObj);
+    let res: any = await saveDraft(paramsObj);
+    if (res && res.code == 200) {
+    }
+    // goBack();
     return;
   }
   // 验证表单
@@ -1807,8 +1805,8 @@ const disabledEndDate = (time: Date) => {
     return true;
   }
   // 如果开始售卖时间已设置,不能早于或等于开始时间
-  if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
-    const startDate = new Date(storeInfoModel.value.saleTimeStr);
+  if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.startTimeValue) {
+    const startDate = new Date(storeInfoModel.value.startTimeValue);
     startDate.setHours(0, 0, 0, 0);
     return time.getTime() <= startDate.getTime();
   }

+ 2 - 2
src/views/orderManagement/index.vue

@@ -114,14 +114,14 @@ const columns = reactive<ColumnProps<any>[]>([
     prop: "paidAmount",
     label: "实付款",
     render: (scope: any) => {
-      return `¥${scope.row.paidAmount || 0}`;
+      return scope.row.paidAmount ? `¥${scope.row.paidAmount}` : "--";
     }
   },
   {
     prop: "estimatedIncome",
     label: "本单预计收入",
     render: (scope: any) => {
-      return `¥${scope.row.estimatedIncome || 0}`;
+      return scope.row.estimatedIncome ? `¥${scope.row.estimatedIncome}` : "--";
     }
   },
   {

+ 2 - 2
src/views/voucherManagement/index.vue

@@ -148,10 +148,10 @@ const columns = reactive<ColumnProps<any>[]>([
     }
   },
   {
-    prop: "groupName",
+    prop: "preferentialPrice",
     label: "价格",
     render: (scope: any) => {
-      return `¥${scope.row.preferentialPrice}`;
+      return scope.row.preferentialPrice ? `¥${scope.row.preferentialPrice}` : "--";
     }
   },
   {