DimensionAbilityList.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div class="dimension-ability-list">
  3. <div class="mb-4 box-justify">
  4. <el-button type="success" @click="toImport">导入</el-button>
  5. <el-button type="primary" @click="toAdd">新增</el-button>
  6. </div>
  7. <div class="part-box part-box-border-bold dimension-table">
  8. <el-table ref="TableList" :data="dataList">
  9. <el-table-column prop="courseCode" label="课程代码"></el-table-column>
  10. <el-table-column prop="courseName" label="课程名称"> </el-table-column>
  11. <el-table-column prop="namePrimary" label="一级能力维度">
  12. </el-table-column>
  13. <el-table-column prop="codePrimary" label="一级维度编号">
  14. </el-table-column>
  15. <el-table-column prop="interpretation" label="一级维度术语解释">
  16. </el-table-column>
  17. <el-table-column
  18. class-name="action-column"
  19. label="操作"
  20. width="180px"
  21. align="center"
  22. >
  23. <template slot-scope="scope">
  24. <el-button
  25. class="btn-primary"
  26. type="text"
  27. :disabled="loading"
  28. @click="toEdit(scope.row)"
  29. >编辑</el-button
  30. >
  31. <el-button
  32. class="btn-danger"
  33. type="text"
  34. :disabled="loading"
  35. @click="toDelete(scope)"
  36. >删除</el-button
  37. >
  38. <el-button
  39. class="btn-primary"
  40. type="text"
  41. :disabled="loading || scope.row.isFirstSec"
  42. @click="toUp(scope)"
  43. >上移</el-button
  44. >
  45. <el-button
  46. class="btn-primary"
  47. type="text"
  48. :disabled="loading || scope.row.isLastSec"
  49. @click="toDown(scope)"
  50. >下移</el-button
  51. >
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. </div>
  56. <import-file
  57. ref="ImportFile"
  58. title="上传文件"
  59. :upload-url="uploadUrl"
  60. :upload-data="uploadData"
  61. :download-handle="downloadHandle"
  62. download-filename="能力维度模板"
  63. :format="['xls', 'xlsx']"
  64. @upload-success="fileUploaded"
  65. >
  66. </import-file>
  67. <!-- ModifyAbilityDim -->
  68. <modify-ability-dim
  69. ref="ModifyAbilityDim"
  70. :instance="curRow"
  71. :dict-data="dataList"
  72. @modified="modified"
  73. ></modify-ability-dim>
  74. </div>
  75. </template>
  76. <script>
  77. import { mapState, mapActions, mapMutations } from "vuex";
  78. import ImportFile from "@/components/ImportFile";
  79. import ModifyAbilityDim from "./ModifyAbilityDim.vue";
  80. import { paperDimensionExport } from "../../api";
  81. import { downloadByApi } from "@/plugins/download";
  82. export default {
  83. name: "dimension-ability-list",
  84. components: { ImportFile, ModifyAbilityDim },
  85. data() {
  86. return {
  87. dataList: [],
  88. curRow: {},
  89. loading: false,
  90. // upload
  91. uploadUrl: "/api/admin/grade/paper/dimension/import",
  92. uploadData: {},
  93. downloading: false
  94. };
  95. },
  96. computed: {
  97. ...mapState("baseConfigs", ["dimensionList", "baseInfo"])
  98. },
  99. mounted() {
  100. this.initData();
  101. },
  102. methods: {
  103. ...mapMutations("baseConfigs", ["setDimensionList"]),
  104. ...mapActions("baseConfigs", ["fetchDimensionList"]),
  105. initData() {
  106. this.dataList = this.dimensionList
  107. .filter(item => item.dimensionType === "ABILITY")
  108. .map(item => {
  109. return { ...item, id: this.$randomCode() };
  110. });
  111. this.sortDataList();
  112. this.uploadData = {
  113. paperNumber: this.baseInfo.paperNumber,
  114. paperType: this.baseInfo.paperType,
  115. paperName: this.baseInfo.paperName,
  116. dimensionType: "ABILITY"
  117. };
  118. },
  119. toImport() {
  120. this.$refs.ImportFile.open();
  121. },
  122. async downloadHandle() {
  123. if (this.downloading) return;
  124. this.downloading = true;
  125. const res = await downloadByApi(() => {
  126. return paperDimensionExport({
  127. courseCode: this.baseInfo.courseCode,
  128. courseName: this.baseInfo.courseName,
  129. dimensionType: "ABILITY"
  130. });
  131. }).catch(e => {
  132. this.$message.error(e || "下载失败,请重新尝试!");
  133. });
  134. this.downloading = false;
  135. if (!res) return;
  136. this.$message.success("下载成功!");
  137. },
  138. async fileUploaded() {
  139. this.$message.success("导入成功!");
  140. await this.fetchDimensionList();
  141. this.initData();
  142. },
  143. modified(data) {
  144. if (data.id) {
  145. const pos = this.dataList.findIndex(item => item.id === data.id);
  146. this.dataList.splice(pos, 1, data);
  147. } else {
  148. this.dataList.push({ ...data, id: this.$randomCode() });
  149. }
  150. this.sortDataList();
  151. this.updateChange();
  152. },
  153. sortDataList() {
  154. this.dataList.sort((a, b) => {
  155. return a.codePrimary < b.codePrimary ? -1 : 1;
  156. });
  157. },
  158. toAdd() {
  159. this.curRow = {
  160. courseCode: this.baseInfo.courseCode,
  161. courseName: this.baseInfo.courseName
  162. };
  163. this.$refs.ModifyAbilityDim.open();
  164. },
  165. toEdit(row) {
  166. this.curRow = row;
  167. this.$refs.ModifyAbilityDim.open();
  168. },
  169. toDelete({ $index }) {
  170. this.dataList.splice($index, 1);
  171. this.updateChange();
  172. },
  173. toUp({ row, $index }) {
  174. const pos = $index;
  175. const curRowCode = row.codePrimary;
  176. const prevRowCode = this.dataList[$index - 1].codePrimary;
  177. this.dataList.splice(pos, 1);
  178. this.dataList.splice(pos - 1, 0, row);
  179. this.dataList[pos].codePrimary = curRowCode;
  180. this.dataList[pos - 1].codePrimary = prevRowCode;
  181. this.updateChange();
  182. },
  183. toDown({ row, $index }) {
  184. const pos = $index;
  185. const curRowCode = row.codePrimary;
  186. const nextRowCode = this.dataList[$index + 1].codePrimary;
  187. this.dataList.splice(pos, 1);
  188. this.dataList.splice(pos, 0, row);
  189. this.dataList[pos].codePrimary = curRowCode;
  190. this.dataList[pos + 1].codePrimary = nextRowCode;
  191. this.updateChange();
  192. },
  193. updateChange() {
  194. const abilityList = this.dimensionList.filter(
  195. item => item.dimensionType === "ABILITY"
  196. );
  197. this.setDimensionList([...this.dataList, ...abilityList]);
  198. }
  199. }
  200. };
  201. </script>