CourseProperty.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. <template>
  2. <section class="content">
  3. <div v-show="isClear == 1">
  4. <LinkTitlesCustom :currentPaths="['基础信息', '课程属性预设']" />
  5. </div>
  6. <!-- 正文信息 -->
  7. <div class="box-body">
  8. <el-form
  9. :inline="true"
  10. :model="formSearch"
  11. label-position="right"
  12. label-width="70px"
  13. >
  14. <el-row>
  15. <el-col :span="6">
  16. <el-form-item label="属性名称">
  17. <el-input
  18. class="search_width"
  19. placeholder="请输入属性名称"
  20. v-model="formSearch.name"
  21. size="small"
  22. ></el-input>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="6">
  26. <el-form-item label="课程名称">
  27. <el-select
  28. class="search_width"
  29. v-model="formSearch.courseId"
  30. filterable
  31. :remote-method="getCourses"
  32. remote
  33. clearable
  34. placeholder="请选择"
  35. size="small"
  36. @focus="e => getCourses(e.target.value)"
  37. >
  38. <el-option
  39. v-for="item in courseInfoSelect"
  40. :label="item.courseInfo"
  41. :value="item.courseId"
  42. :key="item.courseId"
  43. >
  44. </el-option>
  45. </el-select>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="6">
  49. <div class="search_down">
  50. <el-button size="small" type="primary" @click="searchFrom"
  51. ><i class="el-icon-search"></i> 查询</el-button
  52. >
  53. <el-button size="small" type="primary" @click="addCourseProperty"
  54. ><i class="el-icon-plus"></i> 新增</el-button
  55. >
  56. </div>
  57. </el-col>
  58. </el-row>
  59. <div
  60. style="width: 100%; border-bottom: 1px solid #ddd; margin: 10px 0;"
  61. ></div>
  62. <el-row>
  63. <el-form-item class="pull-left">
  64. <span>批量操作:</span>
  65. <el-button
  66. size="small"
  67. type="success"
  68. @click="openCoursePropertys"
  69. :disabled="noBatchSelected"
  70. ><i class="el-icon-check"></i> 启用</el-button
  71. >
  72. <el-button
  73. size="small"
  74. type="danger"
  75. @click="closeCoursePropertys"
  76. :disabled="noBatchSelected"
  77. ><i class="el-icon-close"></i> 禁用</el-button
  78. >
  79. </el-form-item>
  80. </el-row>
  81. </el-form>
  82. <div style="width: 100%;margin-bottom: 10px;"></div>
  83. <!-- 页面列表 -->
  84. <el-table
  85. :data="tableData"
  86. v-loading="loading"
  87. element-loading-text="拼命加载中"
  88. border
  89. style="width:100%;"
  90. @selection-change="selectionChange"
  91. >
  92. <el-table-column type="selection" width="35"></el-table-column>
  93. <el-table-column label="课程名称">
  94. <template slot-scope="scope">
  95. <span>{{ scope.row.courseName }}</span>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="属性名称">
  99. <template slot-scope="scope">
  100. <span>{{ scope.row.name }}</span>
  101. </template>
  102. </el-table-column>
  103. <el-table-column label="状态">
  104. <template slot-scope="scope">
  105. <span v-if="scope.row.enable">
  106. <el-tooltip
  107. class="item"
  108. effect="dark"
  109. content="启用"
  110. placement="left"
  111. >
  112. <i class="el-icon-success" style="color:green;"></i>
  113. </el-tooltip>
  114. </span>
  115. <span v-else>
  116. <el-tooltip
  117. class="item"
  118. effect="dark"
  119. content="禁用"
  120. placement="left"
  121. >
  122. <i class="el-icon-error" style="color:red;"></i>
  123. </el-tooltip>
  124. </span>
  125. </template>
  126. </el-table-column>
  127. <el-table-column label="操作" width="260">
  128. <template slot-scope="scope">
  129. <div class="operate_left">
  130. <el-button
  131. size="mini"
  132. type="primary"
  133. @click="editCourseProperty(scope.row)"
  134. plain
  135. ><i class="el-icon-zoom-in"></i> 详情
  136. </el-button>
  137. <el-button
  138. v-if="!scope.row.enable"
  139. size="mini"
  140. type="primary"
  141. plain
  142. @click="openCourseProperty(scope.row)"
  143. >
  144. <i class="el-icon-check" aria-hidden="true"></i>启用
  145. </el-button>
  146. <el-button
  147. v-if="scope.row.enable"
  148. size="mini"
  149. type="danger"
  150. @click="closeCourseProperty(scope.row)"
  151. >
  152. <i class="el-icon-close" aria-hidden="true"></i>禁用
  153. </el-button>
  154. </div>
  155. </template>
  156. </el-table-column>
  157. </el-table>
  158. <div class="page pull-right">
  159. <el-pagination
  160. @current-change="handleCurrentChange"
  161. :current-page.sync="currentPage"
  162. :page-size="pageSize"
  163. :page-sizes="[10, 20, 50, 100]"
  164. @size-change="handleSizeChange"
  165. layout="total, sizes, prev, pager, next, jumper"
  166. :total="total"
  167. >
  168. </el-pagination>
  169. </div>
  170. </div>
  171. <el-dialog
  172. title="新增课程属性名称"
  173. :visible.sync="coursePropertyDialog"
  174. width="500px"
  175. >
  176. <el-form
  177. :model="coursePropertyForm"
  178. ref="coursePropertyForm"
  179. :rules="rules"
  180. label-position="right"
  181. label-width="90px"
  182. inline-message
  183. >
  184. <el-row>
  185. <el-form-item label="属性名称" label-width="120px" prop="name">
  186. <el-input
  187. class="dialog_input_width"
  188. v-model="coursePropertyForm.name"
  189. ></el-input>
  190. </el-form-item>
  191. </el-row>
  192. <el-row>
  193. <el-form-item label="课程名称" label-width="120px" prop="courseId">
  194. <el-select
  195. class="dialog_input_width"
  196. v-model="coursePropertyForm.courseId"
  197. filterable
  198. :remote-method="getCourses"
  199. remote
  200. clearable
  201. placeholder="请选择课程"
  202. >
  203. <el-option
  204. v-for="item in courseInfoSelect"
  205. :label="item.courseInfo"
  206. :value="item.courseId"
  207. :key="item.courseId"
  208. >
  209. </el-option>
  210. </el-select>
  211. </el-form-item>
  212. </el-row>
  213. <el-row class="margin_top_10 margin_left_120">
  214. <el-button type="primary" @click="submit('coursePropertyForm')"
  215. >保 存</el-button
  216. >
  217. <el-button @click="resetForm('coursePropertyForm')"
  218. ><i class="el-icon-refresh"></i> 重 置</el-button
  219. >
  220. <el-button @click="back('coursePropertyForm')" type="primary"
  221. ><i class="el-icon-arrow-left"></i> 返 回</el-button
  222. >
  223. </el-row>
  224. </el-form>
  225. </el-dialog>
  226. </section>
  227. </template>
  228. <script>
  229. import { CORE_API, QUESTION_API } from "@/constants/constants";
  230. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  231. export default {
  232. components: { LinkTitlesCustom },
  233. data() {
  234. return {
  235. formSearch: {
  236. name: "",
  237. courseId: ""
  238. },
  239. courseList: [],
  240. loading: false,
  241. tableData: [],
  242. currentPage: 1,
  243. pageSize: 10,
  244. total: 10,
  245. coursePropertyForm: {
  246. name: "",
  247. courseId: "",
  248. courseCode: ""
  249. },
  250. coursePropertyDialog: false,
  251. selectedList: [],
  252. rules: {
  253. name: [{ required: true, message: "请输入属性名称", trigger: "blur" }],
  254. courseId: [
  255. { required: true, message: "请选择课程名称", trigger: "change" }
  256. ]
  257. }
  258. };
  259. },
  260. methods: {
  261. //查询所有课程属性
  262. searchFrom() {
  263. this.currentPage = 1;
  264. this.searchCourProperty();
  265. },
  266. searchCourProperty() {
  267. var pageNo = Number(this.currentPage);
  268. this.loading = true;
  269. var url =
  270. QUESTION_API +
  271. "/courseProperty/all/" +
  272. this.currentPage +
  273. "/" +
  274. this.pageSize;
  275. this.$http.get(url, { params: this.formSearch }).then(response => {
  276. this.tableData = response.data.content;
  277. this.total = response.data.totalElements;
  278. this.currentPage = pageNo;
  279. this.loading = false;
  280. });
  281. },
  282. //新增
  283. addCourseProperty() {
  284. this.coursePropertyDialog = true;
  285. this.coursePropertyForm.name = "";
  286. this.coursePropertyForm.courseId = "";
  287. },
  288. //重置
  289. resetForm(formData) {
  290. this.coursePropertyForm.name = "";
  291. this.coursePropertyForm.courseId = "";
  292. this.$refs[formData].clearValidate();
  293. },
  294. //返回
  295. back(formData) {
  296. this.resetForm(formData);
  297. this.coursePropertyDialog = false;
  298. },
  299. //修改
  300. editCourseProperty(row) {
  301. sessionStorage.setItem("course_property_name", this.formSearch.name);
  302. sessionStorage.setItem(
  303. "course_property_courseId",
  304. this.formSearch.courseId
  305. );
  306. sessionStorage.setItem("course_property_currentPage", this.currentPage);
  307. sessionStorage.setItem("courseProperty", JSON.stringify(row));
  308. this.$router.push({
  309. path: "/questions/property_info/" + row.id
  310. });
  311. },
  312. //开启
  313. openCourseProperty(row) {
  314. this.$confirm("确认开启?", "提示", {
  315. type: "success"
  316. }).then(() => {
  317. this.loading = true;
  318. this.$http
  319. .put(QUESTION_API + "/courseProperty/open/" + row.id)
  320. .then(() => {
  321. this.$notify({
  322. message: "开启成功",
  323. type: "success"
  324. });
  325. this.searchCourProperty();
  326. })
  327. .catch(() => {
  328. this.$notify({
  329. type: "error",
  330. message: "开启失败"
  331. });
  332. });
  333. });
  334. },
  335. //批量启用
  336. openCoursePropertys() {
  337. this.$confirm("是否确认开启?", "提示", {
  338. confirmButtonText: "确定",
  339. cancelButtonText: "取消",
  340. type: "error"
  341. }).then(() => {
  342. this.loading = true;
  343. var url = QUESTION_API + "/courseProperty/opens/" + this.selectedIds;
  344. this.$http
  345. .put(url)
  346. .then(() => {
  347. this.$notify({
  348. type: "success",
  349. message: "开启成功!"
  350. });
  351. this.searchCourProperty();
  352. this.selectedList = [];
  353. })
  354. .catch(() => {
  355. this.$notify({
  356. type: "error",
  357. message: "开启失败!"
  358. });
  359. this.selectedList = [];
  360. });
  361. });
  362. this.loading = false;
  363. },
  364. //关闭
  365. closeCourseProperty(row) {
  366. this.$confirm("确认禁用?", "提示", {
  367. type: "warning"
  368. }).then(() => {
  369. this.loading = true;
  370. this.$http
  371. .put(QUESTION_API + "/courseProperty/close/" + row.id)
  372. .then(() => {
  373. this.$notify({
  374. message: "禁用成功",
  375. type: "success"
  376. });
  377. this.searchCourProperty();
  378. })
  379. .catch(() => {
  380. this.$notify({
  381. type: "error",
  382. message: "禁用失败"
  383. });
  384. });
  385. });
  386. },
  387. //批量关闭
  388. closeCoursePropertys() {
  389. this.$confirm("是否确认禁用?", "提示", {
  390. confirmButtonText: "确定",
  391. cancelButtonText: "取消",
  392. type: "error"
  393. }).then(() => {
  394. this.loading = true;
  395. var url = QUESTION_API + "/courseProperty/closes/" + this.selectedIds;
  396. this.$http
  397. .put(url)
  398. .then(() => {
  399. this.$notify({
  400. type: "success",
  401. message: "禁用成功!"
  402. });
  403. this.searchCourProperty();
  404. this.selectedList = [];
  405. })
  406. .catch(() => {
  407. this.$notify({
  408. type: "error",
  409. message: "禁用失败!"
  410. });
  411. this.selectedList = [];
  412. });
  413. });
  414. this.loading = false;
  415. },
  416. //分页
  417. handleCurrentChange(val) {
  418. console.log(`当前页: ${val}`);
  419. this.currentPage = val;
  420. this.searchCourProperty();
  421. },
  422. handleSizeChange(val) {
  423. this.pageSize = val;
  424. this.currentPage = 1;
  425. this.searchCourProperty();
  426. },
  427. //确定
  428. submit(formData) {
  429. this.$refs[formData].validate(valid => {
  430. if (valid) {
  431. for (let course of this.courseList) {
  432. if (course.id == this.coursePropertyForm.courseId) {
  433. this.coursePropertyForm.courseCode = course.code;
  434. }
  435. }
  436. this.$http
  437. .post(
  438. QUESTION_API + "/courseProperty/save",
  439. this.coursePropertyForm
  440. )
  441. .then(() => {
  442. this.$notify({
  443. message: "新增成功",
  444. type: "success"
  445. });
  446. this.coursePropertyDialog = false;
  447. this.searchCourProperty();
  448. })
  449. .catch(() => {
  450. this.$notify({
  451. type: "error",
  452. message: "课程属性名称重复,请重新命名"
  453. });
  454. });
  455. } else {
  456. return false;
  457. }
  458. });
  459. },
  460. //查询所有课程
  461. getCourses(query) {
  462. query = query.trim();
  463. this.courseLoading = true;
  464. this.$http
  465. .get(CORE_API + "/course/query?name=" + query + "&enable=true")
  466. .then(response => {
  467. this.courseList = response.data;
  468. this.courseLoading = false;
  469. });
  470. },
  471. removeItem() {
  472. sessionStorage.removeItem("course_property_name");
  473. sessionStorage.removeItem("course_property_courseId");
  474. sessionStorage.removeItem("course_property_currentPage");
  475. },
  476. //页面回填值
  477. initValue() {
  478. this.isClear = this.$route.params.isClear;
  479. if (this.isClear == 0 || !this.isClear) {
  480. this.removeItem();
  481. this.formSearch = {
  482. name: "",
  483. courseId: ""
  484. };
  485. } else {
  486. this.formSearch.name =
  487. sessionStorage.getItem("course_property_name") == "null"
  488. ? ""
  489. : sessionStorage.getItem("course_property_name");
  490. this.formSearch.courseId =
  491. sessionStorage.getItem("course_property_courseId") == ""
  492. ? ""
  493. : parseInt(sessionStorage.getItem("course_property_courseId"));
  494. this.currentPage =
  495. sessionStorage.getItem("course_property_currentPage") == null
  496. ? 1
  497. : parseInt(sessionStorage.getItem("course_property_currentPage"));
  498. }
  499. this.getOneCourse(this.formSearch.courseId);
  500. this.handleCurrentChange(this.currentPage);
  501. },
  502. //查询单个课程
  503. getOneCourse(courseId) {
  504. if (courseId) {
  505. this.$http.get(CORE_API + "/course/" + courseId).then(response => {
  506. this.courseList.push(response.data);
  507. });
  508. } else {
  509. this.courseList = [];
  510. }
  511. },
  512. //全选
  513. selectionChange(val) {
  514. this.selectedList = [];
  515. var selectedList = this.selectedList;
  516. val.forEach(element => {
  517. selectedList.push(element.id);
  518. });
  519. this.selectedList = selectedList;
  520. }
  521. },
  522. computed: {
  523. selectedIds() {
  524. var selectedIdsStr = "";
  525. for (let id of this.selectedList) {
  526. if (!selectedIdsStr) {
  527. selectedIdsStr += id;
  528. } else {
  529. selectedIdsStr += "," + id;
  530. }
  531. }
  532. return selectedIdsStr;
  533. },
  534. courseInfoSelect() {
  535. var courseList = [];
  536. for (var i = 0; i < this.courseList.length; i++) {
  537. var courseInfo = {
  538. courseInfo:
  539. this.courseList[i].name + "(" + this.courseList[i].code + ")",
  540. courseId: this.courseList[i].id
  541. };
  542. courseList.push(courseInfo);
  543. }
  544. return courseList;
  545. },
  546. noBatchSelected() {
  547. return this.selectedList.length === 0;
  548. }
  549. },
  550. watch: {
  551. $route: "initValue"
  552. },
  553. created() {
  554. this.initValue();
  555. }
  556. };
  557. </script>
  558. <style scoped src="../styles/Common.css"></style>