CourseProperty.vue 16 KB

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