AddPaperSelect.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <template>
  2. <div class="content add-paper-select">
  3. <div>
  4. <LinkTitlesCustom
  5. :current-paths="['题库管理 ', '卷库管理', '抽题模板管理']"
  6. />
  7. </div>
  8. <div class="box-body">
  9. <div class="top">
  10. <div class="flex items-center">
  11. <p>课程名称:{{ $route.query.courseName }}</p>
  12. <p style="margin-left: 100px">
  13. 课程代码:{{ $route.query.courseNo }}
  14. </p>
  15. </div>
  16. <div>
  17. <el-button type="primary" size="small" @click="save">保存</el-button>
  18. <el-button type="primary" size="small" plain @click="back"
  19. >返回</el-button
  20. >
  21. </div>
  22. </div>
  23. <div class="form">
  24. <el-form
  25. ref="form"
  26. :rules="rules"
  27. :model="form"
  28. label-position="left"
  29. label-width="120px"
  30. >
  31. <el-form-item label="组卷模板名称:" prop="name">
  32. <el-input v-model="form.name" style="width: 300px"></el-input>
  33. </el-form-item>
  34. <el-form-item label="选择组卷模式:" required>
  35. <el-radio-group
  36. v-model="form.paperStructType"
  37. @change="paperStructTypeChange"
  38. >
  39. <el-radio label="EXACT">精确结构</el-radio>
  40. <el-radio label="BLUEPRINT">蓝图结构</el-radio>
  41. </el-radio-group>
  42. </el-form-item>
  43. <el-form-item label="选择组卷结构:" prop="paperStructId">
  44. <el-select v-model="form.paperStructId">
  45. <el-option
  46. v-for="item in options1"
  47. :key="item.id"
  48. :label="item.name"
  49. :value="item.id"
  50. ></el-option>
  51. </el-select>
  52. <p style="display: inline-block; margin-left: 40px">
  53. 难度:<span style="color: #409eff; font-weight: bold">{{
  54. difficultyDegree
  55. }}</span>
  56. </p>
  57. </el-form-item>
  58. <el-table
  59. v-loading="tableLoading1"
  60. :data="tableData1"
  61. border
  62. style="margin-top: 10px; margin-bottom: 20px; width: 700px"
  63. >
  64. <el-table-column
  65. v-for="(item, index) in tableColumns1"
  66. :key="index"
  67. :label="item.label"
  68. :prop="item.prop"
  69. :min-width="item.minWidth"
  70. >
  71. <template slot-scope="scope">
  72. <span
  73. v-if="
  74. !['hardInfo', 'mediumInfo', 'easyInfo'].includes(item.prop)
  75. "
  76. >{{ scope.row[item.prop] }}</span
  77. >
  78. <span v-else>{{ scope.row[item.prop]?.count }}</span>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <div class="flex" style="margin-top: 30px">
  83. <div style="width: 40%">
  84. <el-form-item label="选择题源范围:" style="margin-bottom: 0">
  85. <el-select
  86. v-model="form.paperType"
  87. placeholder="题源选择"
  88. style="width: 120px"
  89. @change="changePaperType"
  90. >
  91. <el-option label="题库来源" value="IMPORT"></el-option>
  92. <el-option label="卷库来源" value="GENERATE"></el-option>
  93. </el-select>
  94. <span
  95. v-if="checked && !tempPapers.length"
  96. class="red"
  97. style="font-size: 12px; font-weight: bold; margin-left: 10px"
  98. >请选择数据</span
  99. >
  100. </el-form-item>
  101. <el-table
  102. ref="table2"
  103. v-loading="tableLoading2"
  104. :data="tableData2"
  105. border
  106. @selection-change="handleSelectionChange"
  107. >
  108. <el-table-column
  109. type="selection"
  110. width="55"
  111. :selectable="canSelect"
  112. >
  113. </el-table-column>
  114. <el-table-column
  115. v-for="(item, index) in tableColumns2"
  116. :key="index"
  117. :label="item.label"
  118. :prop="item.prop"
  119. :width="item.width"
  120. >
  121. </el-table-column>
  122. </el-table>
  123. <div class="page pull-right">
  124. <el-pagination
  125. :current-page="curSelect"
  126. :page-size="pageSize"
  127. layout="total, prev, pager, next, jumper"
  128. :total="totalSelect"
  129. @current-change="selectCurrentChange"
  130. >
  131. </el-pagination>
  132. </div>
  133. <div style="clear: both; margin-top: 5px"></div>
  134. <el-form
  135. :inline="true"
  136. label-position="right"
  137. label-width="100px"
  138. >
  139. <el-form-item label="选中列表" class="form-item"></el-form-item>
  140. </el-form>
  141. <el-table :data="tempPapers" border>
  142. <el-table-column label="名称" width="200">
  143. <template slot-scope="scope">
  144. <div>
  145. <span>{{ scope.row.name }}</span>
  146. </div>
  147. </template>
  148. </el-table-column>
  149. <el-table-column label="操作">
  150. <template slot-scope="scope">
  151. <div>
  152. <el-button
  153. type="danger"
  154. size="mini"
  155. @click="removeSelected(scope.row.id)"
  156. >移除</el-button
  157. >
  158. </div>
  159. </template>
  160. </el-table-column>
  161. </el-table>
  162. </div>
  163. <div style="width: 60%; padding-left: 20px">
  164. <div style="color: #606266; font-size: 14px; line-height: 32px">
  165. <span>选中范围预览:</span>
  166. <span
  167. v-if="hasError"
  168. class="red"
  169. style="font-size: 12px; font-weight: bold"
  170. >不满足最低要求</span
  171. >
  172. </div>
  173. <el-table
  174. v-loading="tableLoading3"
  175. :data="tableData3"
  176. border
  177. style="margin-top: 8px"
  178. >
  179. <el-table-column
  180. v-for="(item, index) in tableColumns3"
  181. :key="index"
  182. :label="item.label"
  183. :prop="item.prop"
  184. >
  185. <template slot-scope="scope">
  186. <div
  187. v-if="
  188. ['hardInfo', 'mediumInfo', 'easyInfo'].includes(
  189. item.prop
  190. )
  191. "
  192. >
  193. <el-tooltip
  194. v-if="!scope.row[item.prop].valid"
  195. effect="dark"
  196. :content="scope.row[item.prop].invalidMsg"
  197. placement="top"
  198. >
  199. <span class="red">{{
  200. scope.row[item.prop]?.count
  201. }}</span>
  202. </el-tooltip>
  203. <span v-else>{{ scope.row[item.prop]?.count }}</span>
  204. </div>
  205. <div v-else>
  206. <span
  207. v-if="
  208. item.prop === 'totalCount' && hasNumError(scope.row)
  209. "
  210. style="color: #f56c6c; font-weight: bold"
  211. >{{ scope.row[item.prop] }}</span
  212. >
  213. <span v-else>{{ scope.row[item.prop] }}</span>
  214. </div>
  215. </template>
  216. </el-table-column>
  217. </el-table>
  218. </div>
  219. </div>
  220. </el-form>
  221. </div>
  222. </div>
  223. </div>
  224. </template>
  225. <script>
  226. import qs from "qs";
  227. import { cloneDeep } from "lodash";
  228. import { mapState } from "vuex";
  229. import { QUESTION_API } from "@/constants/constants";
  230. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  231. export default {
  232. name: "AddPaperSelect",
  233. components: { LinkTitlesCustom },
  234. data() {
  235. return {
  236. tempPapers: [],
  237. tempPaperIds: [],
  238. curSelect: 1,
  239. totalSelect: 10,
  240. pageSize: 10,
  241. hasError: false,
  242. form: {
  243. paperStructType: "EXACT",
  244. name: "",
  245. paperStructId: "",
  246. paperType: "IMPORT",
  247. paperIds: "",
  248. },
  249. paperIdsArr: [],
  250. options1: [],
  251. tableData1: [],
  252. difficultyDegree: "",
  253. tableColumns1: [
  254. { label: "题型", prop: "detailName", minWidth: "100" },
  255. { label: "总分", prop: "totalScore", minWidth: "80" },
  256. { label: "数量", prop: "totalCount", minWidth: "80" },
  257. { label: "难", prop: "hardInfo", minWidth: "80" },
  258. { label: "中", prop: "mediumInfo", minWidth: "80" },
  259. { label: "易", prop: "easyInfo", minWidth: "80" },
  260. ],
  261. tableData2: [],
  262. tableColumns2: [
  263. { label: "名称", prop: "name" },
  264. { label: "小题数量", prop: "unitCount", width: "100px" },
  265. ],
  266. multipleSelection: [],
  267. tableData3: [],
  268. tableColumns3: [
  269. { label: "题型", prop: "detailName", minWidth: "100" },
  270. { label: "数量", prop: "totalCount", minWidth: "80" },
  271. { label: "难", prop: "hardInfo", minWidth: "80" },
  272. { label: "中", prop: "mediumInfo", minWidth: "80" },
  273. { label: "易", prop: "easyInfo", minWidth: "80" },
  274. ],
  275. lastRequestKey: "",
  276. tableLoading3: false,
  277. tableLoading1: false,
  278. tableLoading2: false,
  279. checked: false,
  280. initSelectedRows: [],
  281. isEditInitPage: false,
  282. };
  283. },
  284. computed: {
  285. ...mapState({ user: (state) => state.user }),
  286. curStruct() {
  287. if (this.form.paperStructId) {
  288. return this.options1.find(
  289. (item) => item.id === this.form.paperStructId
  290. );
  291. } else {
  292. return {};
  293. }
  294. },
  295. rules() {
  296. return {
  297. name: { required: true, message: "请输入模板名称", trigger: "change" },
  298. paperStructId: {
  299. required: true,
  300. message: "请选择组卷结构",
  301. trigger: "change",
  302. },
  303. };
  304. },
  305. },
  306. watch: {
  307. "form.paperStructId"() {
  308. this.structChange();
  309. this.changePaperType(true);
  310. },
  311. // "form.paperStructType"() {
  312. // this.form.paperStructId = "";
  313. // this.getStruct();
  314. // this.tableData1 = [];
  315. // this.$refs.table2.clearSelection();
  316. // },
  317. multipleSelection(val) {
  318. this.form.paperIds = val.map((item) => item.id).join(",");
  319. },
  320. },
  321. async created() {
  322. let res = await this.getTplData();
  323. if (res) {
  324. this.getStruct();
  325. // this.getTable2(true);
  326. }
  327. },
  328. methods: {
  329. selectCurrentChange(val) {
  330. this.curSelect = val;
  331. this.getTable2();
  332. },
  333. paperStructTypeChange() {
  334. this.form.paperStructId = "";
  335. this.getStruct();
  336. this.tableData1 = [];
  337. this.difficultyDegree = "";
  338. this.$refs.table2.clearSelection();
  339. },
  340. async getTplData() {
  341. const { id } = this.$route.params;
  342. if (id) {
  343. try {
  344. const data = await this.$http.post(
  345. "/api/ecs_ques/randompaper/info",
  346. null,
  347. {
  348. params: {
  349. id,
  350. },
  351. }
  352. );
  353. const tplData = data.data;
  354. this.tempPaperIds = tplData.paperIds || [];
  355. this.tempPapers = tplData.papers || [];
  356. this.isEditInitPage = true;
  357. Object.assign(this.form, tplData || {}, {
  358. paperIds: (tplData.paperIds || []).join(","),
  359. });
  360. this.getTable2();
  361. this.getTable3();
  362. return true;
  363. } catch (e) {
  364. return false;
  365. }
  366. } else {
  367. return true;
  368. }
  369. },
  370. back() {
  371. if (this.$route.params?.id) {
  372. this.$router.push("/questions/extract_paper_template");
  373. } else {
  374. this.$router.push("/questions/gen_paper/0");
  375. }
  376. },
  377. save() {
  378. this.checked = true;
  379. let paperIds = this.tempPaperIds.join(",");
  380. this.$refs.form.validate((valid) => {
  381. if (valid) {
  382. if (this.tempPaperIds.length && !this.hasError) {
  383. let params = {
  384. courseId: this.$route.query.courseId,
  385. ...this.form,
  386. rootOrgId: this.user.rootOrgId,
  387. paperIds,
  388. };
  389. if (this.$route.params.id) {
  390. params.id = this.$route.params.id;
  391. }
  392. this.$http
  393. .post("/api/ecs_ques/randompaper/save", qs.stringify(params))
  394. .then(() => {
  395. this.$message.success("保存成功");
  396. // this.$router.back();
  397. this.$router.push("/questions/extract_paper_template");
  398. })
  399. .catch((err) => {
  400. if (
  401. err.response &&
  402. err.response.data &&
  403. err.response.data.desc
  404. ) {
  405. this.$message.error(err.response.data.desc);
  406. }
  407. });
  408. }
  409. } else {
  410. console.log("error submit!!");
  411. return false;
  412. }
  413. });
  414. },
  415. canSelect() {
  416. return !!this.form.paperStructId;
  417. },
  418. structChange() {
  419. if (!this.form.paperStructId) {
  420. return;
  421. }
  422. this.tableLoading1 = true;
  423. this.$http
  424. .post("/api/ecs_ques/randompaper/struct/question/info", null, {
  425. params: { structId: this.form.paperStructId },
  426. headers: { "content-type": "application/x-www-form-urlencoded" },
  427. })
  428. .then((res) => {
  429. this.tableData1 = res.data.structQuestionInfo || [];
  430. this.difficultyDegree = res.data.difficultyDegree;
  431. this.tableLoading1 = false;
  432. });
  433. },
  434. getStruct() {
  435. var courseNo = this.$route.query.courseNo;
  436. var url =
  437. QUESTION_API +
  438. "/paperStruct?courseNo=" +
  439. courseNo +
  440. "&type=" +
  441. this.form.paperStructType;
  442. this.loading = true;
  443. this.$http.get(url).then((response) => {
  444. this.options1 = response.data;
  445. this.loading = false;
  446. });
  447. },
  448. getTable2() {
  449. this.tableLoading2 = true;
  450. let apiUrl =
  451. this.form.paperType === "IMPORT"
  452. ? "/api/ecs_ques/importPaper/huoge"
  453. : "/api/ecs_ques/genPaper/huoge";
  454. this.$http
  455. .get(
  456. apiUrl +
  457. `/${this.curSelect}/${this.pageSize}?courseNo=${this.$route.query.courseNo}&ids=${this.tempPaperIds}`,
  458. {
  459. // params: {
  460. // courseNo: this.$route.query.courseNo,
  461. // ids: this.tempPaperIds,
  462. // },
  463. }
  464. )
  465. .then((res) => {
  466. this.tableData2 = res.data.content || [];
  467. this.totalSelect = res.data.totalElements;
  468. // this.curSelect = res.data.number + 1;
  469. // if (bool) {
  470. // this.tableData2.forEach((item) => {
  471. // if (this.paperIdsArr.includes(item.id)) {
  472. // this.initSelectedRows.push(item);
  473. // }
  474. // });
  475. // setTimeout(() => {
  476. // this.initSelectedRows.forEach((item) => {
  477. // this.$refs.table2.toggleRowSelection(item, true);
  478. // });
  479. // }, 0);
  480. // }
  481. this.tableLoading2 = false;
  482. });
  483. },
  484. removeSelected(id) {
  485. for (let [index, paper] of this.tempPapers.entries()) {
  486. if (id == paper.id) {
  487. this.tempPapers.splice(index, 1);
  488. this.tableData2.push(paper);
  489. break;
  490. }
  491. }
  492. for (var i = 0; i < this.tempPaperIds.length; i++) {
  493. if (this.tempPaperIds[i] == id) {
  494. this.tempPaperIds.splice(i, 1);
  495. break;
  496. }
  497. }
  498. this.getTable2();
  499. this.getTable3();
  500. },
  501. changePaperType() {
  502. console.log("changePaperType");
  503. if (!this.isEditInitPage) {
  504. this.tempPapers = [];
  505. this.tempPaperIds = [];
  506. this.tableData2 = [];
  507. this.tableData3 = [];
  508. this.multipleSelection = [];
  509. this.curSelect = 1;
  510. this.getTable2();
  511. } else {
  512. this.isEditInitPage = false;
  513. }
  514. // if (bool === true) {
  515. // // this.handleSelectionChange([]);
  516. // this.tempPapers = [];
  517. // this.tempPaperIds = [];
  518. // // this.$refs.table2.clearSelection();
  519. // this.getTable3();
  520. // } else {
  521. // this.tableData2 = [];
  522. // this.tempPapers = [];
  523. // this.tempPaperIds = [];
  524. // this.multipleSelection = [];
  525. // this.curSelect = 1;
  526. // this.getTable2();
  527. // }
  528. },
  529. getTable3() {
  530. // let paperIds = this.multipleSelection.map((item) => item.id);
  531. // if (!paperIds.length) {
  532. if (!this.tempPaperIds.length) {
  533. this.tableData3 = [];
  534. this.tableLoading3 = false;
  535. return false;
  536. }
  537. this.tableLoading3 = true;
  538. let str = new Date().getTime() + "";
  539. this.lastRequestKey = str;
  540. this.$http
  541. .post(
  542. "/api/ecs_ques/randompaper/struct/question/view/info",
  543. qs.stringify({
  544. paperIds: this.tempPaperIds.join(","),
  545. structId: this.form.paperStructId,
  546. }),
  547. {
  548. headers: { "content-type": "application/x-www-form-urlencoded" },
  549. }
  550. )
  551. .then((res) => {
  552. if (this.lastRequestKey === str) {
  553. this.tableData3 = res.data.structQuestionInfo || [];
  554. this.tableLoading3 = false;
  555. this.hasError = !res.data.valid;
  556. }
  557. });
  558. },
  559. handleSelectionChange(val) {
  560. // this.multipleSelection = val;
  561. if (val.length) {
  562. val.forEach((element) => {
  563. this.tempPapers.push(cloneDeep(element));
  564. this.tempPaperIds.push(element.id);
  565. });
  566. this.getTable2();
  567. this.getTable3();
  568. }
  569. },
  570. hasNumError(row) {
  571. return (
  572. row.easyInfo?.valid == false ||
  573. row.hardInfo?.valid == false ||
  574. row.mediumInfo?.valid == false
  575. );
  576. // if (prop === "detailName") {
  577. // return false;
  578. // } else {
  579. // let targetName = row.detailName;
  580. // let find = this.tableData1.find(
  581. // (item) => item.detailName === targetName
  582. // );
  583. // if (!find) {
  584. // return false;
  585. // } else {
  586. // if (prop === "totalCount") {
  587. // return row[prop] < find[prop];
  588. // } else {
  589. // return row[prop].count < find[prop].count;
  590. // }
  591. // }
  592. // }
  593. },
  594. // hasError() {
  595. // return (
  596. // this.tableData1.length &&
  597. // this.tableData3.length &&
  598. // this.tableData3.every((item) => {
  599. // return (
  600. // this.hasNumError(item, "totalCount") ||
  601. // this.hasNumError(item, "hardInfo") ||
  602. // this.hasNumError(item, "mediumInfo") ||
  603. // this.hasNumError(item, "easyInfo")
  604. // );
  605. // })
  606. // );
  607. // },
  608. },
  609. };
  610. </script>
  611. <style lang="scss" scoped>
  612. .add-paper-select {
  613. * {
  614. box-sizing: border-box;
  615. }
  616. .el-form .el-form-item {
  617. margin-bottom: 18px;
  618. }
  619. ::v-deep .red {
  620. color: #f56c6c;
  621. font-weight: bold;
  622. text-decoration: underline;
  623. cursor: pointer;
  624. }
  625. p {
  626. margin: 0;
  627. }
  628. .top {
  629. display: flex;
  630. align-items: center;
  631. justify-content: space-between;
  632. padding-bottom: 15px;
  633. border-bottom: 1px solid #eee;
  634. p {
  635. font-size: 14px;
  636. }
  637. }
  638. .box-body {
  639. background-color: #fff;
  640. border-radius: 6px;
  641. padding: 15px 10px;
  642. .form {
  643. margin-top: 15px;
  644. }
  645. }
  646. }
  647. </style>