examManagementList.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. checkedExamType: checkedExamType === item.code,
  12. }"
  13. v-for="(item, index) in examType"
  14. :key="index"
  15. @click="handleExamQuestionTypeFun(item)"
  16. >
  17. {{ item.name }}
  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.id"
  33. >
  34. {{ item.name }}
  35. </a-select-option>
  36. </a-select>
  37. </div>
  38. </div>
  39. <!-- 表单 -->
  40. <div class="common-card a-card-margin-top">
  41. <!-- 清空、批量删除 -->
  42. <div class="exam-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-edit-checkedtxt">
  51. {{ `已选择 ${selectedRowKeys.length} 项` }}
  52. </span>
  53. <a-button
  54. class="exam-edit-delete"
  55. type="primary"
  56. :disabled="!hasSelected"
  57. @click="handleDeleteSelectDataFun"
  58. >
  59. 批量删除
  60. </a-button>
  61. </div>
  62. <!-- 表单 :scroll="{ y: tableHeight }" -->
  63. <a-table
  64. :columns="columns"
  65. :data-source="tableData"
  66. :row-key="(record) => record.id"
  67. :row-selection="{
  68. selectedRowKeys: selectedRowKeys,
  69. onChange: onSelectChange,
  70. getCheckboxProps: (record) => ({
  71. props: {
  72. disabled: record.disabled,
  73. },
  74. }),
  75. }"
  76. :pagination="false"
  77. >
  78. <template slot="examStatusTxt" slot-scope="text">
  79. <span
  80. :class="
  81. text === examStatusTypeTxt[0]
  82. ? 'exam-examStatus-green'
  83. : text === examStatusTypeTxt[1]
  84. ? 'exam-examStatus-yellow'
  85. : text === examStatusTypeTxt[2]
  86. ? 'exam-examStatus-red'
  87. : ''
  88. "
  89. >{{ text }}</span
  90. >
  91. </template>
  92. <template slot="action" slot-scope="text, record">
  93. <a @click="toQuestionDetailFun(record)">详情</a>
  94. <a-divider type="vertical" />
  95. <a
  96. :class="{
  97. 'exam-delete': true,
  98. 'exam-delete-disable': record.disabled,
  99. }"
  100. @click="deleteQuestionFun(record)"
  101. >删除</a
  102. >
  103. </template>
  104. </a-table>
  105. <!-- 分页 -->
  106. <div class="a-pagination-display">
  107. <a-pagination
  108. v-model="pagination.current"
  109. :pageSize="pagination.pageSize"
  110. :total.sync="pagination.total"
  111. show-less-items
  112. show-quick-jumper
  113. @change="getExamListFun"
  114. />
  115. </div>
  116. </div>
  117. </a-spin>
  118. <div class="company-info">
  119. <span>
  120. copyright © 浮游科技有限公司出品
  121. </span>
  122. </div>
  123. </div>
  124. </template>
  125. <script>
  126. import {
  127. formateUrlParams,
  128. formatePathParams,
  129. formatDateTimeT,
  130. formateExamStatesFun,
  131. formateEngineeringWork,
  132. } from '@/filters';
  133. import { mapGetters } from 'vuex';
  134. import {
  135. EXAM_TYPE,
  136. EXAM_STATUS_TYPE,
  137. EXAM_STATUS_TYPE_TXT,
  138. } from '@/common/Constant';
  139. export default {
  140. name: 'examManagementList',
  141. props: {},
  142. components: {},
  143. data() {
  144. return {
  145. loading: false, // 是否展示加载动画
  146. examType: [], // 考试类别列表
  147. checkedExamType: '', // 所选考试类别
  148. engineeringWorkList: [], // 工种数据列表
  149. engineeringWorkChooseValue: '', // 所选工种
  150. // tableHeight: 400, // 表格高度
  151. columns: [], // form表单的列参数
  152. tableData: [], // 表单数据
  153. pagination: {
  154. pageSize: 10,
  155. current: 1,
  156. total: 0,
  157. }, // 分页参数
  158. selectedRowKeys: [], // 多选的结果
  159. examStatusTypeTxt: EXAM_STATUS_TYPE_TXT, // 考试状态属性文字
  160. };
  161. },
  162. created() {
  163. this.initDataFun(); //初始化数据
  164. },
  165. mounted() {
  166. // this.initTableHeightFun(); // 初始化表单的高度
  167. },
  168. beforeDestroy() {},
  169. watch: {
  170. // screenHeight() {
  171. // this.initTableHeightFun(); // 初始化表单的高度
  172. // },
  173. },
  174. computed: {
  175. // 是否选择了数据
  176. ...mapGetters(['screenHeight', 'GET_ENGINEERING_WORK_LIST']),
  177. // 判断是否有行被选择
  178. hasSelected() {
  179. return this.selectedRowKeys.length > 0;
  180. },
  181. },
  182. methods: {
  183. // // 初始化表单的高度
  184. // initTableHeightFun() {
  185. // this.tableHeight =
  186. // this.$refs.tableBody.offsetHeight -
  187. // (this.$refs.filterCard.offsetHeight + 48 * 4);
  188. // },
  189. //初始化数据
  190. initDataFun() {
  191. this.loading = true;
  192. // 考试类别
  193. this.examType = [{ name: '全部', code: '' }, ...EXAM_TYPE];
  194. this.checkedExamType = this.examType[0].code;
  195. // 工种类别
  196. this.engineeringWorkList = [
  197. { name: '全部', id: '' },
  198. ...this.GET_ENGINEERING_WORK_LIST,
  199. ];
  200. this.engineeringWorkChooseValue = this.engineeringWorkList[0].id;
  201. // 表单的列的配置参数
  202. this.columns = [
  203. // {
  204. // title: '考试编号',
  205. // dataIndex: 'id',
  206. // key: 'id',
  207. // },
  208. {
  209. title: '考试名称',
  210. dataIndex: 'name',
  211. key: 'name',
  212. },
  213. {
  214. title: '考试时间',
  215. dataIndex: 'startTimeTxt',
  216. key: 'startTimeTxt',
  217. width: 200,
  218. },
  219. {
  220. title: '考试类型',
  221. dataIndex: 'examCategoryTxt',
  222. key: 'examCategoryTxt',
  223. width: 150,
  224. },
  225. {
  226. title: '工种',
  227. dataIndex: 'engineerTypeTxt',
  228. key: 'engineerTypeTxt',
  229. width: 200,
  230. },
  231. {
  232. title: '状态',
  233. dataIndex: 'examStatusTxt',
  234. key: 'examStatusTxt',
  235. scopedSlots: { customRender: 'examStatusTxt' },
  236. width: 150,
  237. },
  238. {
  239. title: '操作',
  240. dataIndex: 'action',
  241. key: 'action',
  242. scopedSlots: { customRender: 'action' },
  243. width: 150,
  244. },
  245. ];
  246. this.getExamListFun(); // 查询:试题列表数据
  247. },
  248. // 初始化分页参数
  249. initPagination() {
  250. this.pagination.current = 1;
  251. this.pagination.pageSize = 10;
  252. this.pagination.total = 0;
  253. },
  254. // 操作:选择某个试题类型
  255. handleExamQuestionTypeFun(item) {
  256. if (this.checkedExamType === item.code) {
  257. return;
  258. }
  259. this.checkedExamType = item.code;
  260. this.initPagination(); // 初始化分页参数
  261. this.getExamListFun(); // 查询:试题列表数据
  262. },
  263. // 操作:选择了某个工种
  264. handleChangeEngineeringWorkValue() {
  265. this.initPagination(); // 初始化分页参数
  266. this.getExamListFun(); // 查询:试题列表数据
  267. },
  268. // 查询:试题列表数据
  269. getExamListFun() {
  270. this.loading = true;
  271. let params = {
  272. page: this.pagination.current - 1,
  273. size: this.pagination.pageSize,
  274. category: this.checkedExamType, // 考试类型
  275. engineertypeid: this.engineeringWorkChooseValue, // 工种类别
  276. };
  277. this.$_http
  278. .get(formateUrlParams(this.$_API.INTERFACE_GET_EXAMS, params))
  279. .then((res) => {
  280. let resData = res.data.content;
  281. resData.forEach((item) => {
  282. item.startTimeTxt = formatDateTimeT(item.startTime);
  283. let obj = formateExamStatesFun(item.startTime, item.deadline);
  284. item.examStatus = obj.examStatus;
  285. item.examStatusTxt = obj.examStatusTxt;
  286. item.disabled =
  287. item.examStatus !== EXAM_STATUS_TYPE.NOT_START ? true : false; // 未开始的才能删除
  288. // 工种
  289. if (item.engineerTypes) {
  290. let findItem = formateEngineeringWork(
  291. this.engineeringWorkList,
  292. item.engineerTypes[0]
  293. );
  294. item.engineerTypeTxt = findItem.name;
  295. } else {
  296. item.engineerTypeTxt = '不限';
  297. }
  298. // 考试类型
  299. EXAM_TYPE.forEach((examType) => {
  300. if (item.examCategory === examType.code) {
  301. item.examCategoryTxt = examType.name;
  302. }
  303. });
  304. });
  305. this.tableData = resData;
  306. this.pagination.total = res.data.totalElements; // 总条数
  307. this.loading = false;
  308. })
  309. .catch(() => {
  310. this.loading = false;
  311. });
  312. },
  313. // 操作:详情
  314. toQuestionDetailFun(record) {
  315. if (!record.id) {
  316. this.$message.error('试题数据异常');
  317. this.initPagination(); // 初始化分页参数
  318. this.getExamListFun(); // 查询:试题列表数据
  319. return;
  320. }
  321. this.$router.push({
  322. path: '/examManagement/list/detail',
  323. query: { id: record.id },
  324. });
  325. },
  326. // 操作:删除
  327. deleteQuestionFun(record) {
  328. if (record.disabled) {
  329. return;
  330. }
  331. let that = this;
  332. this.$confirm({
  333. title: '删除',
  334. content: `确认删除考试名为 ${record.name} 的考试吗?`,
  335. okText: '确认',
  336. cancelText: '取消',
  337. onOk() {
  338. let params = {
  339. examId: record.id,
  340. };
  341. that.$_http
  342. .delete(formatePathParams(that.$_API.INTERFACE_DELETE_EXAM, params))
  343. .then(() => {
  344. that.loading = false;
  345. that.$message.success('删除试题成功');
  346. that.initPagination(); // 初始化分页参数
  347. that.getExamListFun(); // 查询:试题列表数据
  348. })
  349. .catch(() => {
  350. that.loading = false;
  351. });
  352. },
  353. onCancel() {},
  354. });
  355. },
  356. // 操作:清空选择
  357. handleClearSelectDataFun() {
  358. this.selectedRowKeys = [];
  359. },
  360. // 操作:多选变化时
  361. onSelectChange(selectedRowKeys) {
  362. this.selectedRowKeys = selectedRowKeys;
  363. },
  364. // 操作:批量删除
  365. handleDeleteSelectDataFun() {
  366. let that = this;
  367. this.$confirm({
  368. title: '批量删除',
  369. content: `确认批量删除考试吗?`,
  370. okText: '确认',
  371. cancelText: '取消',
  372. onOk() {
  373. that.loading = true;
  374. that.$_http
  375. .delete(that.$_API.INTERFACE_DELETE_EXAMS, {
  376. data: that.selectedRowKeys,
  377. })
  378. .then(() => {
  379. that.selectedRowKeys = [];
  380. that.loading = false;
  381. that.$message.success('批量删除试题成功');
  382. that.initPagination(); // 初始化分页参数
  383. that.getExamListFun(); // 查询:试题列表数据
  384. })
  385. .catch(() => {
  386. that.loading = false;
  387. });
  388. },
  389. onCancel() {},
  390. });
  391. },
  392. },
  393. };
  394. </script>
  395. <style lang="less"></style>
  396. <style lang="less" scoped>
  397. @import '~@/styles/common/variable.less';
  398. .app-container {
  399. .filter-condition-box {
  400. display: flex;
  401. align-items: center;
  402. ul {
  403. margin: 0;
  404. display: flex;
  405. li {
  406. margin-left: @paddingMarginVal;
  407. color: @mainColorBlack65;
  408. cursor: pointer;
  409. &:hover {
  410. color: @mainColorBlueNormal;
  411. }
  412. }
  413. .checkedExamType {
  414. color: @mainColorBlueNormal;
  415. font-weight: bold;
  416. }
  417. }
  418. }
  419. .filter-other-box {
  420. width: 100%;
  421. display: flex;
  422. align-items: center;
  423. .filter-other-title {
  424. color: @mainColorBlack85;
  425. }
  426. .filter-other-item-title {
  427. margin-left: @paddingMarginVal;
  428. color: @mainColorBlack65;
  429. }
  430. }
  431. .exam-edit-row {
  432. margin-bottom: @paddingMarginVal;
  433. .exam-edit-checkedtxt {
  434. margin-left: @paddingMarginVal;
  435. }
  436. .exam-edit-delete {
  437. margin-left: @paddingMarginVal;
  438. }
  439. }
  440. .exam-examStatus-green {
  441. color: #58e206;
  442. }
  443. .exam-examStatus-yellow {
  444. color: #ff8d1a;
  445. }
  446. .exam-examStatus-red {
  447. color: #d43030;
  448. }
  449. .exam-delete {
  450. cursor: pointer;
  451. }
  452. .exam-delete-disable {
  453. cursor: no-drop;
  454. color: #a6a6a6;
  455. }
  456. }
  457. </style>