examQuestionList.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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.title }}
  18. </li>
  19. </ul>
  20. </div>
  21. <div class="border-line"></div>
  22. <div class="filter-other-box">
  23. <span class="filter-other-title">其它选项:</span>
  24. <span class="filter-other-item-title">工种:</span>
  25. <a-select
  26. v-model="engineeringWorkChooseValue"
  27. @change="handleChangeEngineeringWorkValue"
  28. >
  29. <a-select-option
  30. v-for="(item, index) in engineeringWorkList"
  31. :key="index"
  32. :value="item.code"
  33. >
  34. {{ item.title }}
  35. </a-select-option>
  36. </a-select>
  37. </div>
  38. </div>
  39. <!-- 表单 -->
  40. <div class="common-card margin-top-all">
  41. <!-- 清空、批量删除 -->
  42. <div class="exam-question-edit-row">
  43. <a-button
  44. type="primary"
  45. :disabled="!hasSelected"
  46. @click="handleClearSelectDataFun"
  47. >
  48. 清空
  49. </a-button>
  50. <span v-if="hasSelected" class="exam-question-edit-checkedtxt">
  51. {{ `已选择 ${selectedRowKeys.length} 项` }}
  52. </span>
  53. <a-button
  54. class="exam-question-edit-delete"
  55. type="primary"
  56. :disabled="!hasSelected"
  57. @click="handleDeleteSelectDataFun"
  58. >
  59. 批量删除
  60. </a-button>
  61. </div>
  62. <!-- 表单[自带分页功能] -->
  63. <a-table
  64. :columns="columns"
  65. :data-source="tableData"
  66. :row-key="(record) => record.id"
  67. :scroll="{ y: tableHeight }"
  68. :row-selection="{
  69. selectedRowKeys: selectedRowKeys,
  70. onChange: onSelectChange,
  71. }"
  72. :pagination="pagination"
  73. @change="handleTableChange"
  74. >
  75. <template slot="questionType" slot-scope="text, record">
  76. <span>{{ record.questionTypeTxt }}</span>
  77. </template>
  78. <template slot="engineeringWork" slot-scope="text, record">
  79. <span>{{ record.engineeringWorkTxt }}</span>
  80. </template>
  81. <template slot="action" slot-scope="text, record">
  82. <a @click="toQuestionDetailFun(record)">详情</a>
  83. <a-divider type="vertical" />
  84. <a @click="deleteQuestionFun(record)">删除</a>
  85. </template>
  86. </a-table>
  87. </div>
  88. </a-spin>
  89. </div>
  90. </template>
  91. <script>
  92. import { mapGetters } from 'vuex';
  93. import { ENGINEERING_WORK_LIST, EXAM_QUESTION_TYPE } from '@/common/Constant';
  94. import { QUESTIONLISTRES } from '@/common/resData';
  95. export default {
  96. name: 'examQuestionList',
  97. props: {},
  98. components: {},
  99. data() {
  100. return {
  101. examQuestionType: [], // 所属题目类型列表
  102. checkedExamQuestionType: '', // 所选题目类型
  103. engineeringWorkList: [], // 工种数据列表
  104. engineeringWorkChooseValue: '', // 所选工种
  105. tableHeight: 400, // 表格高度
  106. columns: [], // form表单的列参数
  107. tableData: [], // 表单数据
  108. pagination: {
  109. pageSize: 7,
  110. current: 1,
  111. total: 0,
  112. }, // 分页参数
  113. loading: false, // 是否展示加载动画
  114. selectedRowKeys: [], // 多选的结果
  115. };
  116. },
  117. created() {
  118. this.initDataFun(); //初始化数据
  119. },
  120. mounted() {
  121. this.initTableHeightFun(); // 初始化表单的高度
  122. },
  123. beforeDestroy() {},
  124. watch: {
  125. screenHeight() {
  126. this.initTableHeightFun(); // 初始化表单的高度
  127. },
  128. },
  129. computed: {
  130. // 是否选择了数据
  131. ...mapGetters(['screenHeight']),
  132. // 判断是否有行被选择
  133. hasSelected() {
  134. return this.selectedRowKeys.length > 0;
  135. },
  136. },
  137. methods: {
  138. // 初始化表单的高度
  139. initTableHeightFun() {
  140. this.tableHeight =
  141. this.$refs.tableBody.offsetHeight -
  142. (this.$refs.filterCard.offsetHeight + 48 * 4);
  143. },
  144. //初始化数据
  145. initDataFun() {
  146. this.loading = true;
  147. // 题目分类
  148. this.examQuestionType = [
  149. { title: '全部', code: '' },
  150. ...EXAM_QUESTION_TYPE,
  151. ];
  152. this.checkedExamQuestionType = this.examQuestionType[0].code;
  153. // 工种类别
  154. this.engineeringWorkList = ENGINEERING_WORK_LIST;
  155. this.engineeringWorkChooseValue = this.engineeringWorkList[0].code;
  156. // 表单的列的配置参数
  157. this.columns = [
  158. {
  159. title: '题目编号',
  160. dataIndex: 'questionCode',
  161. key: 'questionCode',
  162. // width: 200,
  163. },
  164. {
  165. title: '题目',
  166. dataIndex: 'questionDescription',
  167. key: 'questionDescription',
  168. // width: 700,
  169. },
  170. {
  171. title: '题目类别',
  172. dataIndex: 'questionType',
  173. key: 'questionType',
  174. scopedSlots: { customRender: 'questionType' },
  175. // width: 200,
  176. },
  177. {
  178. title: '工种',
  179. dataIndex: 'engineeringWork',
  180. key: 'engineeringWork',
  181. scopedSlots: { customRender: 'engineeringWork' },
  182. // width: 200,
  183. },
  184. {
  185. title: '操作',
  186. dataIndex: 'action',
  187. key: 'action',
  188. scopedSlots: { customRender: 'action' },
  189. // with: 200,
  190. },
  191. ];
  192. this.getQusetionsListFun(); // 查询:题目列表数据
  193. },
  194. // 操作:选择某个题目类型
  195. handleExamQuestionTypeFun(item) {
  196. console.log('选择某个题目类型', item);
  197. if (this.checkedExamQuestionType === item.code) {
  198. return;
  199. }
  200. this.checkedExamQuestionType = item.code;
  201. },
  202. // 操作:选择了某个工种
  203. handleChangeEngineeringWorkValue() {
  204. console.log('选择了某个工种', this.engineeringWorkChooseValue);
  205. },
  206. // 查询:题目列表数据
  207. getQusetionsListFun() {
  208. // 列表数据
  209. const resData = QUESTIONLISTRES.data;
  210. setTimeout(() => {
  211. resData.forEach((item) => {
  212. EXAM_QUESTION_TYPE.forEach((it) => {
  213. if (item.questionType === it.code) {
  214. item.questionTypeTxt = it.title;
  215. }
  216. });
  217. ENGINEERING_WORK_LIST.forEach((it) => {
  218. if (item.engineeringWork === it.code) {
  219. item.engineeringWorkTxt = it.title;
  220. }
  221. });
  222. });
  223. this.pagination.total = resData.length;
  224. this.tableData = [...resData];
  225. this.loading = false;
  226. }, 1500);
  227. },
  228. // 查询:表格某页的数据
  229. handleTableChange(pagination) {
  230. this.loading = true;
  231. setTimeout(() => {
  232. const pager = { ...this.pagination };
  233. pager.current = pagination.current;
  234. this.pagination = pager;
  235. this.loading = false;
  236. }, 1500);
  237. // let params = {
  238. // pagination: pagination,
  239. // questionType: this.checkedExamQuestionType,
  240. // engineeringWork: this.engineeringWorkChooseValue
  241. // };
  242. // this.$_http
  243. // .get(this.$_API.INTERFACE_GET_USER_ADMIN_USERS, { params })
  244. // .then((res) => {
  245. // console.log(res);
  246. // this.tableData = res.data;
  247. // this.pagination.total = res.pagination.total;
  248. // })
  249. // .catch((err) => {
  250. // console.log(err);
  251. // })
  252. // .finally(() => {
  253. // this.loading = false;
  254. // });
  255. },
  256. // 操作:详情
  257. toQuestionDetailFun(record) {
  258. console.log('查看某个试题的详情', record);
  259. },
  260. // 操作:删除
  261. deleteQuestionFun(record) {
  262. // let that = this
  263. this.$confirm({
  264. title: '删除',
  265. content: `确认删除编号为 ${record.questionCode} 的题目吗?`,
  266. okText: '确认',
  267. cancelText: '取消',
  268. onOk() {
  269. // let params = {
  270. // id: record.id,
  271. // };
  272. // that.$_http
  273. // .post(that.$_API.INTERFACE_POST_EXAMS_QUESTION_DELETE, params)
  274. // .then((res) => {
  275. // console.log(res);
  276. // })
  277. // .catch((err) => {
  278. // console.log(err);
  279. // })
  280. // .finally(() => {
  281. // that.loading = false;
  282. // });
  283. },
  284. onCancel() {},
  285. });
  286. },
  287. // 操作:清空选择
  288. handleClearSelectDataFun() {
  289. this.loading = true;
  290. this.selectedRowKeys = [];
  291. this.loading = false;
  292. },
  293. // 操作:多选变化时
  294. onSelectChange(selectedRowKeys) {
  295. this.selectedRowKeys = selectedRowKeys;
  296. },
  297. // 操作:批量删除
  298. handleDeleteSelectDataFun() {
  299. let that = this;
  300. this.$confirm({
  301. title: '批量删除',
  302. content: `确认批量删除吗?`,
  303. okText: '确认',
  304. cancelText: '取消',
  305. onOk() {
  306. console.log('批量删除', that.selectedRowKeys);
  307. that.loading = true;
  308. setTimeout(() => {
  309. that.selectedRowKeys = [];
  310. that.loading = false;
  311. }, 1500);
  312. // that.$_http
  313. // .post(that.$_API.INTERFACE_POST_EXAMS_QUESTION_DELETE_LIST, params)
  314. // .then((res) => {
  315. // console.log(res);
  316. // })
  317. // .catch((err) => {
  318. // console.log(err);
  319. // })
  320. // .finally(() => {
  321. // that.loading = false;
  322. // });
  323. },
  324. onCancel() {},
  325. });
  326. },
  327. },
  328. };
  329. </script>
  330. <style lang="less"></style>
  331. <style lang="less" scoped>
  332. @import '~@/styles/common/variable.less';
  333. </style>