InsertBluePaperStructure.vue 19 KB

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