Course.vue 34 KB

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