Bläddra i källkod

更新智能陪练

lex-xin 3 år sedan
förälder
incheckning
2a55078af8

+ 22 - 2
src/views/accompaniment/index.vue

@@ -399,17 +399,37 @@ export default {
   },
   async mounted() {
     const { query, params } = this.$route;
+      await this.FetchTree();
     if (params.categoriesId) {
-      this.searchForm.categoriesId = [params.categoriesId];
+      // console.log(this.tree)
+      // console.log(this.formatParentId(params.categoriesId, this.tree))
+      this.searchForm.categoriesId = this.formatParentId(params.categoriesId, this.tree);
     }
     this.$store.dispatch("setSubjects");
     this.$store.dispatch("setBranchs");
-    await this.FetchTree();
     await this.FetchList();
 
     // 点击Cascader  label选中
   },
   methods: {
+    formatParentId(id, list, ids = []) {
+      for (const item of list) {
+        if (item.sysMusicScoreCategoriesList) {
+          const cIds = this.formatParentId(
+            id,
+            item.sysMusicScoreCategoriesList,
+            [...ids, item.id]
+          );
+          if (cIds.includes(id)) {
+            return cIds;
+          }
+        }
+        if (item.id === id) {
+          return [...ids, id];
+        }
+      }
+      return ids;
+    },
     async FetchTree() {
       try {
         const res = await queryTree();

+ 73 - 17
src/views/organManager/components/memberSetting.vue

@@ -75,7 +75,7 @@
         </el-form-item>
         <el-form-item label="可用教材" prop="teachingMaterialId"
           :rules="[{ required: true, message: '请选择可用教材', trigger: 'change' }]">
-          <el-select
+          <!-- <el-select
             v-model.trim="form.teachingMaterialId"
             :disabled="isDisabled"
             v-show="!isDisabled"
@@ -89,7 +89,19 @@
           >
             <el-option v-for="(item, index) in teachList" :key="index"
               :label="item.name" :value="item.id"></el-option>
-          </el-select>
+          </el-select> -->
+          <el-cascader
+            v-model.trim="form.teachingMaterialId"
+            :disabled="isDisabled"
+            v-show="!isDisabled"
+            style="width: 300px !important"
+            :options="teachList"
+            :props="{ multiple: true }"
+            :show-all-levels="false"
+            collapse-tags
+            ref="cascader"
+            @change="onChange"
+            clearable></el-cascader>
 
           <el-tag
             :key="tag.id"
@@ -121,7 +133,9 @@
 //         }
 //     }
 // }
-import { getSysMusicScoreList } from '@/views/teachManager/api'
+// import { getSysMusicScoreList } from '@/views/teachManager/api'
+import { queryTree } from '../../accompaniment/api'
+import _ from 'lodash'
 export default {
   props: ['type', 'data'],
   data () {
@@ -143,9 +157,17 @@ export default {
     if(this.data) {
       const { config, teachingMaterialId } = this.data
       const tmpConfig = config ? JSON.parse(config) : {}
+      console.log(teachingMaterialId)
+      let tempIdArr = []
+      if(teachingMaterialId) {
+        const tempIds = teachingMaterialId.split(',').map(i => Number(i))
+        tempIds.forEach(id => {
+          tempIdArr.push(this.formatParentId(id, this.teachList))
+        })
+      }
       this.form = {
         ...tmpConfig.member_config,
-        teachingMaterialId: teachingMaterialId.split(',').map(i => Number(i))
+        teachingMaterialId: tempIdArr
       }
       this.onChange()
     }
@@ -158,23 +180,53 @@ export default {
   methods: {
     async __init() {
       try {
-        const res = await getSysMusicScoreList({ page: 1, rows: 999, enable: 1 })
-        this.teachList = res.data?.rows || []
-      } catch(e) {}
+        const res = await queryTree({ enable: 1 })
+        const rows = res.data || []
+        rows.forEach(item => {
+          let children = []
+          item.label = item.name
+          item.value = item.id
+          let childList = item.sysMusicScoreCategoriesList ? item.sysMusicScoreCategoriesList : []
+          if(childList.length > 0) {
+            childList.forEach(child => {
+              child.label = child.name
+              child.value = child.id
+              children.push(child)
+            })
+          }
+          item.children = children.length > 0 ? children : null
+          this.teachList.push(item)
+        })
+      } catch(e) { console.log(e) }
     },
     onChange() {
-      const val = this.form.teachingMaterialId
+      let childNodes = this.$refs.cascader.getCheckedNodes(true)
       this.dynamicTags = []
-      if(val && val.length > 0) {
-        this.teachList.forEach(item => {
-          if(val.includes(item.id)) {
-            this.dynamicTags.push({
-              name: item.name,
-              id: item.id
-            })
+      childNodes.forEach(node => {
+        this.dynamicTags.push({
+          name: node.label,
+          id: node.value
+        })
+      })
+      console.log(this.getValues())
+    },
+    formatParentId(id, list, ids = []) {
+      for (const item of list) {
+        if (item.sysMusicScoreCategoriesList) {
+          const cIds = this.formatParentId(
+            id,
+            item.sysMusicScoreCategoriesList,
+            [...ids, item.id]
+          );
+          if (cIds.includes(id)) {
+            return cIds;
           }
-        });
+        }
+        if (item.id === id) {
+          return [...ids, id];
+        }
       }
+      return ids;
     },
     handleClose(tag) {
 
@@ -188,9 +240,13 @@ export default {
     },
     getValues() {
       const { teachingMaterialId, ...res } = this.form
+      let tempArr = []
+      teachingMaterialId.forEach(ids => {
+        tempArr.push(_.last(ids))
+      })
       return {
         member_config: { ...res },
-        teachingMaterialId
+        teachingMaterialId: tempArr
       }
     },
   },

+ 1 - 2
src/views/organManager/components/openService.vue

@@ -133,7 +133,6 @@ export default {
   },
   computed: {
     isDisabled() {
-      console.log(this.payState)
       return this.type == 'setting' || this.payState == 1  ? true : false
     },
     unitSuffix() {
@@ -153,7 +152,7 @@ export default {
       try {
         const res = await platformServeQueryModeDetail({ id: val })
         this.modeList = res.data || []
-      } catch(e) { console.log(e) }
+      } catch(e) {  }
     },
     onSubmit() {
       let status = false

+ 5 - 2
src/views/teachManager/index.vue

@@ -255,9 +255,12 @@ export default {
       this.search();
     },
     operationTeachClass(type, row) {
-      console.log(row, this.expands)
-      console.log(this.formatParentId(row.id, this.tableList))
       this.type = type
+      let level = 0
+      if(row) {
+        level = this.formatParentId(row.id, this.tableList).length
+        row.level = level
+      }
       this.activeRow = row || null;
       this.teachClassVisible = true;
     },

+ 24 - 4
src/views/teachManager/modals/addRoot.vue

@@ -23,7 +23,7 @@
       <el-form-item
         label="适用分部"
         prop="organId"
-        v-if="!activeRow.id"
+        v-if="!(activeRow && activeRow.id)"
         :rules="[
           {
             required: true,
@@ -52,6 +52,7 @@
       <el-form-item
         label="音源设置"
         prop="soundResource"
+        v-if="level <= 2"
         :rules="[
           {
             required: true,
@@ -71,7 +72,7 @@
         prop="coverImg"
         :rules="[
           {
-            required: true,
+            required: level > 2 ? false : true,
             message: '请上传教材封面图',
             trigger: 'blur',
           },
@@ -125,17 +126,18 @@ export default {
         children: "sysMusicScoreCategoriesList",
         label: "name",
       },
+      level: 0, // 当前添加或修改第几层
     };
   },
   async mounted() {
     await this.$store.dispatch("setBranchs");
-    console.log(this.activeRow)
     if (this.activeRow?.id) {
       // 判断是否是根元素处理
       // if(this.activeRow?.parentId != 0) {
         this.imageWidthM = 210
         this.imageHeightM = 268
       // }
+      this.level = this.activeRow?.level || 0
       try {
         const res = await getSysMusicScoreDetail({ id: this.activeRow.id });
         if(this.type == 'create') { // 添加一级分类或子级
@@ -154,6 +156,24 @@ export default {
     }
   },
   methods: {
+    formatParentId(id, list, ids = []) {
+      for (const item of list) {
+        if (item.sysMusicScoreCategoriesList) {
+          const cIds = this.formatParentId(
+            id,
+            item.sysMusicScoreCategoriesList,
+            [...ids, item.id]
+          );
+          if (cIds.includes(id)) {
+            return cIds;
+          }
+        }
+        if (item.id === id) {
+          return [...ids, id];
+        }
+      }
+      return ids;
+    },
     addSubmit() {
       this.$refs.form.validate(async (flag) => {
         if (flag) {
@@ -171,7 +191,7 @@ export default {
           };
           try {
             if (this.type == 'update') {
-              obj.id = this.activeRow.id;
+              obj.id = this.activeRow?.id;
               await resetsysMusicScore(obj);
               this.$message.success("修改成功");
               this.$emit("getList");