SelectQuestionDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <el-dialog
  3. class="select-question-dialog"
  4. :visible.sync="modalIsShow"
  5. :close-on-click-modal="false"
  6. :close-on-press-escape="false"
  7. :show-close="false"
  8. append-to-body
  9. fullscreen
  10. @open="visibleChange"
  11. >
  12. <div slot="title" class="box-justify">
  13. <h3>选择试题</h3>
  14. <div>
  15. <el-button size="mini" type="primary" @click="confirm">确定</el-button>
  16. <el-button size="mini" type="danger" plain @click="cancel"
  17. >取消</el-button
  18. >
  19. </div>
  20. </div>
  21. <el-tabs
  22. v-model="tabType"
  23. class="part-box"
  24. type="card"
  25. @tab-click="tabChange"
  26. >
  27. <el-tab-pane name="1">
  28. <span slot="label">试题筛选</span>
  29. <div class="part-filter">
  30. <div class="part-filter-form">
  31. <el-form class="part-filter-form" :inline="true" :model="filter">
  32. <el-form-item label="题型">
  33. <source-detail-select
  34. v-model="filter"
  35. :course-id="filter.courseId"
  36. :disabled="disabledSourceDetail"
  37. >
  38. </source-detail-select>
  39. </el-form-item>
  40. <el-form-item label="题目内容">
  41. <el-input
  42. v-model="filter.questionBody"
  43. placeholder="题目内容"
  44. ></el-input>
  45. </el-form-item>
  46. <el-form-item label="属性">
  47. <property-tree-select
  48. v-model="filter.questionProperty"
  49. :course-id="filter.courseId"
  50. ></property-tree-select>
  51. </el-form-item>
  52. <el-form-item>
  53. <el-button type="danger" @click="toPage(1)">查询</el-button>
  54. </el-form-item>
  55. </el-form>
  56. </div>
  57. </div>
  58. <el-table :data="questions">
  59. <el-table-column
  60. width="60"
  61. type="index"
  62. :index="indexMethod"
  63. label="编号"
  64. >
  65. </el-table-column>
  66. <el-table-column label="题干" min-width="200">
  67. <div slot-scope="scope" @click="toViewQuestion(scope.row)">
  68. <rich-text
  69. class="row-question-body"
  70. title="点击查看试题"
  71. :text-json="scope.row.quesBody"
  72. ></rich-text>
  73. </div>
  74. </el-table-column>
  75. <el-table-column label="课程" width="120">
  76. <template slot-scope="scope">
  77. <span>{{ scope.row.course.name }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="题型" prop="sourceDetailName" width="100">
  81. </el-table-column>
  82. <el-table-column label="难度" prop="difficulty" width="80">
  83. </el-table-column>
  84. <el-table-column label="使用量" prop="usageAmount" width="80">
  85. </el-table-column>
  86. <el-table-column label="创建人" prop="creator" width="120">
  87. </el-table-column>
  88. <el-table-column label="属性" min-width="150">
  89. <div
  90. v-if="scope.row.quesProperties"
  91. slot-scope="scope"
  92. class="edit-cont-props"
  93. >
  94. <p
  95. v-for="(content, propIndex) in scope.row.quesProperties"
  96. :key="propIndex"
  97. >
  98. {{ content.courseProperty && content.courseProperty.name }}
  99. <span style="margin: 0 3px">/</span>
  100. {{ content.firstProperty && content.firstProperty.name }}
  101. <span v-if="content.secondProperty" style="margin: 0 3px"
  102. >/</span
  103. >
  104. {{ content.secondProperty && content.secondProperty.name }}
  105. </p>
  106. </div>
  107. </el-table-column>
  108. <el-table-column label="操作" width="90" fixed="right">
  109. <div v-if="!scope.row.disabled" slot-scope="scope">
  110. <el-button
  111. v-if="scope.row.selected"
  112. size="mini"
  113. type="danger"
  114. @click="toDelete(scope.row)"
  115. >
  116. 删除
  117. </el-button>
  118. <el-button
  119. v-else
  120. size="mini"
  121. type="primary"
  122. plain
  123. @click="toSelect(scope.row)"
  124. >
  125. 添加
  126. </el-button>
  127. </div>
  128. </el-table-column>
  129. </el-table>
  130. <div class="part-page">
  131. <el-pagination
  132. background
  133. :current-page="currentPage"
  134. :page-size="pageSize"
  135. :page-sizes="[10, 20, 50, 100, 200, 300]"
  136. layout="total, sizes, prev, pager, next, jumper"
  137. :total="total"
  138. @current-change="toPage"
  139. @size-change="handleSizeChange"
  140. />
  141. </div>
  142. </el-tab-pane>
  143. <el-tab-pane name="2">
  144. <span slot="label">
  145. <span>已选试题</span>
  146. <span class="color-primary">({{ curSelectedQuestions.length }})</span>
  147. </span>
  148. <el-table :data="curSelectedQuestions">
  149. <el-table-column width="60" type="index" label="编号">
  150. </el-table-column>
  151. <el-table-column label="题干" min-width="200">
  152. <div slot-scope="scope" @click="toViewQuestion(scope.row)">
  153. <rich-text
  154. class="row-question-body"
  155. title="点击查看试题"
  156. :text-json="scope.row.quesBody"
  157. ></rich-text>
  158. </div>
  159. </el-table-column>
  160. <el-table-column label="课程" width="200">
  161. <template slot-scope="scope">
  162. <span>{{ scope.row.course.name }}</span>
  163. </template>
  164. </el-table-column>
  165. <el-table-column label="题型" prop="sourceDetailName" width="100">
  166. </el-table-column>
  167. <el-table-column label="难度" prop="difficulty" width="80">
  168. </el-table-column>
  169. <el-table-column label="使用量" prop="usageAmount" width="80">
  170. </el-table-column>
  171. <el-table-column label="创建人" prop="creator" width="120">
  172. </el-table-column>
  173. <el-table-column label="属性" min-width="150">
  174. <div
  175. v-if="scope.row.quesProperties"
  176. slot-scope="scope"
  177. class="edit-cont-props"
  178. >
  179. <p
  180. v-for="(content, propIndex) in scope.row.quesProperties"
  181. :key="propIndex"
  182. >
  183. {{ content.courseProperty && content.courseProperty.name }}
  184. <span style="margin: 0 3px">/</span>
  185. {{ content.firstProperty && content.firstProperty.name }}
  186. <span v-if="content.secondProperty" style="margin: 0 3px"
  187. >/</span
  188. >
  189. {{ content.secondProperty && content.secondProperty.name }}
  190. </p>
  191. </div>
  192. </el-table-column>
  193. <!-- <el-table-column
  194. v-if="IS_PAPER_MODE"
  195. label="分值"
  196. width="120"
  197. prop="score"
  198. >
  199. <template slot-scope="scope">
  200. <el-input-number
  201. v-model="scope.row.score"
  202. placeholder="分值"
  203. :precision="1"
  204. :min="0"
  205. :max="999"
  206. :step="0.1"
  207. step-strictly
  208. :controls="false"
  209. style="width: 90px"
  210. ></el-input-number>
  211. </template>
  212. </el-table-column> -->
  213. <el-table-column label="操作" width="90" fixed="right">
  214. <div slot-scope="scope">
  215. <el-button
  216. size="mini"
  217. type="danger"
  218. @click="toDeleteSelected(scope.row)"
  219. >
  220. 删除
  221. </el-button>
  222. </div>
  223. </el-table-column>
  224. </el-table>
  225. </el-tab-pane>
  226. </el-tabs>
  227. <div slot="footer"></div>
  228. <question-preview-dialog
  229. ref="QuestionPreviewDialog"
  230. :question="curQuestion"
  231. ></question-preview-dialog>
  232. </el-dialog>
  233. </template>
  234. <script>
  235. import QuestionPreviewDialog from "../../question/components/QuestionPreviewDialog";
  236. import PropertyTreeSelect from "../../question/components/PropertyTreeSelect.vue";
  237. import { questionPageListApi } from "../../question/api";
  238. import { deepCopy } from "@/plugins/utils";
  239. export default {
  240. name: "SelectQuestionDialog",
  241. components: { QuestionPreviewDialog, PropertyTreeSelect },
  242. props: {
  243. courseId: {
  244. type: [String, Number],
  245. default: "",
  246. },
  247. sourceDetail: {
  248. type: Object,
  249. default() {
  250. return {
  251. questionType: "",
  252. sourceDetailId: "",
  253. };
  254. },
  255. },
  256. disabledSourceDetail: {
  257. type: Boolean,
  258. default: false,
  259. },
  260. selectedQuestionIds: {
  261. type: Array,
  262. default() {
  263. return [];
  264. },
  265. },
  266. disabledQuestionIds: {
  267. type: Array,
  268. default() {
  269. return [];
  270. },
  271. },
  272. selectMode: {
  273. type: String,
  274. default: "question",
  275. },
  276. },
  277. data() {
  278. return {
  279. modalIsShow: false,
  280. filter: {
  281. courseId: "",
  282. questionType: "",
  283. sourceDetailId: "",
  284. questionBody: "",
  285. questionProperty: [],
  286. },
  287. tabType: "1",
  288. tableData: [],
  289. currentPage: 1,
  290. pageSize: 10,
  291. total: 10,
  292. questions: [],
  293. curSelectedQuestions: [],
  294. curSelectedQuestionIds: [],
  295. curQuestion: {},
  296. };
  297. },
  298. computed: {
  299. IS_PAPER_MODE() {
  300. return this.selectMode === "paper";
  301. },
  302. },
  303. methods: {
  304. initData() {
  305. this.filter = Object.assign({}, this.filter, {
  306. courseId: this.courseId,
  307. questionType: this.sourceDetail.questionType,
  308. sourceDetailId: this.sourceDetail.sourceDetailId,
  309. });
  310. this.curSelectedQuestions = [];
  311. this.curSelectedQuestionIds = [];
  312. this.toPage(this.currentPage);
  313. },
  314. visibleChange() {
  315. this.initData();
  316. },
  317. cancel() {
  318. this.modalIsShow = false;
  319. },
  320. open() {
  321. this.modalIsShow = true;
  322. },
  323. async getList() {
  324. let data = {
  325. ...this.filter,
  326. pageNumber: this.currentPage,
  327. pageSize: this.pageSize,
  328. };
  329. data.questionProperty = data.questionProperty.join();
  330. const res = await questionPageListApi(data).catch(() => {});
  331. this.questions = res.data.content.map((item) => {
  332. return {
  333. ...item,
  334. selected: this.curSelectedQuestionIds.includes(item.id),
  335. disabled: this.disabledQuestionIds.includes(item.id),
  336. };
  337. });
  338. this.total = res.data.total;
  339. },
  340. indexMethod(index) {
  341. return index + (this.currentPage - 1) * this.pageSize + 1;
  342. },
  343. toPage(val) {
  344. this.currentPage = val;
  345. this.getList();
  346. },
  347. handleSizeChange(val) {
  348. this.pageSize = val;
  349. this.currentPage = 1;
  350. this.getList();
  351. },
  352. tabChange(val) {
  353. if (val.name === "1") {
  354. this.questions.forEach((item) => {
  355. item.selected = this.curSelectedQuestionIds.includes(item.id);
  356. });
  357. }
  358. },
  359. toViewQuestion(row) {
  360. this.curQuestion = row;
  361. this.$refs.QuestionPreviewDialog.open();
  362. },
  363. toSelect(row) {
  364. row.selected = true;
  365. this.curSelectedQuestions.push({ ...row });
  366. this.updateSelectedQuestionIds();
  367. },
  368. toDelete(row) {
  369. row.selected = false;
  370. this.toDeleteSelected(row);
  371. },
  372. toDeleteSelected(row) {
  373. const pos = this.curSelectedQuestions.findIndex(
  374. (item) => item.id === row.id
  375. );
  376. this.curSelectedQuestions.splice(pos, 1);
  377. this.updateSelectedQuestionIds();
  378. },
  379. updateSelectedQuestionIds() {
  380. this.curSelectedQuestionIds = this.curSelectedQuestions.map(
  381. (item) => item.id
  382. );
  383. },
  384. confirm() {
  385. // if (this.IS_PAPER_MODE) {
  386. // const unvalid = this.curSelectedQuestions.some((item) => !item.score);
  387. // if (unvalid) {
  388. // this.$message.error("请完成已选试题分值设置");
  389. // this.tabType = "2";
  390. // return;
  391. // }
  392. // }
  393. this.$emit("confirm", deepCopy(this.curSelectedQuestions));
  394. this.cancel();
  395. },
  396. },
  397. };
  398. </script>