소스 검색

feature:增加设备的资源平台的唯一性校验

zeng.chen 1 개월 전
부모
커밋
4f9fe740fa
1개의 변경된 파일29개의 추가작업 그리고 5개의 파일을 삭제
  1. 29 5
      src/views/device/list/detail.vue

+ 29 - 5
src/views/device/list/detail.vue

@@ -77,14 +77,15 @@
         <el-table :data="contentVipPlatformList" border style="width: min-content">
           <el-table-column prop="platformId" label="资源平台" width="180">
             <template slot-scope="scope">
-              <el-select v-model="scope.row.platformId" placeholder="请选择流量平台" clearable>
+              <el-select v-model="scope.row.platformId" placeholder="请选择流量平台" clearable
+                @change="handlePlatformChange(scope.row, scope.$index)">
                 <el-option v-for="item in platformOptions" :key="item.value" :label="item.label" :value="item.value" />
               </el-select>
             </template>
           </el-table-column>
           <el-table-column prop="contentVip" label="设备会员收费时间" width="180">
             <template slot-scope="scope">
-              <el-select v-model="scope.row.contentVip" placeholder="请设备会员收费时间" clearable>
+              <el-select v-model="scope.row.contentVip" placeholder="默认关闭" clearable>
                 <el-option v-for="item in contentVipOptions" :key="item.value" :label="item.label"
                   :value="item.value" />
               </el-select>
@@ -362,6 +363,21 @@ export default {
     this.getList();
   },
   methods: {
+    handlePlatformChange(row, index) {
+      // 检查是否有重复的platformId
+      const value = row.platformId;
+      if (!value) return;
+
+      const exists = this.contentVipPlatformList.some(
+        (item, idx) => item.platformId === value && idx !== index
+      );
+
+      if (exists) {
+        // 如果存在重复,清空当前选择并提示
+        this.$set(row, 'platformId', null);
+        this.$message.warning('该资源平台已存在,请选择其他平台');
+      }
+    },
     // 详情
     getList() {
       if (this.$route.query.id) {
@@ -370,8 +386,15 @@ export default {
         }).then((res) => {
           if (res.code === 0) {
             this.form = res.data;
-            this.contentVipPlatformList = this.form.contentVipPlatformList;
-            this.isShowPlatform = this.form.contentVipPlatformList.length > 0;
+            this.form.contentVipPlatformList.forEach((item) => {
+              if (item.platformId > 0) {
+                this.contentVipPlatformList.push({
+                  platformId: item.platformId,
+                  contentVip: item.contentVip,
+                });
+              }
+            });
+            this.isShowPlatform = this.contentVipPlatformList.length > 0;
             this.form.typeList.map((i) => {
               this.devModeOptions[i.type - 1].disabled = true;
             });
@@ -547,7 +570,8 @@ export default {
     },
     clickAddPlatform() {
       this.isShowPlatform = true;
-      if (this.platformOptions.length != 0 && this.contentVipPlatformList.length <= this.platformOptions.length) {
+      if (this.platformOptions.length != 0 && this.contentVipPlatformList.length < this.platformOptions.length) {
+
         this.contentVipPlatformList.push({ "contentVip": null, "platformId": null, });
       } else {
         let tips = `最多只能添加${this.platformOptions.length}个平台`;