course.vue 33 KB

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