index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. >
  15. <el-form-item>
  16. <el-input
  17. v-model.trim="searchForm.search"
  18. clearable
  19. @keyup.enter.native="search"
  20. placeholder="教材编号、名称"
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item prop="visitFlag">
  24. <el-select
  25. v-model.trim="searchForm.visitFlag"
  26. placeholder="教材状态"
  27. clearable
  28. >
  29. <el-option label="启动" value="1"></el-option>
  30. <el-option label="停用" value="0"></el-option>
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button native-type="submit" type="primary">搜索</el-button>
  35. <el-button native-type="reset" type="danger">重置</el-button>
  36. </el-form-item>
  37. </save-form>
  38. <div class="btnList">
  39. <el-button type="primary" @click="addTeach">新增教材</el-button>
  40. </div>
  41. <div class="tableWrap">
  42. <el-table
  43. style="width: 100%"
  44. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  45. :data="tableList"
  46. >
  47. <el-table-column
  48. align="center"
  49. prop="id"
  50. label="教材编号"
  51. ></el-table-column>
  52. <el-table-column
  53. align="center"
  54. prop="name"
  55. label="教材名称"
  56. ></el-table-column>
  57. <el-table-column
  58. align="center"
  59. prop="organNames"
  60. label="可见分部"
  61. ></el-table-column>
  62. <el-table-column
  63. align="center"
  64. prop="studentId"
  65. label="曲目数量"
  66. ></el-table-column>
  67. <el-table-column
  68. align="center"
  69. prop="updateTime"
  70. label="最后更新时间"
  71. ></el-table-column>
  72. <el-table-column align="center" prop="studentId" label="教材状态">
  73. <template slot-scope="scope">
  74. <div>
  75. {{ scope.row.enable ? "启用" : "停用" }}
  76. </div>
  77. </template>
  78. </el-table-column>
  79. <el-table-column align="center" prop="studentId" label="操作">
  80. <template slot-scope="scope">
  81. <div>
  82. <el-button type="text">查看</el-button>
  83. <el-button
  84. type="text"
  85. @click="resetTeach(scope.row)"
  86. v-if="!scope.row.enable"
  87. >修改</el-button
  88. >
  89. <el-button
  90. type="text"
  91. v-if="scope.row.enable"
  92. @click="stopTeach(scope.row)"
  93. >停用</el-button
  94. >
  95. <el-button
  96. type="text"
  97. v-if="!scope.row.enable"
  98. @click="stopTeach(scope.row)"
  99. >启用</el-button
  100. >
  101. <el-button
  102. type="text"
  103. v-if="!scope.row.enable"
  104. @click="removeTeach(scope.row)"
  105. >删除</el-button
  106. >
  107. </div>
  108. </template>
  109. </el-table-column>
  110. </el-table>
  111. <pagination
  112. sync
  113. :total.sync="rules.total"
  114. :page.sync="rules.page"
  115. :limit.sync="rules.limit"
  116. :page-sizes="rules.page_size"
  117. @pagination="getList"
  118. />
  119. </div>
  120. </div>
  121. <el-dialog
  122. title="新增教材"
  123. :visible.sync="teachVisible"
  124. width="800px"
  125. v-if="teachVisible"
  126. >
  127. <addTeach
  128. @close="teachVisible = false"
  129. @getList="getList"
  130. ref="addTeach"
  131. v-if="teachVisible"
  132. :activeRow="activeRow"
  133. />
  134. <span slot="footer" class="dialog-footer">
  135. <el-button @click="teachVisible = false">取 消</el-button>
  136. <el-button type="primary" @click="submitAdd">确 定</el-button>
  137. </span>
  138. </el-dialog>
  139. </div>
  140. </template>
  141. <script>
  142. import axios from "axios";
  143. import { getToken } from "@/utils/auth";
  144. import pagination from "@/components/Pagination/index";
  145. import load from "@/utils/loading";
  146. import addTeach from "./modals/addTeach";
  147. import {
  148. getSysMusicScoreList,
  149. enableSysMusicScore,
  150. removeSysMusicScore,
  151. } from "./api";
  152. export default {
  153. components: { pagination, addTeach },
  154. data() {
  155. return {
  156. searchForm: {
  157. search: null,
  158. },
  159. tableList: [],
  160. organList: [],
  161. rules: {
  162. // 分页规则
  163. limit: 10, // 限制显示条数
  164. page: 1, // 当前页
  165. total: 0, // 总条数
  166. page_size: [10, 20, 40, 50], // 选择限制显示条数
  167. },
  168. teachVisible: false,
  169. activeRow: null,
  170. };
  171. },
  172. //生命周期 - 创建完成(可以访问当前this实例)
  173. created() {},
  174. //生命周期 - 挂载完成(可以访问DOM元素)
  175. mounted() {
  176. // 获取分部
  177. this.init();
  178. },
  179. methods: {
  180. init() {
  181. this.getList();
  182. },
  183. async getList() {
  184. try {
  185. const res = await getSysMusicScoreList({
  186. ...this.searchForm,
  187. page: this.rules.page,
  188. rows: this.rules.limit,
  189. });
  190. this.rules.total = res.data.total;
  191. this.tableList = res.data.rows;
  192. } catch (e) {}
  193. },
  194. search() {
  195. this.rules.page = 1;
  196. this.getList();
  197. },
  198. onReSet() {},
  199. addTeach() {
  200. this.activeRow = null;
  201. this.teachVisible = true;
  202. },
  203. submitAdd() {
  204. this.$refs.addTeach.addSubmit();
  205. },
  206. resetTeach(row) {
  207. this.activeRow = row;
  208. this.teachVisible = true;
  209. },
  210. async stopTeach(row) {
  211. let str = "";
  212. if (row.enable) {
  213. str = `是否停用${row.name}该教材`;
  214. } else {
  215. str = `是否启用${row.name}该教材`;
  216. }
  217. this.$confirm(str, "提示", {
  218. confirmButtonText: "确定",
  219. cancelButtonText: "取消",
  220. type: "warning",
  221. })
  222. .then(async () => {
  223. try {
  224. const res = await enableSysMusicScore({ categoriesId: row.id });
  225. if (row.enable) {
  226. this.$message.success("停用成功");
  227. } else {
  228. this.$message.success("启用成功");
  229. }
  230. this.getList();
  231. } catch (e) {
  232. console.log(e);
  233. }
  234. })
  235. .catch((e) => {
  236. console.log(e);
  237. });
  238. },
  239. async removeTeach(row) {
  240. this.$confirm(`是否删除${row.name}`, "提示", {
  241. confirmButtonText: "确定",
  242. cancelButtonText: "取消",
  243. type: "warning",
  244. })
  245. .then(async () => {
  246. try {
  247. const res = await removeSysMusicScore({ id: row.id });
  248. this.$message.success("删除成功");
  249. this.getList();
  250. } catch (e) {
  251. console.log(e);
  252. }
  253. })
  254. .catch((e) => {
  255. console.log(e);
  256. });
  257. },
  258. },
  259. };
  260. </script>
  261. <style lang='scss' scoped>
  262. .btnList {
  263. margin-bottom: 20px;
  264. }
  265. </style>