TrainingPlanCourse.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div class="training-plan-matrix">
  3. <div class="part-box part-box-pad">
  4. <div class="box-justify mb-2">
  5. <div></div>
  6. <el-button type="primary" icon="el-icon-add" @click="toAdd"
  7. >选择课程</el-button
  8. >
  9. </div>
  10. <el-table ref="TableList" :data="dataList">
  11. <el-table-column type="index" label="序号" width="70"></el-table-column>
  12. <el-table-column label="课程(代码)">
  13. <template slot-scope="scope">
  14. {{ scope.row.courseName | defaultFieldFilter }}({{
  15. scope.row.courseCode | defaultFieldFilter
  16. }})
  17. </template>
  18. </el-table-column>
  19. <el-table-column
  20. class-name="action-column"
  21. label="操作"
  22. width="140"
  23. fixed="right"
  24. >
  25. <template slot-scope="scope">
  26. <el-button
  27. class="btn-danger"
  28. type="text"
  29. @click="toDelete(scope.row)"
  30. >删除</el-button
  31. >
  32. <el-button
  33. v-if="scope.$index !== 0"
  34. class="btn-primary"
  35. type="text"
  36. @click="toMove(scope.$index, 'up')"
  37. >上移</el-button
  38. >
  39. <el-button
  40. v-if="scope.$index !== total - 1"
  41. class="btn-primary"
  42. type="text"
  43. @click="toMove(scope.$index, 'down')"
  44. >下移</el-button
  45. >
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. </div>
  50. <!-- AddTrainingPlanCourse -->
  51. <add-training-plan-course
  52. v-if="canEdit"
  53. ref="AddTrainingPlanCourse"
  54. :row-data="rowData"
  55. @modified="getList"
  56. ></add-training-plan-course>
  57. </div>
  58. </template>
  59. <script>
  60. import {
  61. trainingPlanCourseListPage,
  62. deleteRrainingPlanCourse,
  63. sortRrainingPlanCourse,
  64. } from "../../api";
  65. import AddTrainingPlanCourse from "./AddTrainingPlanCourse.vue";
  66. export default {
  67. name: "professional-course",
  68. components: {
  69. AddTrainingPlanCourse,
  70. },
  71. props: {
  72. rowData: {
  73. type: Object,
  74. default() {
  75. return {};
  76. },
  77. },
  78. },
  79. data() {
  80. return {
  81. dataList: [],
  82. total: 0,
  83. };
  84. },
  85. mounted() {
  86. this.getList();
  87. },
  88. methods: {
  89. async getList() {
  90. const data = await trainingPlanCourseListPage({
  91. cultureProgramId: this.rowData.id,
  92. });
  93. this.dataList = data || [];
  94. this.total = this.dataList.length;
  95. },
  96. toAdd() {
  97. this.$refs.AddTrainingPlanCourse.open();
  98. },
  99. exchangeSortNumber(row1, row2) {
  100. const sortNum = row1.sortNum;
  101. row1.sortNum = row2.sortNum;
  102. row2.sortNum = sortNum;
  103. },
  104. async toMove(rowIndex, type) {
  105. const row1 = this.dataList[rowIndex];
  106. const row2 =
  107. type === "up"
  108. ? this.dataList[rowIndex - 1]
  109. : this.dataList[rowIndex + 1];
  110. this.exchangeSortNumber(row1, row2);
  111. const datas = this.dataList.map((item, index) => {
  112. return {
  113. id: item.id,
  114. sortNum: item.sortNum,
  115. };
  116. });
  117. const res = await sortRrainingPlanCourse(datas).catch(() => {
  118. this.exchangeSortNumber(row1, row2);
  119. });
  120. if (!res) return;
  121. this.dataList.sort((a, b) => a.sortNum - b.sortNum);
  122. },
  123. async toDelete(row) {
  124. const confirm = await this.$confirm(
  125. `确定要删除课程【${row.courseName}】吗?`,
  126. "提示",
  127. {
  128. type: "warning",
  129. }
  130. ).catch(() => {});
  131. if (confirm !== "confirm") return;
  132. await deleteRrainingPlanCourse(row.id);
  133. this.$message.success("删除成功!");
  134. this.getList();
  135. },
  136. },
  137. };
  138. </script>