瀏覽代碼

修改显示

lex 9 月之前
父節點
當前提交
1e1fc280e4

+ 96 - 23
src/views/categroyManager/components/add-subject.vue

@@ -1,13 +1,13 @@
 <template>
   <div>
     <el-form :model="forms" size="default" label-width="80px" ref="formRef">
-      <el-form-item
-        prop="parentSubjectId"
+      <!-- <el-form-item
+        prop="instrumentIds"
         label="所属分类"
         :rules="[{ required: true, message: '请选择声部分类' }]"
       >
         <el-select
-          v-model="forms.parentSubjectId"
+          v-model="forms.instrumentIds"
           placeholder="请选择所属分类"
           clearable
           filterable
@@ -21,26 +21,28 @@
           >
           </el-option>
         </el-select>
-      </el-form-item>
-      <el-scrollbar height="400px" v-if="subjectType === 'add'">
-        <el-checkbox-group v-model="forms.cbsSubjectOption">
+      </el-form-item> -->`
+      <div
+        style="max-height: 400px;min-height: 300px; overflow-x: hidden; overflow-y: auto"
+      >
+        <el-radio-group v-model="forms.instrumentIds">
           <el-form-item
             v-for="(cbs, index) in cbsSubjectList"
             :key="index"
             :label="cbs.name"
           >
             <template v-if="cbs.instruments && cbs.instruments.length">
-              <el-checkbox
+              <el-radio
                 v-for="(item, index) in cbs.instruments"
                 :key="index"
                 :label="item.id"
-                :disabled="item.added"
-                >{{ item.name }}</el-checkbox
+                :disabled="item.added && item.id !== defaultId"
+                >{{ item.name }}</el-radio
               >
             </template>
           </el-form-item>
-        </el-checkbox-group>
-      </el-scrollbar>
+        </el-radio-group>
+      </div>
     </el-form>
 
     <div slot="footer" class="dialog-footer">
@@ -53,38 +55,105 @@
 </template>
 
 <script>
+import { api_cbsSubjectPage } from "../api";
+import { subjectUpset } from "@/api/specialSetting";
 export default {
   name: "add-subject",
   props: ["fatherList", "subjectType", "detail"],
   data() {
     return {
+      defaultId: null,
       cbsSubjectOption: [],
       cbsSubjectList: [],
       forms: {
-        cbsSubjectOption: [],
-        parentSubjectId: "" // 分类名称
+        cbsSubjectId: null,
+        instrumentIds: null // 分类名称
       }
     };
   },
   mounted() {
     // 修改声部
     if (this.detail.id) {
-      this.forms.parentSubjectId = this.detail.parentSubjectId;
+      this.forms.id = this.detail.id;
+      this.forms.instrumentIds = this.detail.instrumentIds
+        ? Number(this.detail.instrumentIds)
+        : null;
+      this.defaultId = this.detail.instrumentIds
+        ? Number(this.detail.instrumentIds)
+        : null;
+      this.getCbsSubject(this.detail.id);
     }
   },
   methods: {
-    onSubmit() {
-      // 提交修改乐器
-      this.$refs.formRef.validate(valid => {
-        if (!valid) return;
-        if (this.detail.id) {
-          // 修改
-        } else {
-          // 添加
+    formatParentId(id, list, ids = []) {
+      for (const item of list) {
+        if (item.instruments) {
+          const cIds = this.formatParentId(id, item.instruments, [
+            ...ids,
+            item.id
+          ]);
+          if (cIds.includes(id)) {
+            return cIds;
+          }
+        }
+        if (item.id === id) {
+          return [...ids, id];
         }
+      }
+      return ids;
+    },
+    async getCbsSubject(subjectId) {
+      try {
+        const { data } = await api_cbsSubjectPage({
+          page: 1,
+          rows: 999,
+          subjectId
+        });
+        this.cbsSubjectList = data;
+      } catch (e) {
+        //
+        console.log(e, "data");
+      }
+    },
+    async onSubmit() {
+      // 提交修改乐器
+      if (!this.forms.instrumentIds) {
+        this.$message.error("请选择乐器");
+        return;
+      }
+      const ids = this.formatParentId(
+        this.forms.instrumentIds,
+        this.cbsSubjectList
+      );
+      this.forms.cbsSubjectId = ids[0];
 
-        this.$emit("close");
+      subjectUpset({
+        tenantId: 1,
+        ...this.forms
+      }).then(res => {
+        if (res.code == 200) {
+          this.messageTips("修改", res);
+          this.$emit("getList");
+          this.$emit("close");
+        }
       });
+      // this.$refs.formRef.validate(valid => {
+      //   if (!valid) return;
+      //   // if (this.detail.id) {
+      //   //   // 修改
+      //   // } else {
+      //   //   // 添加
+      //   // }
+
+      //   this.$emit("close");
+      // });
+    },
+    messageTips(title, res) {
+      if (res.code == 200) {
+        this.$message.success(title + "成功");
+      } else {
+        this.$message.error(res.msg);
+      }
     }
   }
 };
@@ -92,6 +161,10 @@ export default {
 
 <style lang="less" scoped>
 .dialog-footer {
+  padding-top: 12px;
   text-align: right;
 }
+/deep/ .el-form-item {
+  margin-bottom: 13px;
+}
 </style>

+ 21 - 21
src/views/categroyManager/components/create-subject.vue

@@ -54,7 +54,7 @@
           仅支持图片格式:JPG、PNG、GIF, 大小2M以内;
         </p>
       </el-form-item>
-      <el-form-item
+      <!-- <el-form-item
         v-if="subjectType === 'update'"
         label="乐器"
         prop="instrumentIds"
@@ -77,7 +77,7 @@
             </template>
           </el-radio-group>
         </div>
-      </el-form-item>
+      </el-form-item> -->
     </el-form>
     <div slot="footer" class="dialog-footer">
       <el-button @click="$emit('close')">取 消</el-button>
@@ -103,8 +103,8 @@ export default {
         name: null,
         id: null,
         img: null,
-        parentSubjectId: null,
-        instrumentIds: null
+        parentSubjectId: null
+        // instrumentIds: null
       },
       cropperOptions: {
         autoCrop: true, //是否默认生成截图框
@@ -123,26 +123,26 @@ export default {
       this.form.id = this.detail.id;
       this.form.parentSubjectId = this.detail.parentSubjectId;
       this.form.img = this.detail.img;
-      this.form.instrumentIds = this.detail.instrumentIds
-        ? Number(this.detail.instrumentIds)
-        : null;
-      this.getCbsSubject(this.detail.id);
+      // this.form.instrumentIds = this.detail.instrumentIds
+      //   ? Number(this.detail.instrumentIds)
+      //   : null;
+      // this.getCbsSubject(this.detail.id);
     }
   },
   methods: {
-    async getCbsSubject(subjectId) {
-      try {
-        const { data } = await api_cbsSubjectPage({
-          page: 1,
-          rows: 999,
-          subjectId
-        });
-        console.log(data, "cbsSubjectList");
-        this.cbsSubjectList = data;
-      } catch {
-        //
-      }
-    },
+    // async getCbsSubject(subjectId) {
+    //   try {
+    //     const { data } = await api_cbsSubjectPage({
+    //       page: 1,
+    //       rows: 999,
+    //       subjectId
+    //     });
+    //     console.log(data, "cbsSubjectList");
+    //     this.cbsSubjectList = data;
+    //   } catch {
+    //     //
+    //   }
+    // },
     //上传图片成功
     cropSuccess(data) {
       this.form.img = data.data.url;

+ 15 - 13
src/views/categroyManager/globalSubjects.vue

@@ -104,12 +104,14 @@
                 type="text"
                 >{{ !scope.row.enableFlag ? "启用" : "停用" }}</el-button
               > -->
-              <!-- <el-button
-                @click="updateInstrument(scope.row)"
-                size="small"
-                type="text"
-                >修改乐器</el-button
-              > -->
+              <auth auths="subject/upset/reset">
+                <el-button
+                  @click="updateInstrument(scope.row)"
+                  size="small"
+                  type="text"
+                  >修改乐器</el-button
+                >
+              </auth>
             </template>
           </el-table-column>
         </el-table>
@@ -122,7 +124,7 @@
         />
       </div>
     </div>
-    <!-- <el-dialog
+    <el-dialog
       :title="'修改乐器'"
       :visible.sync="instrumentVisible"
       width="770px"
@@ -135,7 +137,7 @@
         @close="instrumentVisible = false"
         @getList="getList"
       />
-    </el-dialog> -->
+    </el-dialog>
 
     <el-dialog
       :title="subjectTitle === 'add' ? '添加声部' : '修改声部'"
@@ -275,11 +277,11 @@ export default {
       this.subjectVisible = true;
     },
     /** 修改乐器 */
-    // updateInstrument() {
-    //   this.instrumentTitle = "update";
-    //   this.activeRow = row;
-    //   this.instrumentVisible = true;
-    // },
+    updateInstrument(row) {
+      this.instrumentTitle = "update";
+      this.activeRow = row;
+      this.instrumentVisible = true;
+    },
     removeSubjectCategory(row) {
       this.$confirm("是否确认删除声部", "提示", {
         confirmButtonText: "确定",