course.vue 32 KB

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