Parcourir la source

feature:修改流量套餐的新增赠送会员接口功能

zeng.chen il y a 3 mois
Parent
commit
86706687eb
2 fichiers modifiés avec 61 ajouts et 21 suppressions
  1. 57 17
      src/views/service/package/detail.vue
  2. 4 4
      src/views/service/package/index.vue

+ 57 - 17
src/views/service/package/detail.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="app-container">
-    <el-form :model="form" :rules="rules" ref="form" label-width="100px">
+    <el-form :model="form" :rules="rules" ref="form" label-width="110px">
       <el-form-item label="流量平台:">
         <el-select v-model="form.platform" placeholder="请选择流量平台" :disabled="disabled()">
           <el-option v-for="item in typeOptions" :key="item.value" :value="item.value" :label="item.label" />
@@ -56,11 +56,11 @@
         <el-input-number v-model="form.sort" :min="1" />
       </el-form-item>
       <el-form-item label='赠送会员:'>
-        <el-switch v-model="form.isFreeFlow" />
+        <el-switch v-model="isFreeContentVip" />
       </el-form-item>
-      <el-form-item v-if="form.isFreeFlow" label="关联会员套餐:">
-        <el-select v-model="form.freeOptions" placeholder="请选择会员套餐:">
-          <el-option v-for="item in form.freeOptions" :key="item.id" :label="item.name" :value="item.id" />
+      <el-form-item v-if="isFreeContentVip" label="关联会员套餐:" prop="freeActivityId">
+        <el-select v-model="form.freeActivityId" placeholder="请选择会员套餐:">
+          <el-option v-for="item in freeOptions" :key="item.id" :label="item.name" :value="item.id" />
         </el-select>
       </el-form-item>
       <el-form-item>
@@ -74,7 +74,7 @@
 <script>
 import { devMixin, serviceTimeMixin, serviceTypeMixin } from '@/mixin/index'
 import { list } from '@/api/operation/scene'
-import { detail, edit, create, goodsList } from '@/api/service/package'
+import { detail, edit, create, goodsList, deviceGoodsList } from '@/api/service/package'
 export default {
   mixins: [devMixin, serviceTimeMixin, serviceTypeMixin],
   data() {
@@ -95,6 +95,13 @@ export default {
         callback()
       }
     }
+    let checkFreeFlow = (rule, value, callback) => {
+      if (this.isFreeContentVip && !value) {
+        callback(new Error('请选择赠送会员套餐!'))
+      } else {
+        callback()
+      }
+    }
     return {
       // 表单
       form: {},
@@ -106,6 +113,9 @@ export default {
       goodsOptions: [],
       // 爱听专区
       sceneOptions: [],
+      // 赠送会员套餐
+      freeOptions: [],
+      isFreeContentVip: false,
       // 资源平台
       platformOptions: [{
         value: 6,
@@ -142,7 +152,11 @@ export default {
         discount: [{
           validator: checkedDiscount,
           trigger: 'blur'
-        }]
+        }],
+        freeActivityId: [{
+          validator: checkFreeFlow,
+          trigger: 'blur'
+        }],
       }
     }
   },
@@ -156,14 +170,14 @@ export default {
       if (val !== 5) {
         delete this.form.sort
       }
-      this.getDeviceGoodsList(this.deviceIds ?? [], val, this.form.isFreeFlow ?? false)
+      this.getDeviceGoodsList(this.deviceIds ?? [], val, this.isFreeContentVip ?? false)
 
     },
     'form.platform'(val) {
       this.getDevList({ type: val })
       this.getGoodSList(val)
     },
-    'form.isFreeFlow'(val) {
+    'isFreeContentVip'(val) {
       this.getDeviceGoodsList(this.deviceIds ?? [], this.form.businessType ?? -1, val)
     }
   },
@@ -182,6 +196,7 @@ export default {
       detail(this.form.id).then(res => {
         if (res.code === 0) {
           this.form = res.data
+          this.isFreeContentVip = res.data.isFreeContentVip === 1 ? true : false
           this.deviceIds = res.data.deviceIds.split(',')
         }
       })
@@ -209,18 +224,39 @@ export default {
         }
       })
     },
-    // 流量套餐
-    getDeviceGoodsList(deviceIds, businessType, isFreeFlow) {
-      if (this.typeList[0] != "18" || (deviceIds ?? []).length === 0 || (businessType ?? -1) < 0 || (isFreeFlow ?? false) != true) {
-        console.log('设备id或业务类型为空', this.typeList[0], deviceIds, businessType, isFreeFlow)
+    // 会员套餐
+    getDeviceGoodsList(deviceIds, businessType, isFreeContentVip) {
+      if ((deviceIds ?? []).length === 0 || (businessType ?? -1) < 0 || (isFreeContentVip ?? false) != true) {
+        console.log('设备id或业务类型为空', deviceIds, businessType, isFreeContentVip)
         return
       }
-      console.log('开始请求', this.typeList[0], deviceIds.join(","), businessType, isFreeFlow)
+      console.log('开始请求', this.typeList[0], deviceIds.join(","), businessType, isFreeContentVip)
 
-      deviceGoodsList(this.typeList[0], businessType, deviceIds.join(",")).then((res) => {
-        console.log("流量套餐", JSON.stringify(res.data));
+      deviceGoodsList(1, businessType, deviceIds.join(",")).then((res) => {
         if (res.code === 0) {
-          this.form.freeOptions = res.data;
+
+          // 如果返回的数据为空数组,确保freeOptions也为空数组而不是null或undefined
+          this.freeOptions = res.data || [];
+          // console.log("获取到流量套餐:", this.freeOptions.length, this.form.freeActivityId);
+
+          // 如果freeOptions为空,清空freeActivityId
+          if (this.freeOptions.length === 0) {
+            this.$message.warning('没有可用的会员套餐!');
+            this.form.freeActivityId = undefined;
+          }
+          // 如果freeOptions有值且freeActivityId有值,检查是否存在对应的选项
+          else if (this.form.freeActivityId !== undefined) {
+            const exists = this.freeOptions.some(item => {
+              // console.log("item.id:", item.id, "freeActivityId:", this.form.freeActivityId);
+              return String(item.id) === String(this.form.freeActivityId);
+            });
+            console.log("找匹配的会员套餐:", this.form.freeActivityId, exists);
+            if (!exists) {
+              this.$message.warning('原关联的会员套餐已不可用,请重新选择!');
+              this.form.freeActivityId = undefined;
+            } else {
+            }
+          }
         }
       });
     },
@@ -230,11 +266,14 @@ export default {
       this.$refs.form.validate((valid) => {
         if (valid) {
           this.form.deviceIds = this.deviceIds.join(',')
+          this.form.platformIds = JSON.stringify(this.platformIds)
+          this.form.isFreeContentVip = this.isFreeContentVip ? 1 : 0
           if (this.form.id) {
             edit(this.form).then(res => {
               if (res.code === 0) {
                 this.$message.success('修改成功!')
                 this.cancel()
+              } else {
               }
             })
           } else {
@@ -242,6 +281,7 @@ export default {
               if (res.code === 0) {
                 this.$message.success('新增成功!')
                 this.cancel()
+              } else {
               }
             })
           }

+ 4 - 4
src/views/service/package/index.vue

@@ -53,8 +53,8 @@
       <el-table-column label="当前状态" align="center" prop="status" key="status" :formatter="statusFormatter" />
       <el-table-column label="是否推荐" align="center" prop="isRecommend" key="isRecommend"
         :formatter="recommendFormatter" />
-      <el-table-column v-if="form.typeList[0] === '18'" label="是否赠送流量" align="center" prop="isFreeFlow" key="isFreeFlow"
-        :formatter="freeFlowFormatter" />
+      <el-table-column v-if="form.typeList[0] === '12'" label="是否赠送会员" align="center" prop="isFreeContentVip"
+        key="isFreeContentVip" :formatter="freeVipFormatter" />
       <el-table-column label="创建时间" align="center" prop="createTime" key="createTime" />
       <el-table-column label="操作" align="center">
         <template slot-scope="scope">
@@ -270,8 +270,8 @@ export default {
       return this.selectDictLabel(this.recommendOptions, row.isRecommend);
     },
     // 是否推荐
-    freeFlowFormatter(row) {
-      return this.selectDictLabel(this.recommendOptions, row.isFreeFlow == 1 ? 0 : 1);
+    freeVipFormatter(row) {
+      return this.selectDictLabel(this.recommendOptions, row.isFreeContentVip == 1 ? 0 : 1);
     },
     // 关联设备
     devFormatter(row) {