addRoot.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div>
  3. <el-alert title="教材信息" :closable="false" class="alert" type="info" />
  4. <el-form
  5. :model="form"
  6. label-width="120px"
  7. class="form"
  8. ref="form"
  9. >
  10. <el-form-item
  11. label="教材名称"
  12. prop="name"
  13. :rules="[
  14. {
  15. required: true,
  16. message: '请输入教材名称',
  17. trigger: 'blur',
  18. },
  19. ]"
  20. >
  21. <el-input v-model="form.name" placeholder="请输入教材名称" style="width: 100%"></el-input>
  22. </el-form-item>
  23. <el-form-item
  24. label="适用分部"
  25. prop="organId"
  26. v-if="!(activeRow && activeRow.id)"
  27. :rules="[
  28. {
  29. required: true,
  30. message: '请选择适用分部',
  31. trigger: 'change',
  32. },
  33. ]"
  34. >
  35. <select-all
  36. v-model.trim="form.organId"
  37. style="width: 100%"
  38. class="organSelect"
  39. filterable
  40. placeholder="请选择分部"
  41. multiple
  42. clearable
  43. >
  44. <el-option
  45. v-for="(item, index) in selects.branchs"
  46. :key="index"
  47. :label="item.name"
  48. :value="item.id"
  49. ></el-option>
  50. </select-all>
  51. </el-form-item>
  52. <el-form-item
  53. label="音源设置"
  54. prop="soundResource"
  55. v-if="level <= 2"
  56. :rules="[
  57. {
  58. required: true,
  59. message: '请选择音源设置',
  60. trigger: 'change',
  61. },
  62. ]"
  63. >
  64. <el-select filterable placeholder="请选择音源设置" clearable v-model="form.soundResource" style="width: 100% !important">
  65. <el-option label="NotePerformer音源" value="NOTEPERFORMER"></el-option>
  66. <el-option label="标准音源" value="TANG"></el-option>
  67. <el-option label="官方音源" value="OFFICIAL"></el-option>
  68. </el-select>
  69. </el-form-item>
  70. <el-form-item
  71. label="教材封面图"
  72. prop="coverImg"
  73. :rules="[
  74. {
  75. required: level > 2 ? false : true,
  76. message: '请上传教材封面图',
  77. trigger: 'blur',
  78. },
  79. ]"
  80. label-width="120px"
  81. >
  82. <upload
  83. :class="[imageWidthM == 350 ? 'uploadImg' : 'uploadSmallImg']"
  84. v-model="form.coverImg"
  85. :imageWidthM="imageWidthM"
  86. :imageHeightM="imageHeightM"
  87. ref="uploadImg"
  88. ></upload>
  89. <p style="color: red">
  90. 请上传{{ imageWidthM }}*{{ imageHeightM }}像素,大小2M以内,格式为jpg、png、gif图片
  91. </p>
  92. </el-form-item>
  93. </el-form>
  94. <span slot="footer" class="dialog-footer">
  95. <el-button @click="$listeners.close()">取 消</el-button>
  96. <el-button type="primary" @click="addSubmit">确 定</el-button>
  97. </span>
  98. </div>
  99. </template>
  100. <script>
  101. import Upload from "@/components/Upload/index";
  102. import {
  103. addsysMusicScore,
  104. getSysMusicScoreDetail,
  105. resetsysMusicScore,
  106. } from "../api";
  107. export default {
  108. props: ["type", "activeRow"],
  109. components: {
  110. Upload,
  111. },
  112. data() {
  113. return {
  114. imageWidthM: 350,
  115. imageHeightM: 140,
  116. form: {
  117. organId: [],
  118. name: null,
  119. coverImg: "",
  120. soundResource: null,
  121. sysMusicScoreCategoriesList: [],
  122. // delCategoriesIds: [],
  123. },
  124. index: 0,
  125. treeProps: {
  126. children: "sysMusicScoreCategoriesList",
  127. label: "name",
  128. },
  129. level: 0, // 当前添加或修改第几层
  130. };
  131. },
  132. async mounted() {
  133. await this.$store.dispatch("setBranchs");
  134. if (this.activeRow?.id) {
  135. // 判断是否是根元素处理
  136. // if(this.activeRow?.parentId != 0) {
  137. this.imageWidthM = 210
  138. this.imageHeightM = 268
  139. // }
  140. this.level = this.activeRow?.level || 0
  141. try {
  142. const res = await getSysMusicScoreDetail({ id: this.activeRow.id });
  143. if(this.type == 'create') { // 添加一级分类或子级
  144. this.form.organId = res.data.organId.split(",").map((item) => {
  145. return Number(item);
  146. });
  147. } else if(this.type == 'update') { // 修改分类
  148. this.form.name = res.data.name;
  149. this.form.organId = res.data.organId.split(",").map((item) => {
  150. return Number(item);
  151. });
  152. this.form.coverImg = res.data.coverImg;
  153. this.form.soundResource = res.data.soundResource;
  154. }
  155. } catch (e) {}
  156. }
  157. },
  158. methods: {
  159. formatParentId(id, list, ids = []) {
  160. for (const item of list) {
  161. if (item.sysMusicScoreCategoriesList) {
  162. const cIds = this.formatParentId(
  163. id,
  164. item.sysMusicScoreCategoriesList,
  165. [...ids, item.id]
  166. );
  167. if (cIds.includes(id)) {
  168. return cIds;
  169. }
  170. }
  171. if (item.id === id) {
  172. return [...ids, id];
  173. }
  174. }
  175. return ids;
  176. },
  177. addSubmit() {
  178. this.$refs.form.validate(async (flag) => {
  179. if (flag) {
  180. let { organId, ...rest } = this.form;
  181. let parentId = 0
  182. if(this.type == 'create') {
  183. parentId = this.activeRow?.id || 0
  184. } else if(this.type == 'update') {
  185. parentId = this.activeRow?.parentId || 0
  186. }
  187. let obj = {
  188. ...rest,
  189. parentId,
  190. organId: organId.join(","),
  191. };
  192. try {
  193. if (this.type == 'update') {
  194. obj.id = this.activeRow?.id;
  195. await resetsysMusicScore(obj);
  196. this.$message.success("修改成功");
  197. this.$emit("getList");
  198. this.$emit("close");
  199. } else {
  200. await addsysMusicScore(obj);
  201. this.$message.success("添加成功");
  202. this.$emit("getList");
  203. this.$emit("close");
  204. }
  205. } catch (e) {
  206. console.log(e);
  207. }
  208. }
  209. });
  210. },
  211. uploadImg() {
  212. this.$refs.uploadImg.$refs.upload.submit();
  213. },
  214. },
  215. computed: {},
  216. };
  217. </script>
  218. <style lang="scss" scoped>
  219. .dialog-footer {
  220. display: block;
  221. text-align: right;
  222. }
  223. .alert {
  224. margin-bottom: 20px;
  225. }
  226. .form {
  227. /deep/.el-form-item {
  228. margin-right: 0 !important;
  229. }
  230. }
  231. .addCateBtn {
  232. margin-bottom: 20px;
  233. }
  234. .custom-tree-node {
  235. .title {
  236. font-size: 16px;
  237. }
  238. font-size: 14px;
  239. i {
  240. // font-size: 20px;
  241. margin-left: 5px;
  242. }
  243. }
  244. .uploadImg {
  245. /deep/.avatar {
  246. width: 350px;
  247. height: 140px;
  248. }
  249. }
  250. .uploadSmallImg {
  251. /deep/.avatar {
  252. width: 105px;
  253. height: 134px;
  254. }
  255. }
  256. </style>