course.vue 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. <template>
  2. <section class="content">
  3. <div class="box box-info">
  4. <div
  5. v-loading.body="fileLoading"
  6. element-loading-text="课程上传中,请稍后..."
  7. >
  8. <el-form
  9. inline
  10. :model="formSearch"
  11. label-width="70px"
  12. ref="primaryForm"
  13. >
  14. <el-form-item label="课程名称">
  15. <el-input
  16. class="input_width_lg"
  17. placeholder="请输入课程名称"
  18. v-model="formSearch.name"
  19. />
  20. </el-form-item>
  21. <el-form-item label="课程代码">
  22. <el-input
  23. class="input_width_lg"
  24. placeholder="请输入课程代码"
  25. v-model="formSearch.code"
  26. />
  27. </el-form-item>
  28. <el-form-item label="课程状态">
  29. <el-select
  30. class="input_width_lg"
  31. v-model="formSearch.enable"
  32. placeholder="请选择"
  33. clearable
  34. >
  35. <el-option
  36. v-for="item in statusList"
  37. :label="item.label"
  38. :value="item.value"
  39. :key="item.value"
  40. />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item label="层次">
  44. <el-select
  45. class="input_width_lg"
  46. v-model="formSearch.level"
  47. placeholder="请选择"
  48. clearable
  49. >
  50. <el-option
  51. v-for="item in levelList"
  52. :label="item.label"
  53. :value="item.value"
  54. :key="item.value"
  55. />
  56. </el-select>
  57. </el-form-item>
  58. <el-form-item label="专业" prop="specialtyId">
  59. <el-select
  60. class="input_width_lg"
  61. remote
  62. :remote-method="getSpecialtyList4Search"
  63. :loading="specialtyLoading4Search"
  64. filterable
  65. clearable
  66. v-model="formSearch.specialtyId"
  67. placeholder="请选择"
  68. >
  69. <el-option
  70. v-for="item in specialtyList4SearchWrapper"
  71. :label="item.name"
  72. :value="item.id"
  73. :key="item.id"
  74. />
  75. </el-select>
  76. </el-form-item>
  77. <el-form-item class="d-block">
  78. <el-button
  79. size="small"
  80. type="primary"
  81. icon="el-icon-search"
  82. @click="handleSearchBtn"
  83. >查询</el-button
  84. >
  85. <el-button size="small" @click="resetPrimaryForm"> 重置 </el-button>
  86. <el-button
  87. size="small"
  88. type="primary"
  89. icon="el-icon-plus"
  90. @click="insertCourse"
  91. >新增</el-button
  92. >
  93. </el-form-item>
  94. </el-form>
  95. <div class="block-seperator"></div>
  96. <span>操作:</span>
  97. <el-button
  98. size="small"
  99. type="success"
  100. @click="enableByIds"
  101. :disabled="noBatchSelected"
  102. >
  103. <i class="fa fa-check" aria-hidden="true"></i>启用
  104. </el-button>
  105. <el-button
  106. size="small"
  107. type="warning"
  108. @click="disableByIds"
  109. :disabled="noBatchSelected"
  110. >
  111. <i class="fa fa-close" aria-hidden="true"></i>禁用
  112. </el-button>
  113. <el-button size="small" type="primary" @click="impCourse">
  114. <i class="fa fa-upload" aria-hidden="true"></i>导入
  115. </el-button>
  116. <el-button size="small" type="primary" @click="exportCourse">
  117. <i class="fa fa-download" aria-hidden="true"></i>导出
  118. </el-button>
  119. <div style="width: 100%;margin-bottom: 10px;"></div>
  120. <!-- 添加或新增课程弹出框 -->
  121. <el-dialog
  122. title="课程"
  123. width="450px"
  124. :visible.sync="courseDialog"
  125. @close="dialogBeforeClose"
  126. >
  127. <el-form
  128. :inline="true"
  129. inline-message
  130. :model="courseForm"
  131. ref="courseForm"
  132. :rules="rules"
  133. label-width="90px"
  134. >
  135. <el-row>
  136. <el-form-item label="课程代码" prop="code">
  137. <el-input
  138. :disabled="null != courseForm.id"
  139. class="pull_length"
  140. v-model="courseForm.code"
  141. auto-complete="off"
  142. placeholder="请输入课程代码"
  143. />
  144. </el-form-item>
  145. </el-row>
  146. <el-row>
  147. <el-form-item label="课程名称" prop="name">
  148. <el-input
  149. class="pull_length"
  150. v-model="courseForm.name"
  151. auto-complete="off"
  152. placeholder="请输入课程名称"
  153. />
  154. </el-form-item>
  155. </el-row>
  156. <el-row>
  157. <el-form-item label="层次" prop="level">
  158. <el-select
  159. class="pull_length"
  160. v-model="courseForm.level"
  161. placeholder="请选择"
  162. >
  163. <el-option
  164. v-for="item in levelList"
  165. :label="item.label"
  166. :value="item.value"
  167. :key="item.value"
  168. />
  169. </el-select>
  170. </el-form-item>
  171. </el-row>
  172. <el-row>
  173. <el-form-item label="课程状态" prop="enable">
  174. <el-radio-group class="pull_length" v-model="courseForm.enable">
  175. <el-radio label="true">开启</el-radio>
  176. <el-radio label="false">关闭</el-radio>
  177. </el-radio-group>
  178. </el-form-item>
  179. </el-row>
  180. <el-row class="pull-center">
  181. <el-button type="primary" @click="submitForm">保 存</el-button>
  182. <el-button @click="courseDialog = false">取 消</el-button>
  183. </el-row>
  184. </el-form>
  185. </el-dialog>
  186. <!-- 导入弹窗 -->
  187. <el-dialog title="导入窗口" :visible.sync="impDialog">
  188. <el-form>
  189. <el-row>
  190. <el-form-item style="margin-left:20px">
  191. <el-upload
  192. class="form_left"
  193. ref="upload"
  194. accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  195. :action="uploadAction"
  196. :headers="uploadHeaders"
  197. :data="uploadData"
  198. :before-upload="beforeUpload"
  199. :on-progress="uploadProgress"
  200. :on-success="uploadSuccess"
  201. :on-error="uploadError"
  202. :file-list="fileList"
  203. :auto-upload="false"
  204. :multiple="false"
  205. >
  206. <el-button size="small" slot="trigger" type="primary">
  207. 选择文件
  208. </el-button>
  209. &nbsp;
  210. <el-button size="small" type="success" @click="submitUpload">
  211. 确认上传
  212. </el-button>
  213. <el-button size="small" type="danger" @click="removeFile">
  214. 清空文件
  215. </el-button>
  216. <el-button size="small" type="info" @click="exportFile">
  217. 下载模板
  218. </el-button>
  219. <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
  220. </el-upload>
  221. </el-form-item>
  222. </el-row>
  223. </el-form>
  224. </el-dialog>
  225. <!-- 导入错误信息列表 -->
  226. <el-dialog title="错误提示" :visible.sync="errDialog">
  227. <div
  228. class="text-danger"
  229. v-for="errMessage in errMessages"
  230. :key="errMessage.lineNum"
  231. >
  232. 第{{ errMessage.lineNum }}行:{{ errMessage.msg }}
  233. </div>
  234. <span slot="footer" class="dialog-footer">
  235. <el-button @click="errDialog = false">确定</el-button>
  236. </span>
  237. </el-dialog>
  238. <!-- 关联专业弹出框 -->
  239. <el-dialog
  240. :title="specialtyDialogTitle"
  241. :visible.sync="specialtyDialog"
  242. width="800px"
  243. >
  244. <!-- 表单 -->
  245. <el-form :inline="true" :model="specialtySearchForm">
  246. <el-form-item label="专业名称">
  247. <el-input
  248. class="input_width_lg"
  249. placeholder="请输入专业名称"
  250. v-model="specialtySearchForm.name"
  251. />
  252. </el-form-item>
  253. <el-form-item label="专业代码">
  254. <el-input
  255. class="input_width_lg"
  256. placeholder="请输入专业代码"
  257. v-model="specialtySearchForm.code"
  258. />
  259. </el-form-item>
  260. <el-form-item>
  261. <el-button
  262. size="small"
  263. type="primary"
  264. icon="el-icon-search"
  265. @click="searchSpecialtyPage"
  266. >
  267. 查询
  268. </el-button>
  269. <el-button
  270. size="small"
  271. type="primary"
  272. icon="el-icon-plus"
  273. @click="addRelation"
  274. >
  275. 新增
  276. </el-button>
  277. </el-form-item>
  278. </el-form>
  279. <!-- 专业列表 -->
  280. <el-table :data="specialtyTableData" border>
  281. <el-table-column prop="id" label="ID" width="100" />
  282. <el-table-column prop="name" label="专业名称" width="250" />
  283. <el-table-column prop="code" label="专业代码" />
  284. <el-table-column prop="updateTime" label="更新时间" width="170" />
  285. <el-table-column label="操作">
  286. <div slot-scope="scope">
  287. <span>
  288. <el-button
  289. size="mini"
  290. type="info"
  291. @click="deleteRelation(scope.row)"
  292. >
  293. <i class="el-icon-edit"></i> 取消关联
  294. </el-button>
  295. </span>
  296. </div>
  297. </el-table-column>
  298. </el-table>
  299. <div class="page pull-right">
  300. <el-pagination
  301. @current-change="handleSpecialtyCurrentChange"
  302. :current-page="currentSpecialtyPage"
  303. :page-size="10"
  304. :total="specialtyTotal"
  305. />
  306. </div>
  307. <div style="margin-bottom: 20px"></div>
  308. </el-dialog>
  309. <!-- 添加关联 -->
  310. <el-dialog title="添加关联专业" v-model="addRelationDialog">
  311. <el-form
  312. :inline="true"
  313. :model="addRelationForm"
  314. ref="addRelationForm"
  315. label-width="100px"
  316. :rules="addRelationRules"
  317. >
  318. <el-row>
  319. <el-form-item label="专业" class="pull-left" prop="specialtyId">
  320. <el-select
  321. class="input"
  322. remote
  323. :remote-method="getSpecialtyList4AddRelation"
  324. :loading="specialtyLoading4AddRelation"
  325. filterable
  326. clearable
  327. v-model="addRelationForm.specialtyId"
  328. placeholder="请选择"
  329. >
  330. <el-option
  331. v-for="item in specialtyList4AddRelationWrapper"
  332. :label="item.name"
  333. :value="item.id"
  334. :key="item.id"
  335. />
  336. </el-select>
  337. </el-form-item>
  338. </el-row>
  339. <el-row class="pull_center">
  340. <el-button type="primary" @click="submitAddRelationForm">
  341. 保 存
  342. </el-button>
  343. <el-button @click="addRelationDialog = false">取 消</el-button>
  344. </el-row>
  345. </el-form>
  346. </el-dialog>
  347. <!-- 页面列表 -->
  348. <el-table
  349. :data="tableData"
  350. border
  351. resizable
  352. stripe
  353. @selection-change="selectChange"
  354. >
  355. <el-table-column type="selection" width="35" />
  356. <el-table-column prop="id" label="课程ID" width="80" />
  357. <el-table-column prop="name" label="课程名称" width="180" />
  358. <el-table-column prop="code" label="课程代码" />
  359. <el-table-column label="层次">
  360. <span slot-scope="scope">{{ getLevel(scope.row.level) }}</span>
  361. </el-table-column>
  362. <el-table-column label="状态" width="70">
  363. <span slot-scope="scope">{{ getEnable(scope.row.enable) }}</span>
  364. </el-table-column>
  365. <el-table-column prop="updateTime" label="更新时间" width="170" />
  366. <el-table-column label="操作" width="260">
  367. <div slot-scope="scope">
  368. <el-button
  369. size="mini"
  370. type="primary"
  371. plain
  372. @click="relation(scope.row)"
  373. >
  374. 关联专业
  375. </el-button>
  376. <el-button
  377. size="mini"
  378. type="primary"
  379. plain
  380. @click="editCourse(scope.row)"
  381. >
  382. <i class="el-icon-edit"></i> 编辑
  383. </el-button>
  384. <el-button
  385. size="mini"
  386. v-if="!scope.row.enable"
  387. type="danger"
  388. @click="enableById(scope.row)"
  389. >
  390. <i class="fa fa-check" aria-hidden="true"></i>启用
  391. </el-button>
  392. <el-button
  393. size="mini"
  394. v-if="scope.row.enable"
  395. type="danger"
  396. @click="disableById(scope.row)"
  397. >
  398. <i class="fa fa-close" aria-hidden="true"></i>禁用
  399. </el-button>
  400. </div>
  401. </el-table-column>
  402. </el-table>
  403. <div class="page pull-right">
  404. <el-pagination
  405. @current-change="handleCurrentChange"
  406. :current-page="currentPage"
  407. :page-size="10"
  408. :page-sizes="[10, 20, 50, 100]"
  409. @size-change="handleSizeChange"
  410. layout="total, sizes, prev, pager, next, jumper"
  411. :total="total"
  412. >
  413. </el-pagination>
  414. </div>
  415. </div>
  416. </div>
  417. </section>
  418. </template>
  419. <script>
  420. import { CORE_API } from "@/constants/constants.js";
  421. import { ENABLE_TYPE, LEVEL_TYPE } from "../constants/constants.js";
  422. import { mapState } from "vuex";
  423. export default {
  424. name: "Course",
  425. data() {
  426. return {
  427. specialtyLoading4Search: false,
  428. specialtyList4Search: [],
  429. formSearch: {
  430. name: "",
  431. code: "",
  432. enable: "",
  433. level: "",
  434. specialtyId: ""
  435. },
  436. courseForm: {
  437. id: null,
  438. name: "",
  439. code: "",
  440. level: "ALL",
  441. enable: "true"
  442. },
  443. statusList: ENABLE_TYPE,
  444. levelList: LEVEL_TYPE,
  445. selectedCourseIds: [],
  446. tableData: [],
  447. currentPage: 1,
  448. pageSize: 10,
  449. total: 10,
  450. specialtyAllList: [],
  451. specialtyList: [],
  452. selectedSpecialtyList: [],
  453. specialtys: [],
  454. specialtyAll: [],
  455. impDialog: false,
  456. uploadAction: CORE_API + "/course/import",
  457. uploadHeaders: {},
  458. uploadData: {},
  459. errMessages: [],
  460. errDialog: false,
  461. fileLoading: false,
  462. fileList: [],
  463. courseDialog: false,
  464. relationDialog: false,
  465. rules: {
  466. name: [
  467. {
  468. required: true,
  469. message: "请输入课程名称",
  470. trigger: "blur"
  471. }
  472. ],
  473. code: [
  474. {
  475. required: true,
  476. message: "请输入课程代码",
  477. trigger: "blur"
  478. }
  479. ],
  480. level: [
  481. {
  482. required: true,
  483. message: "请选择层次",
  484. trigger: "change"
  485. }
  486. ],
  487. status: [
  488. {
  489. required: true,
  490. message: "请选择状态",
  491. trigger: "change"
  492. }
  493. ]
  494. },
  495. specialtyDialog: false,
  496. specialtyDialogTitle: null,
  497. specialtySearchForm: {
  498. courseId: null,
  499. code: null,
  500. name: null
  501. },
  502. specialtyTableData: [],
  503. currentSpecialtyPage: 1,
  504. specialtyPageSize: 10,
  505. specialtyTotal: 10,
  506. addRelationDialog: false,
  507. addRelationForm: {
  508. specialtyId: null,
  509. courseId: null
  510. },
  511. specialtyLoading4AddRelation: false,
  512. specialtyList4AddRelation: [],
  513. addRelationRules: {
  514. specialtyId: [
  515. {
  516. required: true,
  517. type: "number",
  518. message: "请选择专业",
  519. trigger: "change"
  520. }
  521. ]
  522. }
  523. };
  524. },
  525. computed: {
  526. ...mapState({
  527. user: state => state.user
  528. }),
  529. noBatchSelected() {
  530. return this.selectedCourseIds.length === 0;
  531. },
  532. courseIds() {
  533. var courseIds = "";
  534. for (let courseId of this.selectedCourseIds) {
  535. if (!courseIds) {
  536. courseIds += courseId;
  537. } else {
  538. courseIds += "," + courseId;
  539. }
  540. }
  541. return courseIds;
  542. },
  543. specialtyAllListSelect() {
  544. let specialtyList = [];
  545. for (let specialty of this.specialtyAllList) {
  546. let specialtyInfo = specialty.name + "(" + specialty.code + ")";
  547. specialtyList.push({ id: specialty.id, specialtyInfo: specialtyInfo });
  548. }
  549. return specialtyList;
  550. },
  551. getSpecialtyAllSelect4Search() {
  552. let specialtyList4Search = [];
  553. for (let specialty of this.specialtys) {
  554. let specialtyInfo = specialty.name + "(" + specialty.code + ")";
  555. specialtyList4Search.push({
  556. id: specialty.id,
  557. specialtyInfo: specialtyInfo
  558. });
  559. }
  560. return specialtyList4Search;
  561. },
  562. specialtyList4SearchWrapper() {
  563. var specialtyList = [];
  564. for (let course of this.specialtyList4Search) {
  565. var name = course.name + " - " + course.code;
  566. var id = course.id;
  567. specialtyList.push({ id: id, name: name });
  568. }
  569. return specialtyList;
  570. },
  571. specialtyList4AddRelationWrapper() {
  572. var specialtyList = [];
  573. for (let course of this.specialtyList4AddRelation) {
  574. var name = course.name + " - " + course.code;
  575. var id = course.id;
  576. specialtyList.push({ id: id, name: name });
  577. }
  578. return specialtyList;
  579. }
  580. },
  581. methods: {
  582. handleSizeChange(val) {
  583. this.pageSize = val;
  584. this.currentPage = 1;
  585. this.searchForm();
  586. },
  587. dialogBeforeClose() {
  588. this.$refs.courseForm.clearValidate();
  589. },
  590. deleteRelation(row) {
  591. var specialtyId = row.id;
  592. var courseId = this.specialtySearchForm.courseId;
  593. var param = new URLSearchParams({
  594. courseId: courseId,
  595. specialtyId: specialtyId
  596. });
  597. var url = CORE_API + "/courseSpeciatlyRelation/delete?" + param;
  598. this.$http
  599. .delete(url)
  600. .then(() => {
  601. this.$notify({
  602. type: "success",
  603. message: "取消关联成功!"
  604. });
  605. this.searchSpecialtyPage();
  606. })
  607. .catch(response => {
  608. if (response.status == 500) {
  609. this.$notify({
  610. showClose: true,
  611. message: response.data.desc,
  612. type: "error"
  613. });
  614. }
  615. });
  616. },
  617. submitAddRelationForm() {
  618. this.$refs.addRelationForm.validate(valid => {
  619. if (valid) {
  620. var param = new URLSearchParams(this.addRelationForm);
  621. var url = CORE_API + "/courseSpeciatlyRelation/add?" + param;
  622. this.$http.post(url, this.speciallyForm).then(
  623. () => {
  624. this.$notify({
  625. type: "success",
  626. message: "添加成功!"
  627. });
  628. this.searchSpecialtyPage();
  629. this.addRelationDialog = false;
  630. },
  631. response => {
  632. if (response.status == 500) {
  633. this.$notify({
  634. showClose: true,
  635. message: response.data.desc,
  636. type: "error"
  637. });
  638. }
  639. }
  640. );
  641. } else {
  642. console.log("error submit!");
  643. return false;
  644. }
  645. });
  646. },
  647. getSpecialtyList4AddRelation(query) {
  648. this.specialtyLoading4AddRelation = true;
  649. this.$http
  650. .get(CORE_API + "/specialty/query?name=" + query)
  651. .then(response => {
  652. this.specialtyList4AddRelation = response.data;
  653. this.specialtyLoading4AddRelation = false;
  654. });
  655. },
  656. addRelation() {
  657. this.addRelationForm.specialtyId = null;
  658. this.addRelationForm.courseId = this.specialtySearchForm.courseId;
  659. this.addRelationDialog = true;
  660. if (this.$refs.addRelationForm) {
  661. this.$refs.addRelationForm.resetFields();
  662. }
  663. },
  664. handleSpecialtyCurrentChange(val) {
  665. this.currentSpecialtyPage = val;
  666. this.searchSpecialtyPage();
  667. },
  668. searchSpecialtyPage() {
  669. var param = new URLSearchParams(this.specialtySearchForm);
  670. var url =
  671. CORE_API +
  672. "/specialty/specialtyPage/" +
  673. (this.currentPage - 1) +
  674. "/" +
  675. this.pageSize +
  676. "?" +
  677. param;
  678. this.$http.get(url).then(response => {
  679. this.specialtyTableData = response.data.content;
  680. this.specialtyTotal = response.data.totalElements;
  681. });
  682. },
  683. getEnable(enable) {
  684. if (enable == true) {
  685. return "启用";
  686. } else if (enable == false) {
  687. return "禁用";
  688. }
  689. return enable;
  690. },
  691. getTag(status) {
  692. if (status == true) {
  693. return "success";
  694. } else if (status == false) {
  695. return "danger";
  696. }
  697. return status;
  698. },
  699. getLevel(level) {
  700. if (level == "ZSB") {
  701. return "专升本";
  702. } else if (level == "GQZ") {
  703. return "高起专";
  704. } else if (level == "GQB") {
  705. return "高起本";
  706. } else {
  707. return "不限";
  708. }
  709. },
  710. getSpecialtyList4Search(query) {
  711. this.specialtyLoading4Search = true;
  712. this.$http
  713. .get(CORE_API + "/specialty/query?name=" + query)
  714. .then(response => {
  715. this.specialtyList4Search = response.data;
  716. this.specialtyLoading4Search = false;
  717. });
  718. },
  719. handleSearchBtn() {
  720. this.currentPage = 1;
  721. this.searchForm();
  722. },
  723. searchForm() {
  724. var param = new URLSearchParams(this.formSearch);
  725. var url =
  726. CORE_API +
  727. "/course/coursePage/" +
  728. (this.currentPage - 1) +
  729. "/" +
  730. this.pageSize +
  731. "?" +
  732. param;
  733. this.$http.get(url).then(response => {
  734. this.tableData = response.data.content;
  735. this.total = response.data.totalElements;
  736. });
  737. },
  738. handleCurrentChange(val) {
  739. this.currentPage = val;
  740. this.searchForm();
  741. },
  742. selectChange(row) {
  743. this.selectedCourseIds = [];
  744. row.forEach(element => {
  745. this.selectedCourseIds.push(element.id);
  746. });
  747. console.log(this.selectedCourseIds);
  748. },
  749. //新增
  750. insertCourse() {
  751. this.courseForm.id = null;
  752. this.courseForm.name = null;
  753. this.courseForm.code = null;
  754. this.courseForm.level = "ALL";
  755. this.courseForm.enable = "true";
  756. this.courseDialog = true;
  757. },
  758. //修改
  759. editCourse(row) {
  760. this.courseForm = Object.assign({}, row);
  761. this.courseForm.enable = row.enable ? "true" : "false";
  762. this.courseId = row.id;
  763. this.courseDialog = true;
  764. },
  765. exportCourse() {
  766. var param = new URLSearchParams(this.formSearch);
  767. window.open(
  768. CORE_API +
  769. "/course/export?$key=" +
  770. this.user.key +
  771. "&$token=" +
  772. this.user.token +
  773. "&" +
  774. param
  775. );
  776. },
  777. //关联课程
  778. relation(row) {
  779. this.specialtyDialogTitle =
  780. "关联专业列表 【课程名称:" +
  781. row.name +
  782. "】【 课程代码:" +
  783. row.code +
  784. "】";
  785. this.specialtySearchForm.courseId = row.id;
  786. this.specialtySearchForm.name = null;
  787. this.specialtySearchForm.code = null;
  788. this.searchSpecialtyPage();
  789. this.specialtyDialog = true;
  790. },
  791. closeCourse() {
  792. this.courseDialog = false;
  793. },
  794. saveRelation() {},
  795. //保存(新增/修改)
  796. submitForm() {
  797. var url = CORE_API + "/course";
  798. if (null != this.courseForm.id) {
  799. //修改
  800. this.$refs.courseForm.validate(valid => {
  801. if (valid) {
  802. this.$http.put(url, this.courseForm).then(
  803. () => {
  804. this.$notify({
  805. type: "success",
  806. message: "修改成功!"
  807. });
  808. this.searchForm();
  809. this.resetForm();
  810. this.courseDialog = false;
  811. },
  812. response => {
  813. if (response.status == 500) {
  814. this.$notify({
  815. showClose: true,
  816. message: response.data.desc,
  817. type: "error"
  818. });
  819. }
  820. }
  821. );
  822. } else {
  823. console.log("error submit!");
  824. return false;
  825. }
  826. });
  827. } else {
  828. this.$refs.courseForm.validate(valid => {
  829. if (valid) {
  830. this.$http.post(url, this.courseForm).then(
  831. () => {
  832. this.$notify({
  833. type: "success",
  834. message: "添加成功"
  835. });
  836. this.searchForm();
  837. this.resetForm();
  838. this.courseDialog = false;
  839. },
  840. response => {
  841. if (response.status == 500) {
  842. this.$notify({
  843. showClose: true,
  844. message: response.data.desc,
  845. type: "error"
  846. });
  847. }
  848. }
  849. );
  850. } else {
  851. console.log("error submit!");
  852. return false;
  853. }
  854. });
  855. }
  856. },
  857. //重置
  858. resetForm() {
  859. this.$refs.courseForm.resetFields();
  860. },
  861. resetPrimaryForm() {
  862. this.formSearch = {
  863. name: "",
  864. code: "",
  865. enable: "",
  866. level: "",
  867. specialtyId: ""
  868. };
  869. this.$refs.primaryForm.resetFields();
  870. },
  871. //删除单个数据
  872. deleteById(row) {
  873. this.$confirm("是否删除该课程?", "提示", {
  874. confirmButtonText: "确定",
  875. cancelButtonText: "取消",
  876. type: "warning"
  877. }).then(() => {
  878. var url = CORE_API + "/course/" + row.id;
  879. this.$http
  880. .delete(url)
  881. .then(() => {
  882. this.$notify({
  883. type: "success",
  884. message: "删除成功!"
  885. });
  886. this.searchForm();
  887. })
  888. .catch(response => {
  889. if (response.status == 500) {
  890. this.$notify({
  891. showClose: true,
  892. message: response.data.desc,
  893. type: "error"
  894. });
  895. }
  896. });
  897. });
  898. },
  899. //删除多条数据
  900. deleteByIds() {
  901. if (this.selectedCourseIds.length === 0) {
  902. this.$notify({
  903. type: "warning",
  904. message: "请选择要删除的课程"
  905. });
  906. } else {
  907. this.$confirm("是否删除这些课程?", "提示", {
  908. confirmButtonText: "确定",
  909. cancelButtonText: "取消",
  910. type: "error"
  911. }).then(() => {
  912. var url = CORE_API + "/course/" + this.courseIds;
  913. this.$http
  914. .delete(url)
  915. .then(() => {
  916. this.$notify({
  917. type: "success",
  918. message: "删除成功!"
  919. });
  920. this.searchForm();
  921. })
  922. .catch(response => {
  923. if (response.status == 500) {
  924. this.$notify({
  925. showClose: true,
  926. message: response.data.desc,
  927. type: "error"
  928. });
  929. }
  930. });
  931. });
  932. }
  933. },
  934. //启用
  935. enableByIds() {
  936. if (this.selectedCourseIds.length === 0) {
  937. this.$notify({
  938. type: "warning",
  939. message: "请选择要开启的课程"
  940. });
  941. } else {
  942. this.$confirm("是否启用这些课程?", "提示", {
  943. confirmButtonText: "确定",
  944. cancelButtonText: "取消",
  945. type: "warning"
  946. }).then(() => {
  947. var url = CORE_API + "/course/enable/" + this.courseIds;
  948. this.$http
  949. .put(url, {})
  950. .then(() => {
  951. this.$notify({
  952. type: "success",
  953. message: "开启成功!"
  954. });
  955. this.searchForm();
  956. })
  957. .catch(response => {
  958. if (response.status == 500) {
  959. this.$notify({
  960. showClose: true,
  961. message: response.data.desc,
  962. type: "error"
  963. });
  964. }
  965. });
  966. });
  967. }
  968. },
  969. enableById(row) {
  970. this.$confirm("是否启用该课程?", "提示", {
  971. confirmButtonText: "确定",
  972. cancelButtonText: "取消",
  973. type: "warning"
  974. }).then(() => {
  975. var url = CORE_API + "/course/enable/" + row.id;
  976. this.$http
  977. .put(url, {})
  978. .then(() => {
  979. this.$notify({
  980. type: "success",
  981. message: "开启成功!"
  982. });
  983. this.searchForm();
  984. })
  985. .catch(response => {
  986. if (response.status == 500) {
  987. this.$notify({
  988. showClose: true,
  989. message: response.data.desc,
  990. type: "error"
  991. });
  992. }
  993. });
  994. });
  995. },
  996. //禁用
  997. disableByIds() {
  998. if (this.selectedCourseIds.length === 0) {
  999. this.$notify({
  1000. type: "warning",
  1001. message: "请选择要禁用的课程"
  1002. });
  1003. } else {
  1004. this.$confirm("是否禁用这些课程?", "提示", {
  1005. confirmButtonText: "确定",
  1006. cancelButtonText: "取消",
  1007. type: "error"
  1008. }).then(() => {
  1009. var url = CORE_API + "/course/disable/" + this.courseIds;
  1010. this.$http
  1011. .put(url, {})
  1012. .then(() => {
  1013. this.$notify({
  1014. type: "success",
  1015. message: "禁用成功!"
  1016. });
  1017. this.searchForm();
  1018. })
  1019. .catch(response => {
  1020. if (response.status == 500) {
  1021. this.$notify({
  1022. showClose: true,
  1023. message: response.data.desc,
  1024. type: "error"
  1025. });
  1026. }
  1027. });
  1028. });
  1029. }
  1030. },
  1031. //禁用
  1032. disableById(row) {
  1033. this.$confirm("是否禁用该课程?", "提示", {
  1034. confirmButtonText: "确定",
  1035. cancelButtonText: "取消",
  1036. type: "error"
  1037. }).then(() => {
  1038. var url = CORE_API + "/course/disable/" + row.id;
  1039. this.$http
  1040. .put(url, {})
  1041. .then(() => {
  1042. this.$notify({
  1043. type: "success",
  1044. message: "禁用成功!"
  1045. });
  1046. this.searchForm();
  1047. })
  1048. .catch(response => {
  1049. if (response.status == 500) {
  1050. this.$notify({
  1051. showClose: true,
  1052. message: response.data.desc,
  1053. type: "error"
  1054. });
  1055. }
  1056. });
  1057. });
  1058. },
  1059. //导入
  1060. impCourse() {
  1061. this.impDialog = true;
  1062. this.initUpload();
  1063. },
  1064. initUpload() {
  1065. this.fileList = [];
  1066. },
  1067. beforeUpload(file) {
  1068. console.log(file);
  1069. },
  1070. uploadProgress() {
  1071. console.log("uploadProgress");
  1072. },
  1073. uploadSuccess(response) {
  1074. if (!response.hasError) {
  1075. this.$notify({
  1076. message: "上传成功",
  1077. type: "success"
  1078. });
  1079. this.fileLoading = false;
  1080. this.impDialog = false;
  1081. this.searchForm();
  1082. } else {
  1083. this.fileLoading = false;
  1084. this.impDialog = false;
  1085. this.errMessages = response.failRecords;
  1086. this.errDialog = true;
  1087. }
  1088. },
  1089. uploadError(response) {
  1090. var jsonStr = response.message.substring(4);
  1091. var resp = eval("(" + jsonStr + ")");
  1092. if (response.status == 500) {
  1093. this.$notify({
  1094. message: resp.desc,
  1095. type: "error"
  1096. });
  1097. }
  1098. this.fileLoading = false;
  1099. },
  1100. //确定上传
  1101. submitUpload() {
  1102. if (!this.checkUpload()) {
  1103. return false;
  1104. }
  1105. this.$refs.upload.submit();
  1106. this.fileLoading = true;
  1107. },
  1108. checkUpload() {
  1109. var fileList = this.$refs.upload.uploadFiles;
  1110. if (fileList.length == 0) {
  1111. this.$notify({
  1112. message: "上传文件不能为空",
  1113. type: "error"
  1114. });
  1115. return false;
  1116. }
  1117. if (fileList.length > 1) {
  1118. this.$notify({
  1119. message: "每次只能上传一个文件",
  1120. type: "error"
  1121. });
  1122. return false;
  1123. }
  1124. for (let file of fileList) {
  1125. if (!file.name.endsWith(".xlsx")) {
  1126. this.$notify({
  1127. message: "上传文件必须为xlsx格式",
  1128. type: "error"
  1129. });
  1130. this.initUpload();
  1131. return false;
  1132. }
  1133. }
  1134. return true;
  1135. },
  1136. //清空文件
  1137. removeFile() {
  1138. // this.fileList = [];
  1139. this.$refs.upload.clearFiles();
  1140. },
  1141. //下载模板
  1142. exportFile() {
  1143. window.location.href =
  1144. CORE_API +
  1145. "/course/importTemplate?$key=" +
  1146. this.user.key +
  1147. "&$token=" +
  1148. this.user.token;
  1149. }
  1150. },
  1151. //初始化查询
  1152. created() {
  1153. this.searchForm();
  1154. this.uploadHeaders = {
  1155. key: this.user.key,
  1156. token: this.user.token
  1157. };
  1158. }
  1159. };
  1160. </script>
  1161. <style scoped>
  1162. .input_width_lg {
  1163. width: 180px;
  1164. }
  1165. .pull_length {
  1166. width: 180px;
  1167. }
  1168. .pull-center {
  1169. margin-left: 30%;
  1170. }
  1171. </style>