add-subject.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div>
  3. <el-form :model="forms" size="default" label-width="80px" ref="formRef">
  4. <!-- <el-form-item
  5. prop="instrumentIds"
  6. label="所属分类"
  7. :rules="[{ required: true, message: '请选择声部分类' }]"
  8. >
  9. <el-select
  10. v-model="forms.instrumentIds"
  11. placeholder="请选择所属分类"
  12. clearable
  13. filterable
  14. style="width: 50% !important"
  15. >
  16. <el-option
  17. v-for="item in fatherList"
  18. :key="item.id"
  19. :label="item.name"
  20. :value="item.id"
  21. >
  22. </el-option>
  23. </el-select>
  24. </el-form-item> -->`
  25. <div
  26. style="max-height: 400px;min-height: 300px; overflow-x: hidden; overflow-y: auto"
  27. >
  28. <el-radio-group v-model="forms.instrumentIds">
  29. <el-form-item
  30. v-for="(cbs, index) in cbsSubjectList"
  31. :key="index"
  32. :label="cbs.name"
  33. >
  34. <template v-if="cbs.instruments && cbs.instruments.length">
  35. <el-radio
  36. v-for="(item, index) in cbs.instruments"
  37. :key="index"
  38. :label="item.id"
  39. :disabled="item.added && item.id !== defaultId"
  40. >{{ item.name }}</el-radio
  41. >
  42. </template>
  43. </el-form-item>
  44. </el-radio-group>
  45. </div>
  46. </el-form>
  47. <div slot="footer" class="dialog-footer">
  48. <el-button @click="$emit('close')">取 消</el-button>
  49. <el-button type="primary" @click="onSubmit" v-preventReClick
  50. >确 认</el-button
  51. >
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { api_cbsSubjectPage } from "../api";
  57. import { subjectUpset } from "@/api/specialSetting";
  58. export default {
  59. name: "add-subject",
  60. props: ["fatherList", "subjectType", "detail"],
  61. data() {
  62. return {
  63. defaultId: null,
  64. cbsSubjectOption: [],
  65. cbsSubjectList: [],
  66. forms: {
  67. cbsSubjectId: null,
  68. instrumentIds: null // 分类名称
  69. }
  70. };
  71. },
  72. mounted() {
  73. // 修改声部
  74. if (this.detail.id) {
  75. this.forms.id = this.detail.id;
  76. this.forms.instrumentIds = this.detail.instrumentIds
  77. ? Number(this.detail.instrumentIds)
  78. : null;
  79. this.defaultId = this.detail.instrumentIds
  80. ? Number(this.detail.instrumentIds)
  81. : null;
  82. this.getCbsSubject(this.detail.id);
  83. }
  84. },
  85. methods: {
  86. formatParentId(id, list, ids = []) {
  87. for (const item of list) {
  88. if (item.instruments) {
  89. const cIds = this.formatParentId(id, item.instruments, [
  90. ...ids,
  91. item.id
  92. ]);
  93. if (cIds.includes(id)) {
  94. return cIds;
  95. }
  96. }
  97. if (item.id === id) {
  98. return [...ids, id];
  99. }
  100. }
  101. return ids;
  102. },
  103. async getCbsSubject(subjectId) {
  104. try {
  105. const { data } = await api_cbsSubjectPage({
  106. page: 1,
  107. rows: 999,
  108. subjectId
  109. });
  110. this.cbsSubjectList = data;
  111. } catch (e) {
  112. //
  113. console.log(e, "data");
  114. }
  115. },
  116. async onSubmit() {
  117. // 提交修改乐器
  118. if (!this.forms.instrumentIds) {
  119. this.$message.error("请选择乐器");
  120. return;
  121. }
  122. const ids = this.formatParentId(
  123. this.forms.instrumentIds,
  124. this.cbsSubjectList
  125. );
  126. this.forms.cbsSubjectId = ids[0];
  127. subjectUpset({
  128. tenantId: 1,
  129. ...this.forms
  130. }).then(res => {
  131. if (res.code == 200) {
  132. this.messageTips("修改", res);
  133. this.$emit("getList");
  134. this.$emit("close");
  135. }
  136. });
  137. // this.$refs.formRef.validate(valid => {
  138. // if (!valid) return;
  139. // // if (this.detail.id) {
  140. // // // 修改
  141. // // } else {
  142. // // // 添加
  143. // // }
  144. // this.$emit("close");
  145. // });
  146. },
  147. messageTips(title, res) {
  148. if (res.code == 200) {
  149. this.$message.success(title + "成功");
  150. } else {
  151. this.$message.error(res.msg);
  152. }
  153. }
  154. }
  155. };
  156. </script>
  157. <style lang="less" scoped>
  158. .dialog-footer {
  159. padding-top: 12px;
  160. text-align: right;
  161. }
  162. /deep/ .el-form-item {
  163. margin-bottom: 13px;
  164. }
  165. </style>