CourseProperty.vue 16 KB

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