examStudentImport.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <section class="content" style="margin-top: -10px;">
  3. <div class="box box-info">
  4. <!-- 正文信息 -->
  5. <div class="box-body">
  6. <div style="margin-top: 20px;">
  7. <el-button
  8. size="small"
  9. type="primary"
  10. icon="el-icon-upload2"
  11. @click="imp"
  12. >导入
  13. </el-button>
  14. </div>
  15. <div style="width: 100%;margin-bottom: 10px;"></div>
  16. <!-- 导入弹窗 -->
  17. <el-dialog
  18. title="考生信息导入页"
  19. size="tiny"
  20. :visible.sync="studentImportDialog"
  21. >
  22. <el-form :model="studentImportForm" ref="studentImportForm">
  23. <el-row>
  24. <el-form-item style="margin-left:30px" label="考试" prop="value">
  25. <el-select
  26. class="input"
  27. :remote-method="queryExams"
  28. remote
  29. :loading="queryExamsLoading"
  30. filterable
  31. clearable
  32. v-model="studentImportForm.examId"
  33. placeholder="请选择"
  34. >
  35. <el-option
  36. v-for="item in examList"
  37. :label="item.name"
  38. :value="item.id"
  39. :key="item.id"
  40. :disabled="!item.enable"
  41. >
  42. </el-option>
  43. </el-select>
  44. </el-form-item>
  45. </el-row>
  46. <el-row>
  47. <el-form-item style="margin-left:30px">
  48. <el-upload
  49. class="form_left"
  50. ref="upload"
  51. accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  52. :action="uploadAction"
  53. :headers="uploadHeaders"
  54. :data="uploadData"
  55. :before-upload="beforeUpload"
  56. :on-progress="uploadProgress"
  57. :on-success="uploadSuccess"
  58. :on-error="uploadError"
  59. :file-list="fileList"
  60. :auto-upload="false"
  61. :multiple="false"
  62. >
  63. <el-button
  64. size="small"
  65. slot="trigger"
  66. type="primary"
  67. icon="el-icon-search"
  68. >选择文件</el-button
  69. >
  70. <el-button
  71. size="small"
  72. style="margin-left:10px;"
  73. type="primary"
  74. @click="submitUpload"
  75. icon="el-icon-check"
  76. >确认上传
  77. </el-button>
  78. <el-button
  79. size="small"
  80. style="margin-left: 10px;"
  81. type="primary"
  82. @click="removeFile"
  83. icon="el-icon-refresh"
  84. >清空文件
  85. </el-button>
  86. <el-button
  87. size="small"
  88. type="primary"
  89. @click="exportFile"
  90. icon="el-icon-download"
  91. >下载模板
  92. </el-button>
  93. <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
  94. </el-upload>
  95. </el-form-item>
  96. </el-row>
  97. </el-form>
  98. </el-dialog>
  99. <!-- 页面列表 -->
  100. <el-table
  101. :data="tableData"
  102. border
  103. style="width: 100%;text-align:center;"
  104. >
  105. <el-table-column
  106. prop="id"
  107. width="50"
  108. label="ID"
  109. sortable
  110. ></el-table-column>
  111. <el-table-column prop="rootOrgName" label="学校" sortable>
  112. </el-table-column>
  113. <el-table-column prop="examName" label="考试" sortable>
  114. </el-table-column>
  115. <el-table-column prop="fileName" label="上传文件名" sortable>
  116. </el-table-column>
  117. <el-table-column prop="statusDesc" width="120" label="状态">
  118. </el-table-column>
  119. <el-table-column prop="errorDesc" label="异常"> </el-table-column>
  120. <el-table-column
  121. prop="creationTime"
  122. width="170"
  123. label="上传时间"
  124. sortable
  125. >
  126. </el-table-column>
  127. <el-table-column label="操作" width="230">
  128. <template slot-scope="scope">
  129. <div>
  130. <el-button
  131. size="mini"
  132. type="primary"
  133. plain
  134. icon="el-icon-download"
  135. @click="getUploadedFile(scope.row.id)"
  136. >下载文件
  137. </el-button>
  138. <el-button
  139. :disabled="
  140. !(
  141. scope.row.status == 'DATA_PROCESSING_COMPLETE' ||
  142. scope.row.status == 'ERROR'
  143. )
  144. "
  145. size="mini"
  146. type="primary"
  147. plain
  148. icon="el-icon-download"
  149. @click="getReports(scope.row.id)"
  150. >导出报告
  151. </el-button>
  152. </div>
  153. </template>
  154. </el-table-column>
  155. </el-table>
  156. <div class="page pull-right">
  157. <el-pagination
  158. @current-change="handleCurrentChange"
  159. :current-page="currentPage"
  160. :page-size="pageSize"
  161. :page-sizes="[10, 20, 50, 100, 200, 300]"
  162. @size-change="handleSizeChange"
  163. layout="total, sizes, prev, pager, next, jumper"
  164. :total="total"
  165. >
  166. </el-pagination>
  167. </div>
  168. </div>
  169. </div>
  170. </section>
  171. </template>
  172. <style scoped></style>
  173. <script>
  174. import { TASK_API, EXAM_WORK_API } from "@/constants/constants.js";
  175. import { mapState } from "vuex";
  176. let _this = null;
  177. export default {
  178. data() {
  179. return {
  180. formSearch: {},
  181. uploadAction: TASK_API + "/examStudentImport/import",
  182. studentImportDialog: false,
  183. examList: [],
  184. uploadHeaders: {},
  185. uploadData: { examId: "" },
  186. fileList: [],
  187. fileLoading: false,
  188. queryExamsLoading: false,
  189. studentImportForm: {
  190. examId: null
  191. },
  192. tableData: [],
  193. currentPage: 1,
  194. pageSize: 10,
  195. total: 0
  196. };
  197. },
  198. computed: {
  199. ...mapState({ user: state => state.user })
  200. },
  201. methods: {
  202. handleCurrentChange(val) {
  203. this.currentPage = val;
  204. this.queryTableDatas();
  205. },
  206. handleSizeChange(val) {
  207. this.pageSize = val;
  208. this.queryTableDatas();
  209. },
  210. imp() {
  211. this.studentImportDialog = true;
  212. this.initUpload();
  213. },
  214. initUpload() {
  215. if (this.$refs.studentImportForm) {
  216. this.$refs.studentImportForm.resetFields();
  217. }
  218. this.fileList = [];
  219. this.studentImportForm.examId = null;
  220. this.examList = [];
  221. this.queryExams("");
  222. },
  223. beforeUpload(file) {
  224. console.log(file);
  225. },
  226. uploadProgress(event, file, fileList) {
  227. console.log("uploadProgress");
  228. console.log(event);
  229. console.log(file);
  230. console.log(fileList);
  231. },
  232. uploadSuccess(response, file, fileList) {
  233. console.log("uploadSuccess");
  234. console.log(response);
  235. console.log(file);
  236. console.log(fileList);
  237. this.$notify({
  238. message: "上传成功",
  239. type: "success"
  240. });
  241. this.fileLoading = false;
  242. this.studentImportDialog = false;
  243. this.queryTableDatas();
  244. },
  245. uploadError(response, file, fileList) {
  246. console.log("uploadError");
  247. console.log(response);
  248. console.log(file);
  249. console.log(fileList);
  250. var json = JSON.parse(response.message);
  251. if (response.status == 500) {
  252. this.$notify({
  253. message: json.desc,
  254. type: "error"
  255. });
  256. }
  257. this.fileLoading = false;
  258. },
  259. //确定上传
  260. submitUpload() {
  261. if (!this.checkUpload()) {
  262. return false;
  263. }
  264. this.$refs.upload.submit();
  265. this.fileLoading = true;
  266. },
  267. checkUpload() {
  268. if (!this.studentImportForm.examId) {
  269. this.$notify({
  270. message: "请选择考试批次",
  271. type: "error"
  272. });
  273. return false;
  274. } else {
  275. this.uploadData.examId = this.studentImportForm.examId;
  276. }
  277. var fileList = this.$refs.upload.uploadFiles;
  278. if (fileList.length == 0) {
  279. this.$notify({
  280. message: "上传文件不能为空",
  281. type: "error"
  282. });
  283. return false;
  284. }
  285. if (fileList.length > 1) {
  286. this.$notify({
  287. message: "每次只能上传一个文件",
  288. type: "error"
  289. });
  290. return false;
  291. }
  292. for (let file of fileList) {
  293. if (!file.name.endsWith(".xlsx")) {
  294. this.$notify({
  295. message: "上传文件必须为xlsx格式",
  296. type: "error"
  297. });
  298. this.initUpload();
  299. return false;
  300. }
  301. }
  302. return true;
  303. },
  304. //清空文件
  305. removeFile() {
  306. this.$refs.upload.clearFiles();
  307. },
  308. //下载模板
  309. exportFile() {
  310. window.location.href =
  311. "/api/ecs_exam_work/exam_student/downloadTemplate?$key=" +
  312. this.user.key +
  313. "&$token=" +
  314. this.user.token;
  315. },
  316. //下载报告
  317. getReports(id) {
  318. window.location.href =
  319. TASK_API +
  320. "/examStudentImport/getReports/" +
  321. id +
  322. "?$key=" +
  323. this.user.key +
  324. "&$token=" +
  325. this.user.token;
  326. },
  327. //下载导入文件
  328. getUploadedFile(id) {
  329. window.location.href =
  330. TASK_API +
  331. "/examStudentImport/getUploadedFile/" +
  332. id +
  333. "?$key=" +
  334. this.user.key +
  335. "&$token=" +
  336. this.user.token;
  337. },
  338. queryExams(name) {
  339. console.log("queryExams; name: " + name);
  340. this.queryExamsLoading = true;
  341. this.$httpWithMsg
  342. .get(EXAM_WORK_API + "/exam/queryByNameLike?name=" + name)
  343. .then(response => {
  344. this.queryExamsLoading = false;
  345. this.examList = response.data;
  346. })
  347. .catch(() => {
  348. this.queryExamsLoading = false;
  349. });
  350. },
  351. queryTableDatas: function() {
  352. var url =
  353. TASK_API +
  354. "/examStudentImport/all/" +
  355. (this.currentPage - 1) +
  356. "/" +
  357. this.pageSize;
  358. this.$httpWithMsg.get(url).then(response => {
  359. console.log(response);
  360. _this.tableData = response.data.list;
  361. _this.total = response.data.total;
  362. });
  363. }
  364. },
  365. created() {
  366. _this = this;
  367. this.queryTableDatas();
  368. this.uploadHeaders = {
  369. key: this.user.key,
  370. token: this.user.token
  371. };
  372. }
  373. };
  374. </script>