SelectQuestionDialog.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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="创建时间" width="170" prop="creationTime">
  89. </el-table-column>
  90. <el-table-column label="操作" width="160" fixed="right">
  91. <div v-if="!scope.row.disabled" slot-scope="scope">
  92. <el-button
  93. v-if="scope.row.selected"
  94. size="mini"
  95. type="danger"
  96. @click="toDelete(scope.row)"
  97. >
  98. 删除
  99. </el-button>
  100. <el-button
  101. v-else
  102. size="mini"
  103. type="primary"
  104. plain
  105. @click="toSelect(scope.row)"
  106. >
  107. 添加
  108. </el-button>
  109. </div>
  110. </el-table-column>
  111. </el-table>
  112. <div class="part-page">
  113. <el-pagination
  114. background
  115. :current-page="currentPage"
  116. :page-size="pageSize"
  117. :page-sizes="[10, 20, 50, 100, 200, 300]"
  118. layout="total, sizes, prev, pager, next, jumper"
  119. :total="total"
  120. @current-change="toPage"
  121. @size-change="handleSizeChange"
  122. />
  123. </div>
  124. </el-tab-pane>
  125. <el-tab-pane name="2">
  126. <span slot="label">
  127. <span>已选试题</span>
  128. <span class="color-primary">({{ curSelectedQuestions.length }})</span>
  129. </span>
  130. <el-table :data="curSelectedQuestions" border>
  131. <el-table-column width="60" type="index" label="编号">
  132. </el-table-column>
  133. <el-table-column label="题干" min-width="200">
  134. <div slot-scope="scope" @click="toViewQuestion(scope.row)">
  135. <rich-text
  136. class="row-question-body"
  137. title="点击查看试题"
  138. :text-json="scope.row.quesBody"
  139. ></rich-text>
  140. </div>
  141. </el-table-column>
  142. <el-table-column label="课程" width="200">
  143. <template slot-scope="scope">
  144. <span>{{ scope.row.course.name }}</span>
  145. </template>
  146. </el-table-column>
  147. <el-table-column label="题型" prop="sourceDetailName" width="100">
  148. </el-table-column>
  149. <el-table-column label="难度" prop="difficulty" width="80">
  150. </el-table-column>
  151. <el-table-column label="使用量" prop="usageAmount" width="80">
  152. </el-table-column>
  153. <el-table-column label="创建人" prop="creator" width="120">
  154. </el-table-column>
  155. <el-table-column label="创建时间" width="170" prop="creationTime">
  156. </el-table-column>
  157. <el-table-column label="操作" width="160" fixed="right">
  158. <div slot-scope="scope">
  159. <el-button
  160. size="mini"
  161. type="danger"
  162. @click="toDeleteSelected(scope.row)"
  163. >
  164. 删除
  165. </el-button>
  166. </div>
  167. </el-table-column>
  168. </el-table>
  169. </el-tab-pane>
  170. </el-tabs>
  171. <div slot="footer"></div>
  172. <question-preview-dialog
  173. ref="QuestionPreviewDialog"
  174. :question="curQuestion"
  175. ></question-preview-dialog>
  176. </el-dialog>
  177. </template>
  178. <script>
  179. import QuestionPreviewDialog from "../../question/components/QuestionPreviewDialog";
  180. import PropertyTreeSelect from "../../question/components/PropertyTreeSelect.vue";
  181. import { questionPageListApi } from "../../question/api";
  182. import { deepCopy } from "@/plugins/utils";
  183. export default {
  184. name: "SelectQuestionDialog",
  185. components: { QuestionPreviewDialog, PropertyTreeSelect },
  186. props: {
  187. courseId: {
  188. type: [String, Number],
  189. default: "",
  190. },
  191. sourceDetail: {
  192. type: Object,
  193. default() {
  194. return {
  195. questionType: "",
  196. sourceDetailId: "",
  197. };
  198. },
  199. },
  200. disabledSourceDetail: {
  201. type: Boolean,
  202. default: false,
  203. },
  204. selectedQuestionIds: {
  205. type: Array,
  206. default() {
  207. return [];
  208. },
  209. },
  210. disabledQuestionIds: {
  211. type: Array,
  212. default() {
  213. return [];
  214. },
  215. },
  216. },
  217. data() {
  218. return {
  219. modalIsShow: false,
  220. filter: {
  221. courseId: "",
  222. questionType: "",
  223. sourceDetailId: "",
  224. questionBody: "",
  225. questionProperty: [],
  226. },
  227. tabType: "1",
  228. tableData: [],
  229. currentPage: 1,
  230. pageSize: 10,
  231. total: 10,
  232. questions: [],
  233. curSelectedQuestions: [],
  234. curSelectedQuestionIds: [],
  235. curQuestion: {},
  236. };
  237. },
  238. methods: {
  239. initData() {
  240. this.filter = Object.assign({}, this.filter, {
  241. courseId: this.courseId,
  242. questionType: this.sourceDetail.questionType,
  243. sourceDetailId: this.sourceDetail.sourceDetailId,
  244. });
  245. this.curSelectedQuestions = [];
  246. this.curSelectedQuestionIds = [];
  247. this.toPage(this.currentPage);
  248. },
  249. visibleChange() {
  250. this.initData();
  251. },
  252. cancel() {
  253. this.modalIsShow = false;
  254. },
  255. open() {
  256. this.modalIsShow = true;
  257. },
  258. async getList() {
  259. let data = {
  260. ...this.filter,
  261. pageNumber: this.currentPage,
  262. pageSize: this.pageSize,
  263. };
  264. data.questionProperty = data.questionProperty.join();
  265. const res = await questionPageListApi(data).catch(() => {});
  266. this.questions = res.data.content.map((item) => {
  267. return {
  268. ...item,
  269. selected: this.curSelectedQuestionIds.includes(item.id),
  270. disabled: this.disabledQuestionIds.includes(item.id),
  271. };
  272. });
  273. this.total = res.total;
  274. },
  275. indexMethod(index) {
  276. return index + (this.currentPage - 1) * this.pageSize + 1;
  277. },
  278. toPage(val) {
  279. this.currentPage = val;
  280. this.getList();
  281. },
  282. handleSizeChange(val) {
  283. this.pageSize = val;
  284. this.currentPage = 1;
  285. this.getList();
  286. },
  287. tabChange(val) {
  288. if (val.name === "1") {
  289. this.questions.forEach((item) => {
  290. item.selected = this.curSelectedQuestionIds.includes(item.id);
  291. });
  292. }
  293. },
  294. toViewQuestion(row) {
  295. this.curQuestion = row;
  296. this.$refs.QuestionPreviewDialog.open();
  297. },
  298. toSelect(row) {
  299. row.selected = true;
  300. this.curSelectedQuestions.push({ ...row });
  301. this.updateSelectedQuestionIds();
  302. },
  303. toDelete(row) {
  304. row.selected = false;
  305. this.toDeleteSelected(row);
  306. },
  307. toDeleteSelected(row) {
  308. const pos = this.curSelectedQuestions.findIndex(
  309. (item) => item.id === row.id
  310. );
  311. this.curSelectedQuestions.splice(pos, 1);
  312. this.updateSelectedQuestionIds();
  313. },
  314. updateSelectedQuestionIds() {
  315. this.curSelectedQuestionIds = this.curSelectedQuestions.map(
  316. (item) => item.id
  317. );
  318. },
  319. confirm() {
  320. this.$emit("confirm", deepCopy(this.curSelectedQuestions));
  321. this.cancel();
  322. },
  323. },
  324. };
  325. </script>