CourseManage.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="course-manage">
  3. <div class="part-box part-box-filter part-box-flex">
  4. <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
  5. <template v-if="checkPrivilege('condition', 'condition')">
  6. <el-form-item label="机构:">
  7. <teaching-room-select
  8. v-model="filter.belongOrgId"
  9. placeholder="机构"
  10. clearable
  11. ></teaching-room-select>
  12. </el-form-item>
  13. <el-form-item label="课程名称:">
  14. <el-input
  15. style="width: 142px;"
  16. v-model.trim="filter.courseName"
  17. placeholder="课程名称"
  18. clearable
  19. ></el-input>
  20. </el-form-item>
  21. <el-form-item label="启用/禁用:" label-width="90px">
  22. <el-select
  23. v-model="filter.enable"
  24. style="width: 120px;"
  25. placeholder="启用/禁用"
  26. clearable
  27. >
  28. <el-option
  29. v-for="(val, key) in ABLE_TYPE"
  30. :key="key"
  31. :value="key * 1"
  32. :label="val"
  33. ></el-option>
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item label="创建时间:">
  37. <el-date-picker
  38. v-model="createTime"
  39. type="datetimerange"
  40. :picker-options="pickerOptions"
  41. range-separator="至"
  42. start-placeholder="创建开始时间"
  43. end-placeholder="创建结束时间"
  44. value-format="timestamp"
  45. align="right"
  46. unlink-panels
  47. >
  48. </el-date-picker>
  49. </el-form-item>
  50. </template>
  51. <el-form-item>
  52. <el-button
  53. v-if="checkPrivilege('button', 'select')"
  54. type="primary"
  55. @click="toPage(1)"
  56. >查询</el-button
  57. >
  58. </el-form-item>
  59. </el-form>
  60. <div class="part-box-action">
  61. <el-button
  62. type="danger"
  63. :disabled="!filterHasQuery"
  64. @click="toBatchDeable"
  65. >批量禁用</el-button
  66. >
  67. <el-button
  68. type="success"
  69. icon="el-icon-download"
  70. v-if="checkPrivilege('button', 'TempleteDownload')"
  71. ><a :href="downloadUrl" :download="dfilename">模板下载</a></el-button
  72. >
  73. <upload-button
  74. v-if="checkPrivilege('button', 'Import')"
  75. btn-icon="el-icon-circle-plus-outline"
  76. btn-content="批量导入"
  77. btn-type="success"
  78. :upload-url="uploadUrl"
  79. :format="['xls', 'xlsx']"
  80. accept=".xls,.xlsx"
  81. @valid-error="validError"
  82. @upload-success="uploadSuccess"
  83. >
  84. </upload-button>
  85. <el-button
  86. v-if="checkPrivilege('button', 'add')"
  87. type="primary"
  88. icon="el-icon-circle-plus-outline"
  89. @click="toAdd"
  90. >新增课程</el-button
  91. >
  92. </div>
  93. </div>
  94. <div class="part-box part-box-pad">
  95. <el-table ref="TableList" :data="courses">
  96. <el-table-column
  97. type="index"
  98. label="序号"
  99. width="70"
  100. :index="indexMethod"
  101. ></el-table-column>
  102. <el-table-column prop="courseName" label="课程名称"></el-table-column>
  103. <el-table-column prop="courseCode" label="课程编码"></el-table-column>
  104. <el-table-column
  105. prop="teachingRoomName"
  106. label="所属机构"
  107. ></el-table-column>
  108. <el-table-column prop="clazzList" label="授课班级">
  109. <span slot-scope="scope">
  110. <more-text :data="scope.row.clazzNames" :show-count="3"></more-text>
  111. </span>
  112. </el-table-column>
  113. <el-table-column prop="createTime" label="创建时间">
  114. <span slot-scope="scope">{{
  115. scope.row.createTime | timestampFilter
  116. }}</span>
  117. </el-table-column>
  118. <el-table-column prop="enable" label="启用/禁用" width="100">
  119. <template slot-scope="scope">
  120. {{ scope.row.enable | enableFilter }}
  121. </template>
  122. </el-table-column>
  123. <el-table-column class-name="action-column" label="操作" width="120px">
  124. <template slot-scope="scope">
  125. <el-button
  126. v-if="checkPrivilege('link', 'edit')"
  127. class="btn-primary"
  128. type="text"
  129. @click="toEdit(scope.row)"
  130. >编辑</el-button
  131. >
  132. <el-button
  133. v-if="checkPrivilege('link', 'Enable')"
  134. :class="scope.row.enable ? 'btn-danger' : 'btn-primary'"
  135. type="text"
  136. @click="toEnable(scope.row)"
  137. >{{ scope.row.enable ? "禁用" : "启用" }}</el-button
  138. >
  139. <!-- <el-button
  140. class="btn-danger"
  141. type="text"
  142. @click="toDelete(scope.row)"
  143. >删除</el-button
  144. > -->
  145. </template>
  146. </el-table-column>
  147. </el-table>
  148. <div class="part-page">
  149. <el-pagination
  150. background
  151. layout="total,prev, pager, next"
  152. :current-page="current"
  153. :total="total"
  154. :page-size="size"
  155. @current-change="toPage"
  156. >
  157. </el-pagination>
  158. </div>
  159. </div>
  160. <modify-course
  161. :instance="curCourse"
  162. @modified="getList"
  163. ref="ModifyCourse"
  164. ></modify-course>
  165. </div>
  166. </template>
  167. <script>
  168. import {
  169. courseListPage,
  170. deleteCourse,
  171. ableCourse,
  172. batchEnableCourse
  173. } from "../api";
  174. import pickerOptions from "@/constants/datePickerOptions";
  175. import ModifyCourse from "../components/ModifyCourse";
  176. import UploadButton from "../../../components/UploadButton";
  177. import { ABLE_TYPE } from "@/constants/enumerate";
  178. export default {
  179. name: "course-manage",
  180. components: { ModifyCourse, UploadButton },
  181. data() {
  182. return {
  183. filter: {
  184. belongOrgId: "",
  185. courseName: "",
  186. startCreateTime: "",
  187. endCreateTime: "",
  188. enable: ""
  189. },
  190. queriedFilter: {},
  191. ABLE_TYPE,
  192. current: 1,
  193. size: this.GLOBAL.pageSize,
  194. total: 0,
  195. courses: [],
  196. curCourse: {},
  197. // import
  198. uploadUrl: "/api/admin/basic/course/data_import",
  199. downloadUrl: "/temps/courseTemplate.xlsx",
  200. dfilename: "课程导入模板.xlsx",
  201. // date-picker
  202. createTime: [],
  203. pickerOptions
  204. };
  205. },
  206. computed: {
  207. filterHasQuery() {
  208. return !Object.keys(this.filter).some(
  209. k => this.filter[k] !== this.queriedFilter[k]
  210. );
  211. }
  212. },
  213. mounted() {
  214. this.getList();
  215. },
  216. methods: {
  217. async getList() {
  218. if (!this.checkPrivilege("list", "list")) return;
  219. const datas = {
  220. ...this.filter,
  221. pageNumber: this.current,
  222. pageSize: this.size
  223. };
  224. if (this.createTime) {
  225. datas.startCreateTime = this.createTime[0];
  226. datas.endCreateTime = this.createTime[1];
  227. }
  228. if (datas.enable !== null && datas.enable !== "")
  229. datas.enable = !!datas.enable;
  230. const data = await courseListPage(datas);
  231. this.courses = data.records.map(item => {
  232. item.clazzNames = item.clazzList.map(org => org.name);
  233. return item;
  234. });
  235. this.total = data.total;
  236. this.queriedFilter = { ...this.filter };
  237. },
  238. toPage(page) {
  239. this.current = page;
  240. this.getList();
  241. },
  242. toAdd() {
  243. this.curCourse = {};
  244. this.$refs.ModifyCourse.open();
  245. },
  246. toEdit(row) {
  247. this.curCourse = row;
  248. this.$refs.ModifyCourse.open();
  249. },
  250. toDelete(row) {
  251. this.$confirm(`确定要删除课程【${row.courseName}】吗?`, "提示", {
  252. type: "warning"
  253. })
  254. .then(async () => {
  255. await deleteCourse([row.id]);
  256. this.$message.success("删除成功!");
  257. this.deletePageLastItem();
  258. })
  259. .catch(() => {});
  260. },
  261. toEnable(row) {
  262. const action = row.enable ? "禁用" : "启用";
  263. this.$confirm(`确定要${action}课程【${row.courseName}】吗?`, "提示", {
  264. type: "warning"
  265. })
  266. .then(async () => {
  267. const enable = !row.enable;
  268. await ableCourse({
  269. idList: [row.id],
  270. enable
  271. });
  272. row.enable = enable;
  273. this.$message.success("操作成功!");
  274. })
  275. .catch(() => {});
  276. },
  277. toBatchDeable() {
  278. this.$confirm(`确定要禁用当前查询的所有课程吗?`, "提示", {
  279. type: "warning"
  280. })
  281. .then(async () => {
  282. await batchEnableCourse({ ...this.filter, enableOperate: false });
  283. this.$message.success("操作成功!");
  284. this.toPage(1);
  285. })
  286. .catch(() => {});
  287. },
  288. // import
  289. validError(errorData) {
  290. this.$message.error(errorData.message);
  291. },
  292. uploadSuccess() {
  293. this.$message.success("文件上传成功,后台正在导入!");
  294. this.getList();
  295. }
  296. }
  297. };
  298. </script>