course.vue 33 KB

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