course.vue 34 KB

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