InsertBluePaperStructure.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <template>
  2. <div id="insertBlueApp">
  3. <LinkTitlesCustom
  4. :current-paths="['基础信息 ', '蓝图结构预设', '蓝图结构创建']"
  5. />
  6. <section class="content">
  7. <!-- 正文信息 -->
  8. <div class="box-body">
  9. <el-form
  10. :inline="true"
  11. :model="blueStruct"
  12. label-position="right"
  13. label-width="78px"
  14. >
  15. <el-row>
  16. <el-col :span="8">
  17. <el-form-item label="结构名称">
  18. <el-input
  19. v-model="blueStruct.name"
  20. class="search_width"
  21. placeholder="试卷结构名称"
  22. size="small"
  23. ></el-input>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="8">
  27. <el-form-item label="设置类型">
  28. <el-select
  29. v-model="blueStruct.genPaperType"
  30. class="search_width"
  31. filterable
  32. disabled
  33. size="small"
  34. >
  35. <el-option label="细节组卷" value="SPECIFIC"> </el-option>
  36. </el-select>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="8">
  40. <el-form-item label="总 分">
  41. <el-input
  42. v-model.number="blueStruct.totalScore"
  43. class="search_width"
  44. placeholder="请输入总分"
  45. size="small"
  46. ></el-input>
  47. </el-form-item>
  48. </el-col>
  49. </el-row>
  50. <el-row>
  51. <el-col :span="8">
  52. <el-form-item label="制定课程">
  53. <el-select
  54. v-model="blueStruct.courseNo"
  55. class="search_width"
  56. :disabled="showcoursePropertyId"
  57. filterable
  58. :remote-method="getCourses"
  59. remote
  60. clearable
  61. placeholder="课程名称"
  62. size="small"
  63. @change="clearCourseProperty"
  64. @focus="(e) => getCourses(e.target.value)"
  65. >
  66. <el-option
  67. v-for="item in courseInfoSelect"
  68. :key="item.courseNo"
  69. :label="item.courseInfo"
  70. :value="item.courseNo"
  71. >
  72. </el-option>
  73. </el-select>
  74. </el-form-item>
  75. </el-col>
  76. <el-col :span="8">
  77. <el-form-item label="课程属性">
  78. <el-select
  79. v-model="blueStruct.coursePropertyId"
  80. class="search_width"
  81. filterable
  82. :disabled="showcoursePropertyId"
  83. placeholder="课程属性"
  84. size="small"
  85. @change="getCoursePropertyName"
  86. >
  87. <el-option
  88. v-for="item in coursePropertyList"
  89. :key="item.id"
  90. :label="item.name"
  91. :value="item.id"
  92. >
  93. </el-option>
  94. </el-select>
  95. </el-form-item>
  96. </el-col>
  97. </el-row>
  98. <el-form-item label="考试说明">
  99. <ckeditor
  100. v-model="blueStruct.examRemark"
  101. :display="display"
  102. :width="wValue"
  103. :height="hValue"
  104. ></ckeditor>
  105. </el-form-item>
  106. </el-form>
  107. <!-- 添加大题弹出框 -->
  108. <el-dialog title="大题信息" :visible.sync="detailDialog" width="500px">
  109. <el-form
  110. ref="paperDetailStructForm"
  111. :model="paperDetailStructForm"
  112. :rules="rules"
  113. label-position="right"
  114. label-width="90px"
  115. inline-message
  116. >
  117. <el-row>
  118. <el-form-item label="大题名称" label-width="120px" prop="name">
  119. <el-input
  120. v-model="paperDetailStructForm.name"
  121. class="dialog_input_width"
  122. placeholder="请输入题型名称"
  123. ></el-input>
  124. </el-form-item>
  125. </el-row>
  126. <el-row>
  127. <el-form-item label="题型描述" label-width="120px" prop="remark">
  128. <el-input
  129. v-model="paperDetailStructForm.remark"
  130. class="dialog_input_width"
  131. type="textarea"
  132. :rows="2"
  133. placeholder="请输入题型描述"
  134. ></el-input>
  135. </el-form-item>
  136. </el-row>
  137. <el-row class="margin_top_10 margin_left_120">
  138. <span v-if="dialogType == 'ADD'">
  139. <el-button
  140. type="primary"
  141. @click="saveDetail('paperDetailStructForm')"
  142. >保 存</el-button
  143. >
  144. </span>
  145. <span v-else>
  146. <el-button
  147. type="primary"
  148. @click="saveEditDetail('paperDetailStructForm')"
  149. >保 存</el-button
  150. >
  151. </span>
  152. <span class="margin_left_10">
  153. <el-button @click="resetForm('paperDetailStructForm')"
  154. ><i class="el-icon-refresh"></i> 重 置</el-button
  155. >
  156. </span>
  157. <span class="margin_left_10">
  158. <el-button
  159. type="primary"
  160. @click="closeDialog('paperDetailStructForm')"
  161. ><i class="el-icon-arrow-left"></i> 返 回</el-button
  162. >
  163. </span>
  164. </el-row>
  165. </el-form>
  166. </el-dialog>
  167. <!-- 页面列表 -->
  168. <div style="margin-top: 10px"></div>
  169. <el-table :data="paperDetailStructs" border style="width: 100%">
  170. <el-table-column label="大题名称">
  171. <template slot-scope="scope">
  172. <span>{{ scope.row.name }}</span>
  173. </template>
  174. </el-table-column>
  175. <el-table-column label="小题数">
  176. <template slot-scope="scope">
  177. <span>{{ scope.row.detailCount }}</span>
  178. </template>
  179. </el-table-column>
  180. <el-table-column label="大题分数">
  181. <template slot-scope="scope">
  182. <span>{{ scope.row.totalScore }}</span>
  183. </template>
  184. </el-table-column>
  185. <el-table-column label="题型">
  186. <template slot-scope="scope">
  187. <span>{{ getTpye(scope.row.questionType) }}</span>
  188. </template>
  189. </el-table-column>
  190. <el-table-column label="操作" width="292">
  191. <template slot-scope="scope">
  192. <div class="operate_left">
  193. <el-button
  194. size="mini"
  195. type="primary"
  196. @click="detailInfo(scope.row)"
  197. ><i class="el-icon-plus"></i> 大题详情</el-button
  198. >
  199. <el-button
  200. size="mini"
  201. type="primary"
  202. @click="editDetail(scope.row)"
  203. ><i class="el-icon-edit"></i>编辑</el-button
  204. >
  205. <el-button
  206. size="mini"
  207. type="danger"
  208. @click="deleteDetail(scope.row)"
  209. ><i class="el-icon-delete"></i> 删除</el-button
  210. >
  211. </div>
  212. </template>
  213. </el-table-column>
  214. </el-table>
  215. </div>
  216. <div class="search_down margin_top_10">
  217. <el-button size="small" type="primary" @click="saveBlueStruct"
  218. >保存试卷结构</el-button
  219. >
  220. <el-button size="small" type="primary" @click="insertDetail"
  221. ><i class="el-icon-plus"></i> 添加大题</el-button
  222. >
  223. <el-button size="small" type="primary" @click="back"
  224. ><i class="el-icon-arrow-left"></i> 返 回</el-button
  225. >
  226. </div>
  227. </section>
  228. </div>
  229. </template>
  230. <script>
  231. import { QUESTION_TYPES } from "../constants/constants";
  232. import { CORE_API, QUESTION_API } from "@/constants/constants";
  233. import ckeditor from "../component/ckeditor.vue";
  234. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  235. export default {
  236. name: "InsertBlueApp",
  237. components: {
  238. ckeditor,
  239. LinkTitlesCustom,
  240. },
  241. data() {
  242. return {
  243. hValue: "100px",
  244. wValue: "800px",
  245. display: "block",
  246. blueStruct: {
  247. name: "",
  248. totalScore: 0, //结构总分
  249. courseNo: "", //课程
  250. courseName: "",
  251. coursePropertyId: "", //课程属性
  252. coursePropertyName: "", //课程属性名称
  253. paperDetailStructs: [],
  254. type: "BLUEPRINT", //试卷结构类型
  255. genPaperType: "SPECIFIC", //组卷类型
  256. examRemark: "",
  257. },
  258. detailDialog: false,
  259. dialogType: "",
  260. paperDetailStructForm: {
  261. id: "",
  262. number: "",
  263. name: "", //大题名称
  264. questionType: "", //题型
  265. detailCount: 0, //小题总数
  266. score: 0, //每题分数
  267. totalScore: 0, //大题分数
  268. quesNames: [], //来源大题
  269. publicSimpleCount: 0, //公开简单
  270. publicMediumCount: 0, //公开中等
  271. publicDifficultyCount: 0, //公开困难
  272. noPublicSimpleCount: 0, //非公开简单
  273. noPublicMediumCount: 0, //非公开中等
  274. noPublicDifficultyCount: 0, //非公开困难
  275. courseProperties: [], //课程属性列表
  276. remark: "", //备注
  277. coursePropertyNumberDtos: [], //
  278. },
  279. quesTypes: QUESTION_TYPES,
  280. paperDetailStructs: [],
  281. courseList: [],
  282. loading: false,
  283. coursePropertyList: [],
  284. rules: {
  285. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  286. remark: [
  287. { required: true, message: "请输入题型描述", trigger: "blur" },
  288. ],
  289. },
  290. };
  291. },
  292. computed: {
  293. totalScore() {
  294. var sum = 0.0;
  295. for (let paperDetailStruct of this.paperDetailStructs) {
  296. sum += paperDetailStruct.score;
  297. }
  298. return sum;
  299. },
  300. courseInfoSelect() {
  301. var courseList = [];
  302. for (let course of this.courseList) {
  303. var courseInfo = course.name + "(" + course.code + ")";
  304. var courseNo = course.code;
  305. courseList.push({ courseNo: courseNo, courseInfo: courseInfo });
  306. }
  307. return courseList;
  308. },
  309. showcoursePropertyId() {
  310. if (this.blueStruct.paperDetailStructs.length > 0) {
  311. for (let paperDetailStruct of this.blueStruct.paperDetailStructs) {
  312. if (paperDetailStruct.detailCount > 0) {
  313. return true;
  314. }
  315. }
  316. }
  317. return false;
  318. },
  319. },
  320. created() {
  321. this.paperStructId = this.$route.params.id;
  322. this.searchForm();
  323. },
  324. methods: {
  325. //查询大题结合
  326. searchForm() {
  327. this.loading = true;
  328. var blueStructStorge = sessionStorage.getItem("blueStruct");
  329. if (typeof blueStructStorge == "string") {
  330. var blueStruct = JSON.parse(blueStructStorge);
  331. this.getCourses(blueStruct.courseName);
  332. this.blueStruct = blueStruct;
  333. this.$http
  334. .get(
  335. QUESTION_API + "/courseProperty/enable/" + this.blueStruct.courseNo
  336. )
  337. .then((response) => {
  338. this.coursePropertyList = response.data;
  339. if (this.coursePropertyList && this.coursePropertyList.length > 0) {
  340. for (let objCouPro of this.coursePropertyList) {
  341. if (objCouPro.id == this.blueStruct.coursePropertyId) {
  342. this.blueStruct.coursePropertyName = objCouPro.name;
  343. console.log("blueStruct", blueStruct);
  344. }
  345. }
  346. }
  347. });
  348. this.paperDetailStructs = blueStruct.paperDetailStructs;
  349. }
  350. this.loading = false;
  351. },
  352. getProperties() {
  353. for (var course of this.courseList) {
  354. if (this.blueStruct.courseNo == course.code) {
  355. var courseId = course.id;
  356. this.$http
  357. .get(QUESTION_API + "/courseProperty/all/" + courseId)
  358. .then((response) => {
  359. this.coursePropertyList = response.data;
  360. console.log("this.coursePropertyList:", this.coursePropertyList);
  361. });
  362. }
  363. }
  364. },
  365. //查询课程下的课程属性
  366. getCoursePropertyList() {
  367. this.$http
  368. .get(
  369. QUESTION_API + "/courseProperty/enable/" + this.blueStruct.courseNo
  370. )
  371. .then((response) => {
  372. this.coursePropertyList = response.data;
  373. console.log("this.coursePropertyList:", this.coursePropertyList);
  374. if (this.coursePropertyList && this.coursePropertyList.length == 0) {
  375. this.blueStruct.coursePropertyId = "";
  376. }
  377. });
  378. },
  379. checkPaperStruct() {
  380. if (!this.blueStruct.name) {
  381. this.$notify({
  382. message: "请填写试卷结构名称",
  383. type: "error",
  384. });
  385. return false;
  386. }
  387. let curPropertyId = this.blueStruct.coursePropertyId;
  388. if (!curPropertyId || curPropertyId.length < 1) {
  389. this.$notify({
  390. type: "error",
  391. message: "选择课程属性",
  392. });
  393. return false;
  394. }
  395. if (
  396. !(
  397. this.blueStruct.paperDetailStructs &&
  398. this.blueStruct.paperDetailStructs.length > 0
  399. )
  400. ) {
  401. this.$notify({
  402. message: "请添加大题",
  403. type: "error",
  404. });
  405. return false;
  406. }
  407. for (let paperDetailStruct of this.blueStruct.paperDetailStructs) {
  408. if (!(paperDetailStruct.detailCount > 0)) {
  409. this.$notify({
  410. message: "请添加大题下的小题数量",
  411. type: "error",
  412. });
  413. return false;
  414. }
  415. }
  416. return true;
  417. },
  418. //验证总分
  419. checkTotalScore() {
  420. var totalScore = 0;
  421. for (let paperDetailStruct of this.blueStruct.paperDetailStructs) {
  422. totalScore = parseFloat(paperDetailStruct.totalScore) + totalScore;
  423. }
  424. if (totalScore != this.blueStruct.totalScore) {
  425. return false;
  426. } else {
  427. return true;
  428. }
  429. },
  430. //保存试卷结构
  431. saveBlueStruct() {
  432. if (this.blueStruct.name.trim().length == 0) {
  433. this.$notify({
  434. type: "error",
  435. message: "结构名称不能为空格",
  436. });
  437. return false;
  438. }
  439. if (!this.checkPaperStruct()) {
  440. return false;
  441. }
  442. if (!this.checkTotalScore()) {
  443. this.$notify({
  444. type: "error",
  445. message: "试卷结构总分与大题总分不一致",
  446. });
  447. return false;
  448. }
  449. this.loading = true;
  450. var url = QUESTION_API + "/paperStruct";
  451. if (this.paperStructId != "add") {
  452. //假如没ID就是新增
  453. this.$http
  454. .put(url, this.blueStruct)
  455. .then(() => {
  456. this.$notify({
  457. message: "保存成功",
  458. type: "success",
  459. });
  460. this.loading = false;
  461. this.removeItem();
  462. this.back();
  463. })
  464. .catch(() => {
  465. this.$notify({
  466. type: "error",
  467. message: "试卷结构名称重复,请重新命名",
  468. });
  469. this.loading = false;
  470. });
  471. } else {
  472. this.$http
  473. .post(url, this.blueStruct)
  474. .then(() => {
  475. this.$notify({
  476. message: "保存成功",
  477. type: "success",
  478. });
  479. this.loading = false;
  480. this.removeItem();
  481. this.back();
  482. })
  483. .catch(() => {
  484. this.loading = false;
  485. this.$notify({
  486. type: "error",
  487. message: "试卷结构名称重复,请重新命名",
  488. });
  489. });
  490. }
  491. },
  492. //添加大题
  493. insertDetail() {
  494. this.dialogType = "ADD";
  495. this.paperDetailStructForm.name = "";
  496. this.paperDetailStructForm.remark = "";
  497. this.detailDialog = true;
  498. },
  499. //保存新增大题
  500. saveDetail(formData) {
  501. this.$refs[formData].validate((valid) => {
  502. if (valid) {
  503. //定义一个id的集合,用来id自加
  504. var ids = [];
  505. for (let paperDetailStruct of this.paperDetailStructs) {
  506. ids.push(paperDetailStruct.id);
  507. }
  508. ids.sort();
  509. var maxId;
  510. if (ids.length == 0) {
  511. maxId = 0;
  512. } else {
  513. maxId = ids[ids.length - 1];
  514. }
  515. var paperDetailStruct = Object.assign({}, this.paperDetailStructForm);
  516. paperDetailStruct.id = maxId + 1;
  517. paperDetailStruct.number = this.paperDetailStructs.length + 1;
  518. this.paperDetailStructs.push(paperDetailStruct);
  519. this.detailDialog = false;
  520. this.blueStruct.paperDetailStructs = this.paperDetailStructs;
  521. sessionStorage.setItem("blueStruct", JSON.stringify(this.blueStruct));
  522. } else {
  523. return false;
  524. }
  525. });
  526. },
  527. //删除大题
  528. deleteDetail(row) {
  529. for (var i = 0; i < this.paperDetailStructs.length; i++) {
  530. if (row.id === this.paperDetailStructs[i].id) {
  531. this.paperDetailStructs.splice(i, 1);
  532. }
  533. }
  534. this.blueStruct.paperDetailStructs = this.paperDetailStructs;
  535. sessionStorage.setItem("blueStruct", JSON.stringify(this.blueStruct));
  536. },
  537. //修改大题
  538. editDetail(row) {
  539. this.dialogType = "EDIT";
  540. for (let paperDetailStruct of this.paperDetailStructs) {
  541. if (row.id === paperDetailStruct.id) {
  542. this.paperDetailStructForm.name = paperDetailStruct.name;
  543. this.paperDetailStructForm.remark = paperDetailStruct.remark;
  544. this.paperDetailStructForm.id = row.id;
  545. }
  546. }
  547. this.detailDialog = true;
  548. },
  549. //保存修改大题
  550. saveEditDetail(formData) {
  551. this.$refs[formData].validate((valid) => {
  552. if (valid) {
  553. for (let paperDetailStruct of this.paperDetailStructs) {
  554. if (this.paperDetailStructForm.id === paperDetailStruct.id) {
  555. console.log("paperDetailStruct", paperDetailStruct);
  556. paperDetailStruct.name = this.paperDetailStructForm.name;
  557. paperDetailStruct.remark = this.paperDetailStructForm.remark;
  558. }
  559. }
  560. this.paperDetailStructForm = { name: "", remark: "", id: "" };
  561. this.blueStruct.paperDetailStructs = this.paperDetailStructs;
  562. sessionStorage.setItem("blueStruct", JSON.stringify(this.blueStruct));
  563. this.detailDialog = false;
  564. }
  565. });
  566. },
  567. //返回
  568. back() {
  569. this.$router.push({
  570. path: "/questions/blue_paper_structure/1",
  571. });
  572. },
  573. //关闭窗口
  574. closeDialog(formData) {
  575. this.resetForm(formData);
  576. this.detailDialog = false;
  577. },
  578. //得到题型
  579. getTpye(val) {
  580. //console.log(val);
  581. for (var ques of this.quesTypes) {
  582. if (val === ques.value) {
  583. return ques.label;
  584. }
  585. }
  586. },
  587. getCourseName(courseNo) {
  588. for (let course of this.courseList) {
  589. if (course.code == courseNo) {
  590. this.blueStruct.courseName = course.name;
  591. }
  592. }
  593. },
  594. //大题详情
  595. detailInfo(row) {
  596. if (!this.blueStruct.coursePropertyId) {
  597. this.$notify({
  598. type: "error",
  599. message: "请选择课程属性",
  600. });
  601. return false;
  602. }
  603. this.getCourseName(this.blueStruct.courseNo);
  604. sessionStorage.setItem("blueStruct", JSON.stringify(this.blueStruct));
  605. this.$router.push({
  606. path:
  607. "/questions/insert_blue_paper_structure_info/" +
  608. row.id +
  609. "/" +
  610. this.paperStructId,
  611. });
  612. },
  613. //清空
  614. removeItem() {
  615. sessionStorage.removeItem("blueStruct");
  616. },
  617. getCoursePropertyName() {
  618. if (this.blueStruct.coursePropertyId) {
  619. for (let objCouPro of this.coursePropertyList) {
  620. if (objCouPro.id == this.blueStruct.coursePropertyId) {
  621. this.blueStruct.coursePropertyName = objCouPro.name;
  622. }
  623. }
  624. } else {
  625. this.blueStruct.coursePropertyName = "";
  626. }
  627. },
  628. //查询所有课程
  629. getCourses(query) {
  630. query = query.trim();
  631. this.courseLoading = true;
  632. this.$http
  633. .get(CORE_API + "/course/query?name=" + query + "&enable=true")
  634. .then((response) => {
  635. this.courseList = response.data;
  636. this.courseLoading = false;
  637. if (this.blueStruct.courseNo) {
  638. this.getCoursePropertyList();
  639. }
  640. });
  641. },
  642. clearCourseProperty() {
  643. this.blueStruct.coursePropertyId = "";
  644. this.coursePropertyList = [];
  645. this.getCoursePropertyList();
  646. },
  647. resetForm(formData) {
  648. this.paperDetailStructForm.name = "";
  649. this.paperDetailStructForm.remark = "";
  650. this.$refs[formData].clearValidate();
  651. },
  652. },
  653. };
  654. </script>
  655. <style scoped src="../styles/Common.css"></style>