Browse Source

运营管理 推荐管理

DESKTOP-O04BTUJ\muzen 3 năm trước cách đây
mục cha
commit
ff0e5165dd
1 tập tin đã thay đổi với 46 bổ sung22 xóa
  1. 46 22
      src/views/operation/recommend/index.vue

+ 46 - 22
src/views/operation/recommend/index.vue

@@ -86,11 +86,11 @@
 
             <el-form-item label="列表:" v-if="isList()">
               <el-button type="primary" @click="getDialog(index)">添加内容</el-button>
-              <el-table :data="item.list">
+              <el-table :data="item.childList" height="332">
                 <el-table-column label="电台名称:" prop="contentName" align="center" />
                 <el-table-column label="操作" align="center">
-                  <template>
-                    <el-button type="delete">删除</el-button>
+                  <template slot-scope="scope">
+                    <el-button type="delete" @click="getDelete(scope.row, index)">删除</el-button>
                   </template>
                 </el-table-column>
               </el-table>
@@ -127,7 +127,8 @@
           <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
         </el-form-item>
       </el-form>
-      <el-table :data="tableData" height="584" @selection-change="handleSelectionChange">
+      <el-table :data="tableData" height="584" ref="tableData" :row-key="rowKey"
+        @selection-change="handleSelectionChange">
         <el-table-column type="selection" align="center" v-if="tabIndex === 2 && active === 1" />
         <el-table-column label="音频ID" prop="audioId" align="center" />
         <el-table-column label="音频名称" prop="audioName" align="center" show-overflow-tooltip />
@@ -141,7 +142,8 @@
         <el-table-column label="付费类型" align="center" :formatter="freeFormatter" width="100px" />
         <el-table-column label="操作" align="center">
           <template slot-scope="scope">
-            <el-button type="text" @click="getSelect(scope.row)" :disabled="tabIndex === 2 && active === 1">选择</el-button>
+            <el-button type="text" @click="getSelect(scope.row)" :disabled="tabIndex === 2 && active === 1">选择
+            </el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -270,9 +272,6 @@ export default {
       // 模块内容
       contentForm: {},
       list: [],
-      // 表单
-      form: {},
-
       // 弹窗
       dialogVisible: false,
       form: {
@@ -319,7 +318,8 @@ export default {
       }).then(res => {
         if (res.code === 0) {
           this.module = res.data
-          this.getDetail(res.data[0].id)
+          this.getModuleDetail(res.data[0].id)
+          this.getContentDetail(res.data[0].id)
         }
       })
     },
@@ -328,13 +328,14 @@ export default {
     getActive(index) {
       if (this.active !== index) {
         this.active = index
-        this.getDetail(this.module[index].id)
+        this.form.audioType = 2
+        this.getModuleDetail(this.module[index].id)
+        this.getContentDetail(this.module[index].id)
       }
     },
 
     // 模块详情
-    getDetail(id) {
-      // 标题模块内容
+    getModuleDetail(id) {
       moduleDetail({
         id: id
       }).then(res => {
@@ -342,8 +343,10 @@ export default {
           this.contentForm = res.data
         }
       })
+    },
 
-      // 模块内容列表
+    // 模块内容列表
+    getContentDetail(id) {
       this.list = []
       contentList({
         moduleId: id
@@ -386,7 +389,6 @@ export default {
     getDialog(index) {
       this.dialogVisible = true
       this.index = index
-      this.list[this.index].list = []
       this.getContentList()
     },
 
@@ -402,6 +404,14 @@ export default {
         if (res.code === 0) {
           this.tableData = res.data.records
           this.total = res.data.total
+          this.$nextTick(() => {
+            this.list[this.index].childList.map(i => {
+              let row = res.data.records.find(j => j.audioId === i.contentId)
+              if (row) {
+                this.$refs.tableData.toggleRowSelection(row, true)
+              }
+            })
+          })
         }
       })
     },
@@ -417,17 +427,31 @@ export default {
       this.$message.success('选择成功!')
     },
 
+    rowKey(row) {
+      return row.audioId
+    },
+
     // 批量选择
     handleSelectionChange(row) {
-      row.map(i => {
-        this.list[this.index].list.push({
-          contentId: i.audioId,
-          contentName: i.audioName,
-          platformId: i.platformId,
-          contentType: i.audioType
+      if (row.length > 0) {
+        row.map(i => {
+          if (this.list[this.index].childList.findIndex(j => j.contentId === i.audioId) === -1) {
+            this.list[this.index].childList.push({
+              contentId: i.audioId,
+              contentName: i.audioName,
+              platformId: i.platformId,
+              contentType: i.audioType
+            })
+          }
         })
-      })
-      this.$message.success('选择成功')
+      }
+    },
+
+    // 删除已添加的内容
+    getDelete(row, index) {
+      let e = this.list[index].childList.findIndex(i => i.contentId === row.contentId)
+      this.list[index].childList.splice(e, 1)
+      console.log(this.list[index].childList);
     },
 
     // 上传图片