addEdit.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :center="true"
  6. align="left"
  7. top="8vh"
  8. width="1000px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="closeModel"
  15. >
  16. <el-card style="margin-top: -25px">
  17. <upload-excel-component
  18. :on-success="handleSuccess"
  19. :before-upload="beforeUpload"
  20. />
  21. <el-table
  22. :data="tableData"
  23. size="mini"
  24. border
  25. max-height="400px"
  26. highlight-current-row
  27. style="width: 100%; margin-top: 20px"
  28. >
  29. <el-table-column prop="invNo" label="发票编号" width="180" />
  30. <el-table-column prop="inv_type_name" label="发票类型" width="150" />
  31. <el-table-column prop="inv_code" label="发票代码" />
  32. <el-table-column prop="inv_number" label="发票号码" />
  33. <el-table-column prop="inv_total" label="发票金额" width="130" />
  34. <el-table-column prop="createtime" label="开票日期" width="150" />
  35. </el-table>
  36. <div class="tr" style="padding: 10px 0 0 0">
  37. <el-button type="primary" size="small" @click="submitForm"
  38. >保 存
  39. </el-button>
  40. </div>
  41. </el-card>
  42. </el-dialog>
  43. </template>
  44. <script>
  45. import UploadExcelComponent from "@/components/UploadExcel/index.vue";
  46. import asyncRequest from "@/apis/caixiaoService/InvoiceSales/orderBatchBilling";
  47. export default {
  48. name: "invoiceApply",
  49. props: ["showModel"],
  50. components: { UploadExcelComponent },
  51. data() {
  52. return {
  53. tableData: [],
  54. tableHeader: [],
  55. title: "",
  56. showModelThis: false,
  57. loading: false,
  58. newTime: 0,
  59. };
  60. },
  61. watch: {
  62. showModel: function (val) {
  63. this.showModelThis = val;
  64. if (val) {
  65. this.initForm();
  66. }
  67. },
  68. showModelThis(val) {
  69. if (!val) {
  70. this.$emit("cancel");
  71. }
  72. },
  73. },
  74. methods: {
  75. beforeUpload(file) {
  76. const isLt1M = file.size / 1024 / 1024 < 1;
  77. if (isLt1M) {
  78. return true;
  79. }
  80. this.$message({
  81. message: "请不要上传大于1MB的文件.",
  82. type: "warning",
  83. });
  84. return false;
  85. },
  86. handleSuccess({ results, header }) {
  87. let head = [
  88. "发票编号",
  89. "发票类型",
  90. "发票代码",
  91. "发票号码",
  92. "发票金额",
  93. "开票日期",
  94. ];
  95. if (head.length !== header.length) {
  96. this.$message.error("表头与导入模板不匹配!");
  97. return;
  98. }
  99. let hederOk = true;
  100. head.forEach((v1, i1) => {
  101. if (v1 !== header[i1].replace(/\s*/g, "")) {
  102. hederOk = false;
  103. }
  104. });
  105. if (!hederOk) {
  106. this.$message.error("表头与导入模板不匹配!");
  107. return;
  108. }
  109. this.tableHeader = header;
  110. this.tableData = [];
  111. let list = results;
  112. let tableOk = true;
  113. this.tableData = [];
  114. list.forEach((v1) => {
  115. let b = Object.values(v1);
  116. let time = this.setTime((b[5] + "").replace(/^\s*|\s*$/g, ""));
  117. let inv_type = this.get_inv_type(b[1] + "");
  118. if (inv_type === -1) {
  119. tableOk = false;
  120. }
  121. let model = {
  122. invNo: b[0] + "",
  123. inv_type_name: inv_type === -1 ? "" : b[1] + "",
  124. inv_type: inv_type === -1 ? "" : inv_type,
  125. inv_code: b[2] + "",
  126. inv_number: b[3] + "",
  127. inv_total: b[4] + "",
  128. createtime: time,
  129. };
  130. this.tableData.push(model);
  131. });
  132. if (!tableOk) {
  133. this.$message.error("发票类型不正确,请将表格格式转为文本上传!");
  134. }
  135. },
  136. unique(arr) {
  137. let hash = [];
  138. for (let i = 0; i < arr.length; i++) {
  139. let index = hash.findIndex((v1) => v1.inv_number === arr[i].inv_number);
  140. if (index === -1) {
  141. hash.push(arr[i]);
  142. }
  143. }
  144. return hash;
  145. },
  146. setTime(time) {
  147. time = time.replace(/\//g, "-");
  148. time = time.replace(/\./g, "-");
  149. let key = new Date(time).valueOf() + "";
  150. if (key.length !== 13) {
  151. time = "";
  152. }
  153. return time;
  154. },
  155. closeModel() {
  156. console.log("closeModel!!");
  157. },
  158. dropzoneS(file) {
  159. console.log(file);
  160. this.$message({ message: "Upload success", type: "success" });
  161. },
  162. dropzoneR(file) {
  163. console.log(file);
  164. this.$message({ message: "Delete success", type: "success" });
  165. },
  166. async initForm() {
  167. this.newTime = 0;
  168. this.loading = true;
  169. this.tableData = [];
  170. this.tableHeader = [];
  171. this.step = 1;
  172. this.title = "批量导入开票信息";
  173. this.changea();
  174. this.loading = false;
  175. },
  176. refreshAll() {
  177. this.showModelThis = false;
  178. this.$emit("refresh");
  179. },
  180. changea() {
  181. this.newTime = new Date().valueOf();
  182. },
  183. async submitForm() {
  184. if (!this.loading) {
  185. if (this.tableData.length < 1) {
  186. this.$message.error("导入数据不能为空!");
  187. this.loading = false;
  188. return;
  189. }
  190. let arr = this.unique(this.tableData);
  191. if (arr.length !== this.tableData.length) {
  192. this.$message.error("发票号码不可以重复出现!");
  193. this.loading = false;
  194. return;
  195. }
  196. this.loading = true;
  197. let isok = true;
  198. let list = [];
  199. this.tableData.forEach((v1, i1) => {
  200. let model = Object.assign({}, v1);
  201. delete model["inv_type_name"];
  202. for (let key in model) {
  203. if (model[key] === "") {
  204. isok = false;
  205. }
  206. }
  207. list.push(model);
  208. });
  209. if (!isok) {
  210. this.$message.error("导入数据不能出现空值!");
  211. this.loading = false;
  212. return;
  213. }
  214. const res = await asyncRequest.receiptimport({ data: list });
  215. this.loading = false;
  216. if (res && res.code === 0) {
  217. this.showModelThis = false;
  218. this.$emit("refresh");
  219. } else if (res && res.code >= 100 && res.code <= 104) {
  220. await this.logout();
  221. } else if (res && res.code === 1005) {
  222. this.$message.error(res.message);
  223. } else {
  224. console.log("其他错误");
  225. }
  226. }
  227. },
  228. get_inv_type(type) {
  229. let list = [
  230. {
  231. id: "1",
  232. name: "增值税专用发票",
  233. },
  234. {
  235. id: "2",
  236. name: "增值税普通发票",
  237. },
  238. {
  239. id: "3",
  240. name: "增值税电子专用发票",
  241. },
  242. {
  243. id: "4",
  244. name: "增值税电子普通发票",
  245. },
  246. ];
  247. let index = list.findIndex((v1) => v1.name === type.replace(/\s*/g, ""));
  248. if (index !== -1) {
  249. index === list[index].id;
  250. }
  251. return index;
  252. },
  253. },
  254. };
  255. </script>
  256. <style lang="scss" scoped>
  257. .orderBatchBilling {
  258. .activity-upload {
  259. position: relative;
  260. .img-list-main {
  261. position: relative;
  262. width: auto;
  263. border-left: 1px solid rgb(220, 223, 230);
  264. .img-item {
  265. float: left;
  266. width: 254px;
  267. height: 164px;
  268. border: 1px solid rgb(220, 223, 230);
  269. border-left: 0;
  270. position: relative;
  271. &.error {
  272. border: 1px solid #c03639;
  273. .error-m {
  274. position: absolute;
  275. background: #f2f2f2;
  276. left: 0;
  277. top: 0;
  278. z-index: 20;
  279. width: 250px;
  280. height: 160px;
  281. line-height: 160px;
  282. text-align: left;
  283. display: flex;
  284. align-items: center;
  285. padding: 16px;
  286. box-sizing: border-box;
  287. li {
  288. width: 100%;
  289. padding: 5px 0;
  290. max-height: 160px;
  291. color: #c03639;
  292. text-align: center;
  293. box-sizing: border-box;
  294. }
  295. &.show {
  296. opacity: 1;
  297. transition: opacity 0.3s;
  298. }
  299. &.close {
  300. opacity: 0;
  301. transition: opacity 0.3s;
  302. }
  303. }
  304. }
  305. img {
  306. display: inline-block;
  307. width: 100%;
  308. height: 100%;
  309. }
  310. i {
  311. position: absolute;
  312. right: 6px;
  313. font-size: 16px;
  314. top: 6px;
  315. z-index: 30;
  316. color: #909399;
  317. &:hover {
  318. cursor: pointer;
  319. color: rgb(56, 193, 231);
  320. }
  321. }
  322. }
  323. }
  324. .btnupload {
  325. float: left;
  326. border: 1px solid rgb(220, 223, 230);
  327. border-left: 0;
  328. box-sizing: border-box;
  329. width: 254px;
  330. height: 164px;
  331. line-height: 164px;
  332. text-align: center;
  333. }
  334. .Upload {
  335. width: 254px;
  336. height: 164px;
  337. line-height: 164px;
  338. text-align: center;
  339. position: absolute;
  340. line-height: 0px;
  341. top: 0;
  342. left: 0;
  343. z-index: 2;
  344. line-height: 164px;
  345. }
  346. .fileUp {
  347. vertical-align: top;
  348. }
  349. .avatar {
  350. width: 254px;
  351. height: 164px;
  352. line-height: 164px;
  353. text-align: center;
  354. }
  355. .avatar-uploader .el-upload:hover {
  356. border-color: #409eff;
  357. }
  358. .avatar-uploader-icon {
  359. font-size: 33px;
  360. color: #8c939d;
  361. width: 50px;
  362. height: 50px;
  363. line-height: 50px;
  364. text-align: center;
  365. }
  366. .avatar {
  367. width: 100%;
  368. height: 100%;
  369. display: block;
  370. }
  371. .txt-tips {
  372. display: inline-block;
  373. font-size: 13px;
  374. color: #606266;
  375. padding: 15px 0 0 15px;
  376. p {
  377. margin: 0;
  378. line-height: 30px;
  379. span {
  380. padding: 0 15px 0 0;
  381. }
  382. }
  383. }
  384. .avatar-uploader .el-upload {
  385. border: 1px dashed #d9d9d9;
  386. border-radius: 6px;
  387. cursor: pointer;
  388. position: relative;
  389. overflow: hidden;
  390. }
  391. }
  392. }
  393. </style>