examQuestionList.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div class="app-container" ref="tableBody">
  3. <a-spin :spinning="loading">
  4. <!-- 过滤条件栏目 -->
  5. <div class="common-card" ref="filterCard">
  6. <div class="filter-condition-box">
  7. <span>所属类别:</span>
  8. <ul>
  9. <li
  10. :class="{
  11. checkedExamQuestionType: checkedExamQuestionType === item.code,
  12. }"
  13. v-for="(item, index) in examQuestionType"
  14. :key="index"
  15. @click="handleExamQuestionTypeFun(item)"
  16. >
  17. {{ item.name }}
  18. </li>
  19. </ul>
  20. </div>
  21. <div class="filter-condition-box a-card-margin-top flexCenter">
  22. <span>所属类型:</span>
  23. <div class="create-select-row">
  24. <div class="create-select-item">
  25. <span>父类</span>
  26. <a-select
  27. v-model="checkedQuestionConditionParentType"
  28. @change="selectTypeConditionParent"
  29. >
  30. <a-select-option
  31. v-for="(item, index) in questionConditionParentType"
  32. :key="index"
  33. :value="item.id"
  34. >
  35. {{ item.name }}
  36. </a-select-option>
  37. </a-select>
  38. </div>
  39. <div class="create-select-item">
  40. <span>子类</span>
  41. <a-select
  42. v-model="checkedQuestionConditionChildrenType"
  43. :disabled="!checkedQuestionConditionParentType"
  44. @change="selectTypeConditionChildren"
  45. >
  46. <a-select-option
  47. v-for="(item, index) in questionConditionChildrenType"
  48. :key="index"
  49. :value="item.id"
  50. >
  51. {{ item.name }}
  52. </a-select-option>
  53. </a-select>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="border-line"></div>
  58. <div class="filter-other-box">
  59. <span class="filter-other-title">其它选项:</span>
  60. <span class="filter-other-item-title">工种:</span>
  61. <a-select
  62. v-model="engineeringWorkChoose"
  63. @change="handleChangeEngineeringWorkValue"
  64. >
  65. <a-select-option
  66. v-for="(item, index) in engineeringWorkList"
  67. :key="index"
  68. :value="item.id"
  69. >
  70. {{ item.name }}
  71. </a-select-option>
  72. </a-select>
  73. </div>
  74. </div>
  75. <!-- 表单 -->
  76. <div class="common-card a-card-margin-top">
  77. <!-- 清空、批量删除 -->
  78. <div class="exam-question-edit-row">
  79. <a-button
  80. type="primary"
  81. :disabled="!hasSelected"
  82. @click="handleClearSelectDataFun"
  83. >
  84. 清空所选
  85. </a-button>
  86. <span v-if="hasSelected" class="exam-question-edit-checkedtxt">
  87. {{ `已选择 ${selectedRowKeys.length} 项` }}
  88. </span>
  89. <a-button
  90. class="exam-question-edit-delete"
  91. type="primary"
  92. :disabled="!hasSelected"
  93. @click="handleDeleteSelectDataFun"
  94. >
  95. 批量删除
  96. </a-button>
  97. </div>
  98. <!-- 表单 -->
  99. <a-table
  100. :columns="columns"
  101. :data-source="tableData"
  102. :row-key="(record) => record.id"
  103. :scroll="{ y: tableHeight }"
  104. :row-selection="{
  105. selectedRowKeys: selectedRowKeys,
  106. onChange: onSelectChange,
  107. }"
  108. :pagination="false"
  109. >
  110. <template slot="type" slot-scope="text, record">
  111. <span>{{ record.typeTxt }}</span>
  112. </template>
  113. <template slot="questionCategory" slot-scope="text, record">
  114. <span>{{
  115. record.questionCategory ? record.questionCategory.name : '不限'
  116. }}</span>
  117. </template>
  118. <template slot="rootQuestionCategory" slot-scope="text, record">
  119. <span>{{
  120. record.rootQuestionCategory
  121. ? record.rootQuestionCategory.name
  122. : '不限'
  123. }}</span>
  124. </template>
  125. <template slot="action" slot-scope="text, record">
  126. <a @click="toQuestionDetailFun(record)">详情</a>
  127. <a-divider type="vertical" />
  128. <a @click="deleteQuestionFun(record)">删除</a>
  129. </template>
  130. </a-table>
  131. <!-- 分页 -->
  132. <div class="a-pagination-display">
  133. <a-pagination
  134. v-model="pagination.current"
  135. :pageSize="pagination.pageSize"
  136. :total.sync="pagination.total"
  137. show-less-items
  138. show-quick-jumper
  139. @change="getQusetionsListFun"
  140. />
  141. </div>
  142. </div>
  143. </a-spin>
  144. <div class="company-info">
  145. <span>
  146. copyright © 浮游科技有限公司出品
  147. </span>
  148. </div>
  149. </div>
  150. </template>
  151. <script>
  152. import { EXAM_QUESTION_TYPE } from '@/common/Constant';
  153. import { mapGetters } from 'vuex';
  154. import { formatePathParams, formateEngineeringWork } from '@/filters';
  155. export default {
  156. name: 'examQuestionList',
  157. props: {},
  158. components: {},
  159. data() {
  160. return {
  161. examQuestionType: [], // 试题类别列表
  162. checkedExamQuestionType: '', // 所选试题类别
  163. questionConditionParentType: [], // 试题类型列表-父类
  164. checkedQuestionConditionParentType: '', // 所选试题类型-父类
  165. questionConditionChildrenType: [], // 试题类型列表-子类
  166. checkedQuestionConditionChildrenType: '', // 所选试题类型-子类
  167. engineeringWorkList: [], // 工种数据列表
  168. engineeringWorkChoose: '', // 所选工种信息
  169. tableHeight: 400, // 表格高度
  170. columns: [], // form表单的列参数
  171. tableData: [], // 表单数据
  172. pagination: {
  173. pageSize: 7,
  174. current: 1,
  175. total: 0,
  176. }, // 分页参数
  177. loading: false, // 是否展示加载动画
  178. selectedRowKeys: [], // 多选的结果
  179. };
  180. },
  181. created() {
  182. this.initDataFun(); //初始化数据
  183. },
  184. mounted() {
  185. this.initTableHeightFun(); // 初始化表单的高度
  186. },
  187. beforeDestroy() {},
  188. watch: {
  189. screenHeight() {
  190. this.initTableHeightFun(); // 初始化表单的高度
  191. },
  192. },
  193. computed: {
  194. ...mapGetters([
  195. 'screenHeight',
  196. 'GET_ENGINEERING_WORK_LIST',
  197. 'GET_EXAM_QUESTION_TYPE_CONDITION_PARENT',
  198. ]),
  199. // 判断是否有行被选择
  200. hasSelected() {
  201. return this.selectedRowKeys.length > 0;
  202. },
  203. },
  204. methods: {
  205. // 初始化表单的高度
  206. initTableHeightFun() {
  207. this.tableHeight =
  208. this.$refs.tableBody.offsetHeight -
  209. (this.$refs.filterCard.offsetHeight + 48 * 4 - 5);
  210. },
  211. //初始化数据
  212. initDataFun() {
  213. // 试题类别
  214. this.examQuestionType = [
  215. { name: '全部', code: '' },
  216. ...EXAM_QUESTION_TYPE,
  217. ];
  218. // 试题类型
  219. this.questionConditionParentType = [
  220. { name: '不限', id: '' },
  221. ...this.GET_EXAM_QUESTION_TYPE_CONDITION_PARENT,
  222. ];
  223. this.checkedQuestionConditionParentType = this.questionConditionParentType[0].id;
  224. // 工种类别
  225. this.engineeringWorkList = [
  226. { name: '不限', id: '' },
  227. ...this.GET_ENGINEERING_WORK_LIST,
  228. ];
  229. // 表单的列的配置参数
  230. this.columns = [
  231. {
  232. title: '试题编号',
  233. dataIndex: 'id',
  234. key: 'id',
  235. },
  236. {
  237. title: '试题',
  238. dataIndex: 'content',
  239. key: 'content',
  240. },
  241. {
  242. title: '试题类别',
  243. dataIndex: 'type',
  244. key: 'type',
  245. scopedSlots: { customRender: 'type' },
  246. },
  247. {
  248. title: '试题父类',
  249. dataIndex: 'questionCategory',
  250. key: 'questionCategory',
  251. scopedSlots: { customRender: 'questionCategory' },
  252. },
  253. {
  254. title: '试题子类',
  255. dataIndex: 'rootQuestionCategory',
  256. key: 'rootQuestionCategory',
  257. scopedSlots: { customRender: 'rootQuestionCategory' },
  258. },
  259. {
  260. title: '工种',
  261. dataIndex: 'engineerTypeTxt',
  262. key: 'engineerTypeTxt',
  263. scopedSlots: { customRender: 'engineerTypeTxt' },
  264. },
  265. {
  266. title: '操作',
  267. dataIndex: 'action',
  268. key: 'action',
  269. scopedSlots: { customRender: 'action' },
  270. },
  271. ];
  272. this.getQusetionsListFun(); // 查询:试题列表数据
  273. },
  274. // 初始化分页参数
  275. initPagination() {
  276. this.pagination.current = 1;
  277. this.pagination.pageSize = 7;
  278. this.pagination.total = 0;
  279. },
  280. // 查询:试题类型列表-子类
  281. getTableChildrenListFun() {
  282. if (!this.checkedQuestionConditionParentType) {
  283. this.checkedQuestionConditionChildrenType = '';
  284. this.questionConditionChildrenType = [];
  285. this.initPagination(); // 初始化分页参数
  286. this.getQusetionsListFun(); // 查询:试题列表数据
  287. return;
  288. }
  289. this.loading = true;
  290. let params = {
  291. categoryId: this.checkedQuestionConditionParentType,
  292. };
  293. this.$_http
  294. .get(
  295. formatePathParams(
  296. this.$_API.INTERFACE_GET_EXAMS_QUESTION_TYPE_CONDITION_CHILDRENS,
  297. params
  298. )
  299. )
  300. .then((res) => {
  301. this.questionConditionChildrenType = res.data;
  302. this.checkedQuestionConditionChildrenType = this.questionConditionChildrenType[0].id;
  303. this.loading = false;
  304. this.initPagination(); // 初始化分页参数
  305. this.getQusetionsListFun(); // 查询:试题列表数据
  306. })
  307. .catch(() => {
  308. this.loading = false;
  309. });
  310. },
  311. // 查询:试题列表数据
  312. getQusetionsListFun() {
  313. this.loading = true;
  314. let params = {
  315. page: this.pagination.current - 1,
  316. size: this.pagination.pageSize,
  317. type: this.checkedExamQuestionType,
  318. categoryid: this.checkedQuestionConditionChildrenType,
  319. engineertypeid: this.engineeringWorkChoose,
  320. };
  321. this.$_http
  322. .get(this.$_API.INTERFACE_GET_EXAMS_QUESTION_LIST, { params })
  323. .then((res) => {
  324. let resData = res.data.content;
  325. resData.forEach((item) => {
  326. this.examQuestionType.forEach((it) => {
  327. if (item.type === it.code) {
  328. item.typeTxt = it.name;
  329. }
  330. }); // 试题类别---注意之后从engineertypes中拿
  331. // 工种
  332. if (item.engineerTypes) {
  333. let findItem = formateEngineeringWork(
  334. this.engineeringWorkList,
  335. item.engineerTypes[0]
  336. );
  337. item.engineerTypeTxt = findItem.name;
  338. } else {
  339. item.engineerTypeTxt = '不限';
  340. }
  341. });
  342. this.pagination.total = res.data.totalElements; // 总条数
  343. this.tableData = resData;
  344. this.loading = false;
  345. })
  346. .catch(() => {
  347. this.loading = false;
  348. });
  349. },
  350. // 操作:选择某个试题类别
  351. handleExamQuestionTypeFun(item) {
  352. if (this.checkedExamQuestionType === item.code) {
  353. return;
  354. }
  355. this.checkedExamQuestionType = item.code;
  356. this.initPagination(); // 初始化分页参数
  357. this.getQusetionsListFun(); // 查询:试题列表数据
  358. },
  359. // 操作:选择了父类
  360. selectTypeConditionParent() {
  361. this.getTableChildrenListFun(); // 查询:试题类型列表-子类
  362. },
  363. // 操作:选择了子类
  364. selectTypeConditionChildren() {
  365. this.initPagination(); // 初始化分页参数
  366. this.getQusetionsListFun(); // 查询:试题列表数据
  367. },
  368. // 操作:选择了某个工种
  369. handleChangeEngineeringWorkValue() {
  370. this.initPagination(); // 初始化分页参数
  371. this.getQusetionsListFun(); // 查询:试题列表数据
  372. },
  373. // 操作:详情
  374. toQuestionDetailFun(record) {
  375. console.log('查看某个试题的详情', record);
  376. // if (!record || !record.id) {
  377. // this.$message.error('数据异常,请重新进入当前页面');
  378. // return;
  379. // }
  380. // switch (record.type) {
  381. // case EXAM_QUESTION_TYPE[0].code:
  382. // this.$router.push({
  383. // path: '/examQuestionManagement/create/singleChoice',
  384. // query: { id: record.id },
  385. // });
  386. // break;
  387. // case EXAM_QUESTION_TYPE[1].code:
  388. // this.$router.push({
  389. // path: '/examQuestionManagement/create/multipleChoice',
  390. // query: { id: record.id },
  391. // });
  392. // break;
  393. // case EXAM_QUESTION_TYPE[2].code:
  394. // this.$router.push({
  395. // path: '/examQuestionManagement/create/trueOrFalse',
  396. // query: { id: record.id },
  397. // });
  398. // break;
  399. // case EXAM_QUESTION_TYPE[3].code:
  400. // this.$router.push({
  401. // path: '/examQuestionManagement/create/gapFilling',
  402. // query: { id: record.id },
  403. // });
  404. // break;
  405. // default:
  406. // this.$message.error('试题类别异常,无法查看详情');
  407. // break;
  408. // }
  409. },
  410. // 操作:删除
  411. deleteQuestionFun(record) {
  412. let that = this;
  413. this.$confirm({
  414. title: '删除',
  415. content: `确认删除编号为 ${record.id} 的试题吗?`,
  416. okText: '确认',
  417. cancelText: '取消',
  418. onOk() {
  419. that.loading = true;
  420. let params = {
  421. questionId: record.id,
  422. };
  423. that.$_http
  424. .delete(
  425. formatePathParams(
  426. that.$_API.INTERFACE_DELETE_EXAMS_QUESTION_DELETE,
  427. params
  428. )
  429. )
  430. .then(() => {
  431. that.selectedRowKeys = that.selectedRowKeys.filter((id) => {
  432. if (id !== record.id) {
  433. return id;
  434. }
  435. });
  436. that.loading = false;
  437. that.$message.success('删除试题成功');
  438. that.initPagination(); // 初始化分页参数
  439. that.getQusetionsListFun(); // 查询:试题列表数据
  440. })
  441. .catch(() => {
  442. that.loading = false;
  443. });
  444. },
  445. onCancel() {},
  446. });
  447. },
  448. // 操作:清空选择
  449. handleClearSelectDataFun() {
  450. this.selectedRowKeys = [];
  451. },
  452. // 操作:多选变化时
  453. onSelectChange(selectedRowKeys) {
  454. this.selectedRowKeys = selectedRowKeys;
  455. },
  456. // 操作:批量删除
  457. handleDeleteSelectDataFun() {
  458. let that = this;
  459. this.$confirm({
  460. title: '批量删除',
  461. content: `确认批量删除吗?`,
  462. okText: '确认',
  463. cancelText: '取消',
  464. onOk() {
  465. that.loading = true;
  466. that.$_http
  467. .delete(that.$_API.INTERFACE_DELETE_EXAMS_QUESTION_DELETE_LIST, {
  468. data: that.selectedRowKeys,
  469. })
  470. .then(() => {
  471. that.selectedRowKeys = [];
  472. that.loading = false;
  473. that.$message.success('批量删除试题成功');
  474. that.initPagination(); // 初始化分页参数
  475. that.getQusetionsListFun(); // 查询:试题列表数据
  476. })
  477. .catch(() => {
  478. that.loading = false;
  479. });
  480. },
  481. onCancel() {},
  482. });
  483. },
  484. },
  485. };
  486. </script>
  487. <style lang="less"></style>
  488. <style lang="less" scoped>
  489. @import '~@/styles/common/variable.less';
  490. </style>