CourseProperty.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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. @focus="e => getCourses(e.target.value)"
  203. >
  204. <el-option
  205. v-for="item in courseInfoSelect"
  206. :label="item.courseInfo"
  207. :value="item.courseId"
  208. :key="item.courseId"
  209. >
  210. </el-option>
  211. </el-select>
  212. </el-form-item>
  213. </el-row>
  214. <el-row class="margin_top_10 margin_left_120">
  215. <el-button type="primary" @click="submit('coursePropertyForm')"
  216. >保 存</el-button
  217. >
  218. <el-button @click="resetForm('coursePropertyForm')"
  219. ><i class="el-icon-refresh"></i> 重 置</el-button
  220. >
  221. <el-button @click="back('coursePropertyForm')" type="primary"
  222. ><i class="el-icon-arrow-left"></i> 返 回</el-button
  223. >
  224. </el-row>
  225. </el-form>
  226. </el-dialog>
  227. </section>
  228. </template>
  229. <script>
  230. import { CORE_API, QUESTION_API } from "@/constants/constants";
  231. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  232. export default {
  233. components: { LinkTitlesCustom },
  234. data() {
  235. return {
  236. formSearch: {
  237. name: "",
  238. courseId: ""
  239. },
  240. courseList: [],
  241. loading: false,
  242. tableData: [],
  243. currentPage: 1,
  244. pageSize: 10,
  245. total: 10,
  246. coursePropertyForm: {
  247. name: "",
  248. courseId: "",
  249. courseCode: ""
  250. },
  251. coursePropertyDialog: false,
  252. selectedList: [],
  253. rules: {
  254. name: [{ required: true, message: "请输入属性名称", trigger: "blur" }],
  255. courseId: [
  256. { required: true, message: "请选择课程名称", trigger: "change" }
  257. ]
  258. }
  259. };
  260. },
  261. methods: {
  262. //查询所有课程属性
  263. searchFrom() {
  264. this.currentPage = 1;
  265. this.searchCourProperty();
  266. },
  267. searchCourProperty() {
  268. var pageNo = Number(this.currentPage);
  269. this.loading = true;
  270. var url =
  271. QUESTION_API +
  272. "/courseProperty/all/" +
  273. this.currentPage +
  274. "/" +
  275. this.pageSize;
  276. this.$http.get(url, { params: this.formSearch }).then(response => {
  277. this.tableData = response.data.content;
  278. this.total = response.data.totalElements;
  279. this.currentPage = pageNo;
  280. this.loading = false;
  281. });
  282. },
  283. //新增
  284. addCourseProperty() {
  285. this.coursePropertyDialog = true;
  286. this.coursePropertyForm.name = "";
  287. this.coursePropertyForm.courseId = "";
  288. },
  289. //重置
  290. resetForm(formData) {
  291. this.coursePropertyForm.name = "";
  292. this.coursePropertyForm.courseId = "";
  293. this.$refs[formData].clearValidate();
  294. },
  295. //返回
  296. back(formData) {
  297. this.resetForm(formData);
  298. this.coursePropertyDialog = false;
  299. },
  300. //修改
  301. editCourseProperty(row) {
  302. sessionStorage.setItem("course_property_name", this.formSearch.name);
  303. sessionStorage.setItem(
  304. "course_property_courseId",
  305. this.formSearch.courseId
  306. );
  307. sessionStorage.setItem("course_property_currentPage", this.currentPage);
  308. sessionStorage.setItem("courseProperty", JSON.stringify(row));
  309. this.$router.push({
  310. path: "/questions/property_info/" + row.id
  311. });
  312. },
  313. //开启
  314. openCourseProperty(row) {
  315. this.$confirm("确认开启?", "提示", {
  316. type: "success"
  317. }).then(() => {
  318. this.loading = true;
  319. this.$http
  320. .put(QUESTION_API + "/courseProperty/open/" + row.id)
  321. .then(() => {
  322. this.$notify({
  323. message: "开启成功",
  324. type: "success"
  325. });
  326. this.searchCourProperty();
  327. })
  328. .catch(() => {
  329. this.$notify({
  330. type: "error",
  331. message: "开启失败"
  332. });
  333. });
  334. });
  335. },
  336. //批量启用
  337. openCoursePropertys() {
  338. this.$confirm("是否确认开启?", "提示", {
  339. confirmButtonText: "确定",
  340. cancelButtonText: "取消",
  341. type: "error"
  342. }).then(() => {
  343. this.loading = true;
  344. var url = QUESTION_API + "/courseProperty/opens/" + this.selectedIds;
  345. this.$http
  346. .put(url)
  347. .then(() => {
  348. this.$notify({
  349. type: "success",
  350. message: "开启成功!"
  351. });
  352. this.searchCourProperty();
  353. this.selectedList = [];
  354. })
  355. .catch(() => {
  356. this.$notify({
  357. type: "error",
  358. message: "开启失败!"
  359. });
  360. this.selectedList = [];
  361. });
  362. });
  363. this.loading = false;
  364. },
  365. //关闭
  366. closeCourseProperty(row) {
  367. this.$confirm("确认禁用?", "提示", {
  368. type: "warning"
  369. }).then(() => {
  370. this.loading = true;
  371. this.$http
  372. .put(QUESTION_API + "/courseProperty/close/" + row.id)
  373. .then(() => {
  374. this.$notify({
  375. message: "禁用成功",
  376. type: "success"
  377. });
  378. this.searchCourProperty();
  379. })
  380. .catch(() => {
  381. this.$notify({
  382. type: "error",
  383. message: "禁用失败"
  384. });
  385. });
  386. });
  387. },
  388. //批量关闭
  389. closeCoursePropertys() {
  390. this.$confirm("是否确认禁用?", "提示", {
  391. confirmButtonText: "确定",
  392. cancelButtonText: "取消",
  393. type: "error"
  394. }).then(() => {
  395. this.loading = true;
  396. var url = QUESTION_API + "/courseProperty/closes/" + this.selectedIds;
  397. this.$http
  398. .put(url)
  399. .then(() => {
  400. this.$notify({
  401. type: "success",
  402. message: "禁用成功!"
  403. });
  404. this.searchCourProperty();
  405. this.selectedList = [];
  406. })
  407. .catch(() => {
  408. this.$notify({
  409. type: "error",
  410. message: "禁用失败!"
  411. });
  412. this.selectedList = [];
  413. });
  414. });
  415. this.loading = false;
  416. },
  417. //分页
  418. handleCurrentChange(val) {
  419. console.log(`当前页: ${val}`);
  420. this.currentPage = val;
  421. this.searchCourProperty();
  422. },
  423. handleSizeChange(val) {
  424. this.pageSize = val;
  425. this.currentPage = 1;
  426. this.searchCourProperty();
  427. },
  428. //确定
  429. submit(formData) {
  430. this.$refs[formData].validate(valid => {
  431. if (valid) {
  432. for (let course of this.courseList) {
  433. if (course.id == this.coursePropertyForm.courseId) {
  434. this.coursePropertyForm.courseCode = course.code;
  435. }
  436. }
  437. this.$http
  438. .post(
  439. QUESTION_API + "/courseProperty/save",
  440. this.coursePropertyForm
  441. )
  442. .then(() => {
  443. this.$notify({
  444. message: "新增成功",
  445. type: "success"
  446. });
  447. this.coursePropertyDialog = false;
  448. this.searchCourProperty();
  449. })
  450. .catch(() => {
  451. this.$notify({
  452. type: "error",
  453. message: "课程属性名称重复,请重新命名"
  454. });
  455. });
  456. } else {
  457. return false;
  458. }
  459. });
  460. },
  461. //查询所有课程
  462. getCourses(query) {
  463. query = query.trim();
  464. this.courseLoading = true;
  465. this.$http
  466. .get(CORE_API + "/course/query?name=" + query + "&enable=true")
  467. .then(response => {
  468. this.courseList = response.data;
  469. this.courseLoading = false;
  470. });
  471. },
  472. removeItem() {
  473. sessionStorage.removeItem("course_property_name");
  474. sessionStorage.removeItem("course_property_courseId");
  475. sessionStorage.removeItem("course_property_currentPage");
  476. },
  477. //页面回填值
  478. initValue() {
  479. this.isClear = this.$route.params.isClear;
  480. if (this.isClear == 0 || !this.isClear) {
  481. this.removeItem();
  482. this.formSearch = {
  483. name: "",
  484. courseId: ""
  485. };
  486. } else {
  487. this.formSearch.name =
  488. sessionStorage.getItem("course_property_name") == "null"
  489. ? ""
  490. : sessionStorage.getItem("course_property_name");
  491. this.formSearch.courseId =
  492. sessionStorage.getItem("course_property_courseId") == ""
  493. ? ""
  494. : parseInt(sessionStorage.getItem("course_property_courseId"));
  495. this.currentPage =
  496. sessionStorage.getItem("course_property_currentPage") == null
  497. ? 1
  498. : parseInt(sessionStorage.getItem("course_property_currentPage"));
  499. }
  500. this.getOneCourse(this.formSearch.courseId);
  501. this.handleCurrentChange(this.currentPage);
  502. },
  503. //查询单个课程
  504. getOneCourse(courseId) {
  505. if (courseId) {
  506. this.$http.get(CORE_API + "/course/" + courseId).then(response => {
  507. this.courseList.push(response.data);
  508. });
  509. } else {
  510. this.courseList = [];
  511. }
  512. },
  513. //全选
  514. selectionChange(val) {
  515. this.selectedList = [];
  516. var selectedList = this.selectedList;
  517. val.forEach(element => {
  518. selectedList.push(element.id);
  519. });
  520. this.selectedList = selectedList;
  521. }
  522. },
  523. computed: {
  524. selectedIds() {
  525. var selectedIdsStr = "";
  526. for (let id of this.selectedList) {
  527. if (!selectedIdsStr) {
  528. selectedIdsStr += id;
  529. } else {
  530. selectedIdsStr += "," + id;
  531. }
  532. }
  533. return selectedIdsStr;
  534. },
  535. courseInfoSelect() {
  536. var courseList = [];
  537. for (var i = 0; i < this.courseList.length; i++) {
  538. var courseInfo = {
  539. courseInfo:
  540. this.courseList[i].name + "(" + this.courseList[i].code + ")",
  541. courseId: this.courseList[i].id
  542. };
  543. courseList.push(courseInfo);
  544. }
  545. return courseList;
  546. },
  547. noBatchSelected() {
  548. return this.selectedList.length === 0;
  549. }
  550. },
  551. watch: {
  552. $route: "initValue"
  553. },
  554. created() {
  555. this.initValue();
  556. }
  557. };
  558. </script>
  559. <style scoped src="../styles/Common.css"></style>