newYY.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <div id="newYY">
  3. <div style="margin-bottom: 12px">
  4. <span style="font-size: 14px">第一步:</span>
  5. <el-select
  6. :style="marSty"
  7. :size="size"
  8. filterable
  9. v-model="formData.applyId"
  10. placeholder="请选择考试计划(必填)"
  11. >
  12. <el-option
  13. v-for="item in examList"
  14. :key="item.applyId"
  15. :label="item.applyName"
  16. :value="item.applyId"
  17. >
  18. </el-option>
  19. </el-select>
  20. <el-select
  21. :style="marSty"
  22. :size="size"
  23. filterable
  24. v-model="formData.applySiteAddress"
  25. placeholder="请选择考试地点(必填)"
  26. >
  27. <el-option
  28. v-for="item in applySiteAddress"
  29. :key="item.siteId"
  30. :label="item.siteAddress"
  31. :value="item.siteAddress"
  32. >
  33. </el-option>
  34. </el-select>
  35. <el-button
  36. :size="size"
  37. type="warning"
  38. @click="downModel(1)"
  39. style="margin-right: 10px"
  40. >下载模板(不含考培)</el-button
  41. >
  42. <el-select
  43. :style="marSty"
  44. :size="size"
  45. clearable
  46. filterable
  47. v-model="formData.applySiteAddressTrain"
  48. placeholder="请选择考培地点(必填)"
  49. >
  50. <el-option
  51. v-for="item in applySiteAddress"
  52. :key="item.siteId"
  53. :label="item.siteAddress"
  54. :value="item.siteAddress"
  55. >
  56. </el-option>
  57. </el-select>
  58. <el-button :size="size" type="warning" @click="downModel(2)"
  59. >下载模板(含考培)</el-button
  60. >
  61. </div>
  62. <div style="margin-bottom: 12px">
  63. <span style="font-size: 14px">第二步:</span>
  64. <label
  65. for="mobles"
  66. class="el-button el-button--success el-button--mini"
  67. style="margin-right: 10px"
  68. >批量导入(不含考培)</label
  69. ><input
  70. style="display: none"
  71. type="file"
  72. id="mobles"
  73. ref="input1"
  74. @change="importMobleadd"
  75. />
  76. <label
  77. for="mobles2"
  78. class="el-button el-button--success el-button--mini"
  79. style="margin-right: 10px"
  80. >批量导入(含考培)</label
  81. ><input
  82. style="display: none"
  83. type="file"
  84. id="mobles2"
  85. ref="input2"
  86. @change="importMobleaddtrain"
  87. />
  88. </div>
  89. <div>
  90. <el-badge
  91. :hidden="!tableDataSuccess.length"
  92. :value="tableDataSuccess.length"
  93. class="item"
  94. >
  95. <el-button
  96. :size="size"
  97. :type="active === 1 ? 'primary' : ''"
  98. @click="active = 1"
  99. >成功导入</el-button
  100. >
  101. </el-badge>
  102. <el-badge
  103. :hidden="!tableDataError.length"
  104. :value="tableDataError.length"
  105. class="item"
  106. >
  107. <el-button
  108. :size="size"
  109. :type="active === 2 ? 'primary' : ''"
  110. @click="active = 2"
  111. >失败导入</el-button
  112. >
  113. </el-badge>
  114. </div>
  115. <div v-show="active === 1" class="exportBox">
  116. <h4 class="h4Sty">
  117. 成功导入<strong style="color: red">{{ tableDataSuccess.length }}</strong
  118. >人
  119. </h4>
  120. <el-table
  121. max-height="600"
  122. :data="tableDataSuccess"
  123. style="width: 100%"
  124. border
  125. :header-cell-style="{
  126. 'background-color': '#eee',
  127. color: '#333',
  128. fontSize: '14px',
  129. }"
  130. >
  131. <af-table-column
  132. v-for="(item, index) in computedForm(tableSet, 1)"
  133. :key="index"
  134. :prop="item.prop"
  135. :label="item.label"
  136. :width="item.width"
  137. align="center"
  138. >
  139. <template slot-scope="scope">
  140. <div v-if="item.scope === 'time'">
  141. <div>{{ scope.row[item.prop1] }}</div>
  142. <div>{{ scope.row[item.prop2] }} {{ scope.row[item.prop3] }}</div>
  143. </div>
  144. <div v-else-if="item.scope === 'StudentType'">
  145. {{scope.row[item.prop] == 1 ? '非补考学员':scope.row[item.prop] == 2 ? '补考学员':''}}
  146. </div>
  147. <span v-else>{{ scope.row[item.prop] }}</span>
  148. </template>
  149. </af-table-column>
  150. </el-table>
  151. </div>
  152. <div v-show="active === 2" class="exportBox">
  153. <h4 class="h4Sty">
  154. 失败导入<strong style="color: red">{{ tableDataError.length }}</strong
  155. >人
  156. <el-button
  157. v-if="tableDataError.length"
  158. style="margin-left: 10px"
  159. :size="size"
  160. type="success"
  161. @click="dowmErrorData"
  162. >下载失败数据</el-button
  163. >
  164. </h4>
  165. <el-table
  166. max-height="600"
  167. :data="tableDataError"
  168. style="width: 100%"
  169. border
  170. :header-cell-style="{
  171. 'background-color': '#eee',
  172. color: '#333',
  173. fontSize: '14px',
  174. }"
  175. >
  176. <af-table-column
  177. v-for="(item, index) in computedForm(tableSet, 2)"
  178. :key="index"
  179. :prop="item.prop"
  180. :label="item.label"
  181. :width="item.width"
  182. align="center"
  183. >
  184. <template slot-scope="scope">
  185. <div v-if="item.scope === 'time'">
  186. <div>{{ scope.row[item.prop1] }}</div>
  187. <div>
  188. {{ changeDatas(scope.row[item.prop2]) }}
  189. {{ scope.row[item.prop3] }}
  190. </div>
  191. </div>
  192. <div v-else-if="item.scope === 'StudentType'">
  193. {{scope.row[item.prop] == 1 ? '非补考学员':scope.row[item.prop] == 2 ? '补考学员':''}}
  194. </div>
  195. <span v-else>{{ scope.row[item.prop] }}</span>
  196. </template>
  197. </af-table-column>
  198. </el-table>
  199. </div>
  200. </div>
  201. </template>
  202. <script>
  203. import * as baseUrls from "@/utils/request.js";
  204. import { mapGetters } from "vuex";
  205. export default {
  206. data() {
  207. return {
  208. typeInt: 1,
  209. active: 1,
  210. marSty: { marginRight: "10px" },
  211. size: "mini",
  212. formData: {
  213. applyId: "",
  214. applySiteAddress: "",
  215. applySiteAddressTrain: "",
  216. },
  217. tableDataSuccess: [],
  218. tableDataError: [],
  219. tableSet: [
  220. {
  221. label: "学员姓名",
  222. prop: "userName",
  223. },
  224. {
  225. label: "学员身份证",
  226. prop: "idCard",
  227. },
  228. {
  229. label: "学员报名类型",
  230. prop: "studentTypeName",
  231. scope: "StudentType",
  232. },
  233. {
  234. label: "商品编码",
  235. prop: "code",
  236. },
  237. {
  238. label: "所购商品",
  239. prop: "goodsName",
  240. },
  241. {
  242. label: "考试标题",
  243. prop: "applyName",
  244. },
  245. {
  246. label: "预约场次(考试地点和时间)",
  247. prop1: "applySiteAddress",
  248. prop2: "applySiteExamTime",
  249. prop3: "applySiteTime",
  250. scope: "time",
  251. },
  252. {
  253. label: "预约场次(考培地点和时间)",
  254. prop1: "applySiteAddressTrain",
  255. prop2: "applySiteExamTrainTime",
  256. prop3: "applySiteTrainTime",
  257. scope: "time",
  258. },
  259. {
  260. label: "出错原因",
  261. prop: "cause",
  262. width:"",
  263. hidden: true,
  264. width:"260px"
  265. },
  266. ],
  267. };
  268. },
  269. computed: {
  270. ...mapGetters(["examList", "applySiteAddress"]),
  271. computedForm: function () {
  272. return function (tabs, int) {
  273. if (int === 1) {
  274. const ays = tabs.filter((item) => {
  275. if (this.typeInt === 1) {
  276. return (
  277. item.label !== "预约场次(考培地点和时间)" && !item.hidden
  278. );
  279. } else {
  280. return !item.hidden;
  281. }
  282. });
  283. return ays;
  284. } else {
  285. const ays = tabs.filter((item) => {
  286. if (this.typeInt === 1) {
  287. return item.label !== "预约场次(考培地点和时间)";
  288. } else {
  289. return item;
  290. }
  291. });
  292. return ays;
  293. }
  294. };
  295. },
  296. },
  297. methods: {
  298. /**
  299. * 转换时间格式
  300. */
  301. changeDatas(time) {
  302. if (time) {
  303. var datas = this.$methodsTools.onlyForma(
  304. new Date(time).getTime() / 1000,
  305. false
  306. );
  307. return datas;
  308. } else {
  309. return "";
  310. }
  311. },
  312. /**
  313. * 下载错误数据
  314. */
  315. dowmErrorData() {
  316. switch (this.typeInt) {
  317. case 1:
  318. this.$api
  319. .inquiresystemsubscribeexportErrorNew(this.tableDataError)
  320. .then((res) => {
  321. let url =
  322. baseUrls.baseURL + "common/download?fileName=" + res.msg;
  323. let link = document.createElement("a");
  324. let fileName = "导入模板" + ".xlsx";
  325. document.body.appendChild(link);
  326. link.href = url;
  327. link.dowmload = fileName;
  328. link.click();
  329. link.remove();
  330. });
  331. break;
  332. case 2:
  333. this.$api
  334. .inquiresystemsubscribeexportexportErrorTrain(this.tableDataError)
  335. .then((res) => {
  336. let url =
  337. baseUrls.baseURL + "common/download?fileName=" + res.msg;
  338. let link = document.createElement("a");
  339. let fileName = "导入模板" + ".xlsx";
  340. document.body.appendChild(link);
  341. link.href = url;
  342. link.dowmload = fileName;
  343. link.click();
  344. link.remove();
  345. });
  346. break;
  347. default:
  348. break;
  349. }
  350. },
  351. /**
  352. *
  353. * @param {Number} int 下载模板
  354. */
  355. downModel(int) {
  356. if (!this.formData.applyId) {
  357. this.$message.warning("请选择考试计划");
  358. return;
  359. }
  360. if (!this.formData.applySiteAddress) {
  361. this.$message.warning("请选择考试地点");
  362. return;
  363. }
  364. if (int === 2 && !this.formData.applySiteAddressTrain) {
  365. this.$message.warning("请选择考培地点");
  366. return;
  367. }
  368. var data = JSON.parse(JSON.stringify(this.formData));
  369. if (int === 1) {
  370. delete data.applySiteAddressTrain;
  371. }
  372. const indexs = this.examList.findIndex((item) => {
  373. return item.applyId == data.applyId;
  374. });
  375. data.applyName = this.examList[indexs].applyName;
  376. this.$api.inquiresystemsubscribeexportNew(data).then(async (res) => {
  377. for (let k in res.data) {
  378. if (res.data[k].code === 200) {
  379. await this.dowmFunc(res, k);
  380. } else {
  381. this.$message.error("code值错误:", res.data[k].code);
  382. }
  383. }
  384. });
  385. },
  386. dowmFunc(res, k) {
  387. return new Promise((resolve, reject) => {
  388. let url =
  389. baseUrls.baseURL + "common/download?fileName=" + res.data[k].msg;
  390. let link = document.createElement("a");
  391. let fileName = "导入模板" + ".xlsx";
  392. document.body.appendChild(link);
  393. link.href = url;
  394. link.dowmload = fileName;
  395. link.click();
  396. link.remove();
  397. setTimeout(() => {
  398. resolve();
  399. }, 200);
  400. });
  401. },
  402. /**
  403. *
  404. * @param {event} e 不含考培导入模板
  405. */
  406. importMobleadd(e) {
  407. var file = e.target.files[0];
  408. let formData = new FormData();
  409. formData.append("file", file);
  410. this.$api
  411. .editsystemsubscribeimportData(formData)
  412. .then((res) => {
  413. this.tableDataSuccess = res.data.successList;
  414. this.tableDataError = res.data.errorList;
  415. this.typeInt = 1;
  416. this.$message.info("导入操作执行成功")
  417. })
  418. .finally(() => {
  419. e.target.value = "";
  420. });
  421. },
  422. /**
  423. *
  424. * @param {event} e 含考培导入模板
  425. */
  426. importMobleaddtrain(e) {
  427. var file = e.target.files[0];
  428. let formData = new FormData();
  429. formData.append("file", file);
  430. this.$api
  431. .editsystemsubscribeimportTrainData(formData)
  432. .then((res) => {
  433. this.tableDataSuccess = res.data.successList;
  434. this.tableDataError = res.data.errorList;
  435. this.typeInt = 2;
  436. this.$message.info("导入操作执行成功")
  437. })
  438. .finally(() => {
  439. e.target.value = "";
  440. });
  441. },
  442. },
  443. };
  444. </script>
  445. <style lang="less" scoped>
  446. .h4Sty {
  447. margin: 6px;
  448. font-size: 14px;
  449. }
  450. .exportBox {
  451. border: 1px solid #999;
  452. padding: 10px;
  453. margin-top: 10px;
  454. border-radius: 4px;
  455. }
  456. /deep/.el-button {
  457. border-radius: 8px;
  458. }
  459. /deep/.el-dialog {
  460. border-radius: 8px;
  461. .el-dialog__header {
  462. padding: 0;
  463. .hearders {
  464. height: 40px;
  465. display: flex;
  466. align-items: center;
  467. justify-content: space-between;
  468. padding: 0px 18px 0px 20px;
  469. border-bottom: 1px solid #e2e2e2;
  470. .leftTitle {
  471. font-size: 14px;
  472. font-weight: bold;
  473. color: #2f4378;
  474. }
  475. .rightBoxs {
  476. display: flex;
  477. align-items: center;
  478. img {
  479. width: 14px;
  480. height: 14px;
  481. margin-left: 13px;
  482. cursor: pointer;
  483. }
  484. }
  485. }
  486. }
  487. .el-dialog__footer {
  488. padding: 0;
  489. .dialog-footer {
  490. padding: 0px 40px;
  491. height: 70px;
  492. border-top: 1px solid #e2e2e2;
  493. display: flex;
  494. align-items: center;
  495. justify-content: flex-end;
  496. }
  497. }
  498. }
  499. .imgBox {
  500. width: 100%;
  501. // height: 210px;
  502. border: 1px solid #e2e2e2;
  503. border-radius: 8px;
  504. padding: 8px 8px 3px;
  505. display: flex;
  506. flex-direction: column;
  507. align-items: center;
  508. .imgLabel {
  509. flex: 1;
  510. width: 100%;
  511. border: 1px dotted #e2e2e2;
  512. color: #999;
  513. font-size: 14px;
  514. cursor: pointer;
  515. border-radius: 8px;
  516. .msPhoto {
  517. display: flex;
  518. justify-content: center;
  519. align-items: center;
  520. max-width: 100%;
  521. max-height: 270px;
  522. img {
  523. max-width: 100%;
  524. max-height: 270px;
  525. }
  526. }
  527. .imgbbx {
  528. display: flex;
  529. flex-direction: column;
  530. align-items: center;
  531. justify-content: center;
  532. width: 100%;
  533. height: 100%;
  534. i {
  535. font-weight: bold;
  536. margin: 14px 0;
  537. font-size: 24px;
  538. }
  539. }
  540. }
  541. p {
  542. margin: 5px 0px;
  543. }
  544. }
  545. .item {
  546. margin-top: 10px;
  547. margin-right: 20px;
  548. }
  549. </style>