course.vue 34 KB

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