course.vue 36 KB

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