Просмотр исходного кода

fix:修复控制台报错问题、添加红包金额限制、修复批量设置红包勾选弹窗异常问题

caoliqin 3 дней назад
Родитель
Сommit
fe5dfb33e5

+ 23 - 6
src/views/course/userCoursePeriod/batchRedPacket.vue

@@ -1,9 +1,10 @@
 <template>
   <el-dialog
     title="批量设置红包"
-    :visible.sync="visible"
+    :visible.sync="dialogVisible"
     width="800px"
     append-to-body
+    @close="handleClose"
   >
     <el-table
       v-loading="loading"
@@ -23,14 +24,15 @@
         align="center"
       />
       <el-table-column
-        label="金额"
+        label="金额(0.1-0.3元)"
         align="center"
         width="200"
       >
         <template slot-scope="scope">
           <el-input-number
             v-model="scope.row.amount"
-            :min="0.01"
+            :min="0.1"
+            :max="0.3"
             :precision="2"
             :step="0.01"
             size="small"
@@ -65,14 +67,22 @@ export default {
   data() {
     return {
       loading: false,
-      tableData: []
+      tableData: [],
+      dialogVisible: false
     }
   },
   watch: {
     visible(val) {
+      this.dialogVisible = val;
       if (val) {
         this.initTableData()
       }
+    },
+    dialogVisible(val) {
+      if (!val) {
+        // 当弹窗关闭时,通知父组件
+        this.$emit('update:visible', false);
+      }
     }
   },
   methods: {
@@ -80,11 +90,18 @@ export default {
     initTableData() {
       this.tableData = this.selectedData.map(item => ({
         ...item,
-        amount: 0.01
+        amount: 0.1
       }))
     },
     // 保存
     handleSave() {
+      // 验证金额范围
+      const invalidItems = this.tableData.filter(item => item.amount < 0.1 || item.amount > 0.3);
+      if (invalidItems.length > 0) {
+        this.$message.error('红包金额需要在0.1元至0.3元之间');
+        return;
+      }
+
       this.$confirm(`是否确定?确定后营期下的所有公司红包金额都将设置成对应值`, '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
@@ -113,7 +130,7 @@ export default {
     },
     // 关闭
     handleClose() {
-      this.$emit('update:visible', false)
+      this.dialogVisible = false;
     }
   }
 }

+ 22 - 14
src/views/course/userCoursePeriod/redPacket.vue

@@ -27,11 +27,12 @@
         <el-table-column label="课程" prop="courseName" align="center" />
         <el-table-column label="小节" prop="videoName" align="center" />
         <el-table-column label="营期日期" prop="dayDate" align="center"/>
-        <el-table-column label="红包金额" width="200px" align="center">
+        <el-table-column label="红包金额(0.1-0.3元)" width="200px" align="center">
           <template slot-scope="scope">
             <el-input-number
               v-model="scope.row.amount"
-              :min="0"
+              :min="0.1"
+              :max="0.3"
               :precision="2"
               :step="0.01"
               size="small"
@@ -130,27 +131,34 @@ export default {
       }).then(response => {
         this.redPacketList = (response.data || []).map(item => ({
           ...item,
-          amount: item.amount || 0
+          amount: item.amount || 0.1
         }));
       });
     },
     // 保存红包金额
     handleSave() {
-      const saveData = this.redPacketList
-        .filter(item => item.amount > 0)
-        .map(item => ({
-          companyId: this.currentCompany.companyId,
-          redPacketMoney: item.amount,
-          videoId: item.videoId,
-          periodId: this.periodId,
-          dataType: 2
-        }));
-
-      if (saveData.length === 0) {
+      // 筛选出有金额的项目
+      const validAmountItems = this.redPacketList.filter(item => item.amount > 0);
+      if (validAmountItems.length === 0) {
         this.$message.warning('请至少设置一个红包金额');
         return;
       }
 
+      // 验证金额范围
+      const invalidItems = validAmountItems.filter(item => item.amount < 0.1 || item.amount > 0.3);
+      if (invalidItems.length > 0) {
+        this.$message.error('红包金额需要在0.1元至0.3元之间');
+        return;
+      }
+
+      const saveData = validAmountItems.map(item => ({
+        companyId: this.currentCompany.companyId,
+        redPacketMoney: item.amount,
+        videoId: item.videoId,
+        periodId: this.periodId,
+        dataType: 2
+      }));
+
       batchSaveRedPacket(saveData).then(response => {
         if (response.code === 200) {
           this.$message.success('保存成功');