index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <!-- -->
  2. <template>
  3. <div class="m-container">
  4. <h2>
  5. <div class="squrt"></div>
  6. 教材列表
  7. </h2>
  8. <div class="m-core">
  9. <save-form
  10. :inline="true"
  11. :model="searchForm"
  12. @submit="search"
  13. @reset="onReSet"
  14. ref="searchForm"
  15. >
  16. <el-form-item prop="search">
  17. <el-input
  18. v-model.trim="searchForm.search"
  19. clearable
  20. @keyup.enter.native="search"
  21. placeholder="教材编号、名称"
  22. ></el-input>
  23. </el-form-item>
  24. <el-form-item prop="organId">
  25. <el-select
  26. class="multiple"
  27. v-model.trim="searchForm.organId"
  28. filterable
  29. clearable
  30. placeholder="请选择分部"
  31. >
  32. <el-option
  33. v-for="(item, index) in selects.branchs"
  34. :key="index"
  35. :label="item.name"
  36. :value="item.id"
  37. ></el-option>
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item prop="enable">
  41. <el-select
  42. v-model.trim="searchForm.enable"
  43. placeholder="教材状态"
  44. clearable
  45. >
  46. <el-option label="启用" value="1"></el-option>
  47. <el-option label="停用" value="0"></el-option>
  48. </el-select>
  49. </el-form-item>
  50. <el-form-item>
  51. <el-button native-type="submit" type="primary">搜索</el-button>
  52. <el-button native-type="reset" type="danger">重置</el-button>
  53. </el-form-item>
  54. </save-form>
  55. <div class="btnList">
  56. <auth auths="sysMusicScoreCategories/save">
  57. <el-button type="primary" @click="operationTeachClass('create')">新增教材</el-button>
  58. </auth>
  59. </div>
  60. <div class="tableWrap">
  61. <el-table
  62. style="width: 100%"
  63. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  64. :data="tableList"
  65. row-key="id"
  66. :expand-row-keys="expands"
  67. :tree-props="{children: 'sysMusicScoreCategoriesList', hasChildren: 'hasChildren'}"
  68. >
  69. <!-- <el-table-column
  70. align="center"
  71. prop="id"
  72. label="教材编号"
  73. ></el-table-column> -->
  74. <el-table-column
  75. align="left"
  76. prop="name"
  77. label="教材名称"
  78. >
  79. <template slot-scope="scope">
  80. {{ scope.row.name }}({{ scope.row.id }})
  81. </template>
  82. </el-table-column>
  83. <!-- <el-table-column align="center" prop="organNames" label="可见分部">
  84. <template slot-scope="scope">
  85. <div>
  86. <overflow-text :text="scope.row.organNames"></overflow-text>
  87. </div>
  88. </template>
  89. </el-table-column> -->
  90. <el-table-column
  91. align="center"
  92. prop="musicScoreNum"
  93. label="曲目数量"
  94. ></el-table-column>
  95. <el-table-column
  96. align="center"
  97. prop="musicScoreNum"
  98. label="使用音源"
  99. >
  100. <template slot-scope="scope">
  101. {{ scope.row.soundResource | formatSoundReSource }}
  102. </template>
  103. </el-table-column>
  104. <el-table-column
  105. align="center"
  106. prop="updateTime"
  107. label="最后更新时间"
  108. ></el-table-column>
  109. <el-table-column align="center" prop="studentId" label="教材状态">
  110. <template slot-scope="scope">
  111. <div>
  112. {{ scope.row.enable ? "启用" : "停用" }}
  113. </div>
  114. </template>
  115. </el-table-column>
  116. <el-table-column align="center" prop="studentId" label="操作">
  117. <template slot-scope="scope">
  118. <div>
  119. <auth auths="/accompaniment">
  120. <el-button type="text" @click="lookMusic(scope.row)"
  121. >查看</el-button
  122. >
  123. </auth>
  124. <auth auths="sysMusicScoreCategories/update">
  125. <el-button
  126. type="text"
  127. @click="operationTeachClass('create', scope.row)"
  128. v-if="!scope.row.enable && formatParentId(scope.row.id, tableList).length < 4"
  129. >添加</el-button
  130. >
  131. </auth>
  132. <auth auths="sysMusicScoreCategories/update">
  133. <el-button
  134. type="text"
  135. @click="operationTeachClass('update', scope.row)"
  136. v-if="!scope.row.enable"
  137. >修改</el-button
  138. >
  139. </auth>
  140. <auth auths="sysMusicScoreCategories/enable">
  141. <el-button
  142. type="text"
  143. v-if="scope.row.enable"
  144. @click="stopTeach(scope.row)"
  145. >停用</el-button
  146. >
  147. <el-button
  148. type="text"
  149. v-if="!scope.row.enable"
  150. @click="stopTeach(scope.row)"
  151. >启用</el-button
  152. >
  153. </auth>
  154. <auth auths="sysMusicScoreCategories/delete">
  155. <el-button
  156. type="text"
  157. v-if="!scope.row.enable"
  158. @click="removeTeach(scope.row)"
  159. >删除</el-button
  160. >
  161. </auth>
  162. </div>
  163. </template>
  164. </el-table-column>
  165. </el-table>
  166. <!-- <pagination
  167. sync
  168. :total.sync="rules.total"
  169. :page.sync="rules.page"
  170. :limit.sync="rules.limit"
  171. :page-sizes="rules.page_size"
  172. @pagination="getList"
  173. /> -->
  174. </div>
  175. </div>
  176. <el-dialog
  177. :title="type == 'create' ? '新增教材' : '修改教材'"
  178. :visible.sync="teachClassVisible"
  179. width="600px"
  180. v-if="teachClassVisible"
  181. >
  182. <teachClass
  183. @close="teachClassVisible = false"
  184. @getList="getList"
  185. ref="teachClass"
  186. :type="type"
  187. v-if="teachClassVisible"
  188. :activeRow="activeRow"
  189. />
  190. </el-dialog>
  191. </div>
  192. </template>
  193. <script>
  194. import pagination from "@/components/Pagination/index";
  195. import teachClass from "./modals/addRoot";
  196. import { queryTree } from '../accompaniment/api'
  197. import {
  198. getSysMusicScoreList,
  199. enableSysMusicScore,
  200. removeSysMusicScore,
  201. } from "./api";
  202. export default {
  203. components: { pagination, teachClass },
  204. data() {
  205. return {
  206. searchForm: {
  207. search: null,
  208. enable: null,
  209. organId: null,
  210. },
  211. tableList: [],
  212. organList: [],
  213. activeRow: null,
  214. type: 'create',
  215. teachClassVisible: false,
  216. expands: []
  217. };
  218. },
  219. //生命周期 - 挂载完成(可以访问DOM元素)
  220. mounted() {
  221. // 获取分部
  222. this.$store.dispatch("setBranchs");
  223. this.getList();
  224. },
  225. filters: {
  226. formatSoundReSource(val) {
  227. let template = {
  228. NOTEPERFORMER: 'NotePerformer音源',
  229. TANG: '标准音源',
  230. OFFICIAL: '官方音源'
  231. }
  232. return template[val]
  233. }
  234. },
  235. methods: {
  236. async getList() {
  237. let {organId ,...rest} = this.searchForm
  238. try {
  239. const res = await queryTree({
  240. // organId:organId.join(','),
  241. ...rest
  242. });
  243. console.log(res)
  244. this.tableList = res.data;
  245. } catch (e) {}
  246. },
  247. search() {
  248. this.getList();
  249. },
  250. onReSet() {
  251. this.$refs.searchForm.resetFields();
  252. this.search();
  253. },
  254. operationTeachClass(type, row) {
  255. console.log(row, this.expands)
  256. console.log(this.formatParentId(row.id, this.tableList))
  257. this.type = type
  258. this.activeRow = row || null;
  259. this.teachClassVisible = true;
  260. },
  261. formatParentId(id, list, ids = []) {
  262. for (const item of list) {
  263. if (item.sysMusicScoreCategoriesList) {
  264. const cIds = this.formatParentId(
  265. id,
  266. item.sysMusicScoreCategoriesList,
  267. [...ids, item.id]
  268. );
  269. if (cIds.includes(id)) {
  270. return cIds;
  271. }
  272. }
  273. if (item.id === id) {
  274. return [...ids, id];
  275. }
  276. }
  277. return ids;
  278. },
  279. async stopTeach(row) {
  280. let str = "";
  281. if (row.enable) {
  282. str = `是否停用${row.name}该教材`;
  283. } else {
  284. str = `是否启用${row.name}该教材`;
  285. }
  286. this.$confirm(str, "提示", {
  287. confirmButtonText: "确定",
  288. cancelButtonText: "取消",
  289. type: "warning",
  290. })
  291. .then(async () => {
  292. try {
  293. const res = await enableSysMusicScore({ categoriesId: row.id });
  294. if (row.enable) {
  295. this.$message.success("停用成功");
  296. } else {
  297. this.$message.success("启用成功");
  298. }
  299. this.getList();
  300. } catch (e) {
  301. console.log(e);
  302. }
  303. })
  304. .catch((e) => {
  305. console.log(e);
  306. });
  307. },
  308. async removeTeach(row) {
  309. this.$confirm(`是否删除${row.name}`, "提示", {
  310. confirmButtonText: "确定",
  311. cancelButtonText: "取消",
  312. type: "warning",
  313. })
  314. .then(async () => {
  315. try {
  316. const res = await removeSysMusicScore({ id: row.id });
  317. this.$message.success("删除成功");
  318. this.getList();
  319. } catch (e) {
  320. console.log(e);
  321. }
  322. })
  323. .catch((e) => {
  324. console.log(e);
  325. });
  326. },
  327. lookMusic(row) {
  328. this.$router.push({
  329. name: "accompaniment",
  330. params: { categoriesId: row.id },
  331. });
  332. },
  333. },
  334. };
  335. </script>
  336. <style lang='scss' scoped>
  337. .btnList {
  338. margin-bottom: 20px;
  339. }
  340. </style>