newYY.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. <el-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. <span v-else>{{ scope.row[item.prop] }}</span>
  145. </template>
  146. </el-table-column>
  147. </el-table>
  148. </div>
  149. <div v-show="active === 2" class="exportBox">
  150. <h4 class="h4Sty">
  151. 失败导入<strong style="color: red">{{ tableDataError.length }}</strong
  152. >人
  153. <el-button
  154. v-if="tableDataError.length"
  155. style="margin-left: 10px"
  156. :size="size"
  157. type="success"
  158. @click="dowmErrorData"
  159. >下载失败数据</el-button
  160. >
  161. </h4>
  162. <el-table
  163. max-height="600"
  164. :data="tableDataError"
  165. style="width: 100%"
  166. border
  167. :header-cell-style="{
  168. 'background-color': '#eee',
  169. color: '#333',
  170. fontSize: '14px',
  171. }"
  172. >
  173. <el-table-column
  174. v-for="(item, index) in computedForm(tableSet, 2)"
  175. :key="index"
  176. :prop="item.prop"
  177. :label="item.label"
  178. :width="item.width"
  179. align="center"
  180. >
  181. <template slot-scope="scope">
  182. <div v-if="item.scope === 'time'">
  183. <div>{{ scope.row[item.prop1] }}</div>
  184. <div>
  185. {{ changeDatas(scope.row[item.prop2]) }}
  186. {{ scope.row[item.prop3] }}
  187. </div>
  188. </div>
  189. <span v-else>{{ scope.row[item.prop] }}</span>
  190. </template>
  191. </el-table-column>
  192. </el-table>
  193. </div>
  194. </div>
  195. </template>
  196. <script>
  197. import * as baseUrls from "@/utils/request.js";
  198. import { mapGetters } from "vuex";
  199. export default {
  200. data() {
  201. return {
  202. typeInt: 1,
  203. active: 1,
  204. marSty: { marginRight: "10px" },
  205. size: "mini",
  206. formData: {
  207. applyId: "",
  208. applySiteAddress: "",
  209. applySiteAddressTrain: "",
  210. },
  211. tableDataSuccess: [],
  212. tableDataError: [],
  213. tableSet: [
  214. {
  215. label: "学员姓名",
  216. prop: "userName",
  217. },
  218. {
  219. label: "学员身份证",
  220. prop: "idCard",
  221. },
  222. {
  223. label: "商品编码",
  224. prop: "code",
  225. width: "120px",
  226. },
  227. {
  228. label: "所购商品",
  229. prop: "goodsName",
  230. width: "180px",
  231. },
  232. {
  233. label: "考试安排",
  234. prop: "applyName",
  235. width: "140px",
  236. },
  237. {
  238. label: "预约场次(考试地点和时间)",
  239. prop1: "applySiteAddress",
  240. prop2: "applySiteExamTime",
  241. prop3: "applySiteTime",
  242. scope: "time",
  243. width: "240px",
  244. },
  245. {
  246. label: "预约场次(考培地点和时间)",
  247. prop1: "applySiteAddressTrain",
  248. prop2: "applySiteExamTrainTime",
  249. prop3: "applySiteTrainTime",
  250. scope: "time",
  251. width: "240px",
  252. },
  253. {
  254. label: "出错原因",
  255. prop: "cause",
  256. hidden: true,
  257. },
  258. ],
  259. };
  260. },
  261. computed: {
  262. ...mapGetters(["examList", "applySiteAddress"]),
  263. computedForm: function () {
  264. return function (tabs, int) {
  265. if (int === 1) {
  266. const ays = tabs.filter((item) => {
  267. if (this.typeInt === 1) {
  268. return (
  269. item.label !== "预约场次(考培地点和时间)" && !item.hidden
  270. );
  271. } else {
  272. return !item.hidden;
  273. }
  274. });
  275. return ays;
  276. } else {
  277. const ays = tabs.filter((item) => {
  278. if (this.typeInt === 1) {
  279. return item.label !== "预约场次(考培地点和时间)";
  280. } else {
  281. return item;
  282. }
  283. });
  284. return ays;
  285. }
  286. };
  287. },
  288. },
  289. methods: {
  290. /**
  291. * 转换时间格式
  292. */
  293. changeDatas(time) {
  294. if (time) {
  295. var datas = this.$methodsTools.onlyForma(
  296. new Date(time).getTime() / 1000,
  297. false
  298. );
  299. return datas;
  300. } else {
  301. return "";
  302. }
  303. },
  304. /**
  305. * 下载错误数据
  306. */
  307. dowmErrorData() {
  308. this.$api
  309. .inquiresystemsubscribeexportErrorNew(this.tableDataError)
  310. .then((res) => {
  311. let url = baseUrls.baseURL + "common/download?fileName=" + res.msg;
  312. let link = document.createElement("a");
  313. let fileName = "导入模板" + ".xlsx";
  314. document.body.appendChild(link);
  315. link.href = url;
  316. link.dowmload = fileName;
  317. link.click();
  318. link.remove();
  319. });
  320. },
  321. /**
  322. *
  323. * @param {Number} int 下载模板
  324. */
  325. downModel(int) {
  326. if (!this.formData.applyId) {
  327. this.$message.warning("请选择考试计划");
  328. return;
  329. }
  330. if (!this.formData.applySiteAddress) {
  331. this.$message.warning("请选择考试地点");
  332. return;
  333. }
  334. if (int === 2 && !this.formData.applySiteAddressTrain) {
  335. this.$message.warning("请选择考培地点");
  336. return;
  337. }
  338. var data = JSON.parse(JSON.stringify(this.formData));
  339. if (int === 1) {
  340. delete data.applySiteAddressTrain;
  341. }
  342. const indexs = this.examList.findIndex((item) => {
  343. return item.applyId == data.applyId;
  344. });
  345. data.applyName = this.examList[indexs].applyName;
  346. this.$api.inquiresystemsubscribeexportNew(data).then(async (res) => {
  347. for (let k in res.data) {
  348. if (res.data[k].code === 200) {
  349. await this.dowmFunc(res, k);
  350. } else {
  351. this.$message.error("code值错误:", res.data[k].code);
  352. }
  353. }
  354. });
  355. },
  356. dowmFunc(res, k) {
  357. return new Promise((resolve, reject) => {
  358. let url =
  359. baseUrls.baseURL + "common/download?fileName=" + res.data[k].msg;
  360. let link = document.createElement("a");
  361. let fileName = "导入模板" + ".xlsx";
  362. document.body.appendChild(link);
  363. link.href = url;
  364. link.dowmload = fileName;
  365. link.click();
  366. link.remove();
  367. setTimeout(() => {
  368. resolve();
  369. }, 200);
  370. });
  371. },
  372. /**
  373. *
  374. * @param {event} e 不含考培导入模板
  375. */
  376. importMobleadd(e) {
  377. var file = e.target.files[0];
  378. let formData = new FormData();
  379. formData.append("file", file);
  380. this.$api
  381. .editsystemsubscribeimportData(formData)
  382. .then((res) => {
  383. this.tableDataSuccess = res.data.successList;
  384. this.tableDataError = res.data.errorList;
  385. this.typeInt = 1;
  386. })
  387. .finally(() => {
  388. e.target.value = "";
  389. });
  390. },
  391. /**
  392. *
  393. * @param {event} e 含考培导入模板
  394. */
  395. importMobleaddtrain(e) {
  396. var file = e.target.files[0];
  397. let formData = new FormData();
  398. formData.append("file", file);
  399. this.$api
  400. .editsystemsubscribeimportTrainData(formData)
  401. .then((res) => {
  402. this.tableDataSuccess = res.data.successList;
  403. this.tableDataError = res.data.errorList;
  404. this.typeInt = 2;
  405. })
  406. .finally(() => {
  407. e.target.value = "";
  408. });
  409. },
  410. },
  411. };
  412. </script>
  413. <style lang="less" scoped>
  414. .h4Sty {
  415. margin: 6px;
  416. font-size: 14px;
  417. }
  418. .exportBox {
  419. border: 1px solid #999;
  420. padding: 10px;
  421. margin-top: 10px;
  422. border-radius: 4px;
  423. }
  424. /deep/.el-button {
  425. border-radius: 8px;
  426. }
  427. /deep/.el-dialog {
  428. border-radius: 8px;
  429. .el-dialog__header {
  430. padding: 0;
  431. .hearders {
  432. height: 40px;
  433. display: flex;
  434. align-items: center;
  435. justify-content: space-between;
  436. padding: 0px 18px 0px 20px;
  437. border-bottom: 1px solid #e2e2e2;
  438. .leftTitle {
  439. font-size: 14px;
  440. font-weight: bold;
  441. color: #2f4378;
  442. }
  443. .rightBoxs {
  444. display: flex;
  445. align-items: center;
  446. img {
  447. width: 14px;
  448. height: 14px;
  449. margin-left: 13px;
  450. cursor: pointer;
  451. }
  452. }
  453. }
  454. }
  455. .el-dialog__footer {
  456. padding: 0;
  457. .dialog-footer {
  458. padding: 0px 40px;
  459. height: 70px;
  460. border-top: 1px solid #e2e2e2;
  461. display: flex;
  462. align-items: center;
  463. justify-content: flex-end;
  464. }
  465. }
  466. }
  467. .imgBox {
  468. width: 100%;
  469. // height: 210px;
  470. border: 1px solid #e2e2e2;
  471. border-radius: 8px;
  472. padding: 8px 8px 3px;
  473. display: flex;
  474. flex-direction: column;
  475. align-items: center;
  476. .imgLabel {
  477. flex: 1;
  478. width: 100%;
  479. border: 1px dotted #e2e2e2;
  480. color: #999;
  481. font-size: 14px;
  482. cursor: pointer;
  483. border-radius: 8px;
  484. .msPhoto {
  485. display: flex;
  486. justify-content: center;
  487. align-items: center;
  488. max-width: 100%;
  489. max-height: 270px;
  490. img {
  491. max-width: 100%;
  492. max-height: 270px;
  493. }
  494. }
  495. .imgbbx {
  496. display: flex;
  497. flex-direction: column;
  498. align-items: center;
  499. justify-content: center;
  500. width: 100%;
  501. height: 100%;
  502. i {
  503. font-weight: bold;
  504. margin: 14px 0;
  505. font-size: 24px;
  506. }
  507. }
  508. }
  509. p {
  510. margin: 5px 0px;
  511. }
  512. }
  513. .item {
  514. margin-top: 10px;
  515. margin-right: 20px;
  516. }
  517. </style>