Ver Fonte

红德堂-打卡活动自定义打卡天数

Long há 5 horas atrás
pai
commit
b90147cc3e
1 ficheiros alterados com 31 adições e 3 exclusões
  1. 31 3
      src/views/his/courseCheckIn/index.vue

+ 31 - 3
src/views/his/courseCheckIn/index.vue

@@ -110,6 +110,11 @@
           </el-date-picker>
         </el-form-item>
 
+        <el-form-item label="打卡天数" prop="checkinDays">
+          <el-input-number v-model="form.checkinDays" :min="1" :max="365" :precision="0" size="small" style="width: 200px" placeholder="请输入打卡天数" />
+          <span style="margin-left: 10px; color: #999;">天</span>
+        </el-form-item>
+
         <el-form-item label="参与公司" prop="companyIds">
           <el-select filterable multiple v-model="form.companyIds" placeholder="请选择参与公司" size="small" style="width: 100%">
             <el-option
@@ -301,7 +306,8 @@ export default {
         prizeGoodsId: null,
         prizeGoodsName: null,
         prizeList: [],
-        remark: null
+        remark: null,
+        checkinDays: null
       },
       rules: {
         activityName: [
@@ -310,13 +316,17 @@ export default {
         timeRange: [
           { required: true, message: "活动时间不能为空", trigger: "change" }
         ],
+        checkinDays: [
+          { required: true, message: "打卡天数不能为空", trigger: "blur" },
+          { type: "number", min: 1, message: "打卡天数必须大于0", trigger: "blur" },
+          { validator: this.validateCheckinDays, trigger: "blur" }
+        ],
         companyIds: [
           { required: true, message: "参与公司不能为空", trigger: "change" }
         ],
         projectIds: [
           { required: true, message: "参与项目不能为空", trigger: "change" }
         ],
-
       },
       copyOpen: false,
       copyForm: {
@@ -413,9 +423,26 @@ export default {
         prizeGoodsId: null,
         prizeGoodsName: null,
         prizeList: [],
-        remark: null
+        remark: null,
+        checkinDays: null
       };
     },
+    // 校验打卡天数不能超过活动时长
+    validateCheckinDays(rule, value, callback) {
+      if (!this.form.timeRange || this.form.timeRange.length < 2) {
+        callback(new Error('请先选择活动时间'));
+        return;
+      }
+      const startDate = new Date(this.form.timeRange[0]);
+      const endDate = new Date(this.form.timeRange[1]);
+      const diffTime = Math.abs(endDate - startDate);
+      const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1; // 包含首尾天数
+      if (value > diffDays) {
+        callback(new Error('打卡天数不能超过活动时长(' + diffDays + '天)'));
+      } else {
+        callback();
+      }
+    },
     handlePrizeGoodsChange(goodsId) {
       if (goodsId) {
         const goods = this.integralGoodsList.find(item => item.goodsId === goodsId);
@@ -581,6 +608,7 @@ export default {
             activityName: this.form.activityName,
             startTime: this.form.timeRange[0],
             endTime: this.form.timeRange[1],
+            checkinDays: this.form.checkinDays,
             companyIds: this.form.companyIds.join(','),
             projectIds: this.form.projectIds.join(','),
             notifyTemplate: this.form.notifyTemplate,