index.js 32.9 KB
Newer Older
fukai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import Utils from "~/utils"
import moment from "moment"


export default {
	mixins: [commonFunctions],
	methods: {
		initOwnref() {
			let trnName = "";
			if (this.root) {
				trnName = this.root.trnName;
			}
			switch (trnName.toUpperCase()) {
				case "BFTSND":
				case "BFTDRV":
				case "BFTINV":
					this.model.imgInvmod.ownref = this.model.dedgrp.rec.ownref;
					break;
				case "DITDCK":
				case "BDTDCK":
				case "BDTINV":
					this.model.imgInvmod.ownref = this.model.didgrp.rec.ownref;
					break;
				case "BPTINV":
					this.model.imgInvmod.ownref = this.model.bpdgrp.rec.ownref;
					break;
				case "CPTINV":
					this.model.imgInvmod.ownref = this.model.cpdgrp.rec.ownref;
					break;
			}
		},
		excelUpload(){
			this.detailsDialog = true
		},
		file2XLSX(file) {
			return new Promise(function (resolve, reject) {
				// 通过FileReader对象读取文件
				const reader = new FileReader()
				// 读取为二进制字符串
				reader.readAsBinaryString(file)
				reader.onload = function (e) {
					console.log(e, '读取文件成功的e');
					// 获取读取文件成功的结果值
					const data = e.target.result
					// XLSX.read解析数据,按照type 的类型解析
					const XLSX = require('xlsx')
					let wb = XLSX.read(data, {
						type: 'binary' // 二进制
					})
					console.log(wb, '---->解析后的数据')
					// 存储获取到的数据
					const result = []
					// 工作表名称的有序列表
					wb.SheetNames.forEach(sheetName => {
						result.push({
							// 工作表名称
							sheetName: sheetName,
							// 利用 sheet_to_json 方法将 excel 转成 json 数据
							sheet: XLSX.utils.sheet_to_json(wb.Sheets[sheetName])
						})
					})
					resolve(result)
				}
			})
		},
		async getdbCode(dbCode, codeNam) {
			let params = {
				codeType: dbCode,
				uil: 'EN'
			}
			let rtnmsg = await Api.post("/manager/dic/listDicInfo", params)
			if (rtnmsg.respCode === SUCCESS) {
				let srvtxt = rtnmsg.data.map(item => ({
					value: item.codeValue,
					label: item.codeName
				}));
				this.dbCodes[codeNam] = srvtxt
			}
		},
		getLabel(list, id) {
			if (id != '' && Array.isArray(list) && list.length != 0) {
				return !list.find(item => item['value'] == id) ? id : list.find(item => item['value'] == id)['label']
			}
		},
		addRow() {
			let newRow = {
				imagid: 'BFTSND_BFTDRV_BFTINV'.includes(this.root.trnName.toUpperCase()) && this.model.dedgrp.rec.elcflg == 'Y' ? '00000000-0000-0000-0000-000000000000' : '',
				seqnum: '',
				invcod: '',
				invnum: '',
				invdat: '',
				checkcode: '',
				state: '',
				amounttax: 0.00,
				untamt: 0.00,
				amountin: 0.00,
				valflg: 'VLID',
				reason: '',
				state:''
			};
			let start = 0;
			if (this.model.imgInvmod.invlst) {
				start = this.model.imgInvmod.invlst.length;
			}
			this.model.imgInvmod.invlst.splice(start, 0, newRow);
			this.model.imgInvmod.pageTable.total=this.model.imgInvmod.invlst.length
			this.model.imgInvmod.pageTable.currentPage = parseInt((this.model.imgInvmod.invlst.length-1) /this.model.imgInvmod.pageTable.pageSize) + 1
			this.model.imgInvmod.pageTable.tableData =this.paginate(this.model.imgInvmod.pageTable.currentPage,this.model.imgInvmod.pageTable.pageSize);
			this.root.$refs["modelForm"].validateField([`imgInvmod.addList`]);
			this.root.$refs["modelForm"].validateField([`imgInvmod.checkTrue`]);
		},
		handleRowClick(row) {
			this.currentZcinvlstIndex = row.index
		},
		tableRowClassName({ row, rowIndex }) {
			row.index = rowIndex;
		},
		tableRowClassName1({ row, rowIndex }) {
			row.index = rowIndex;
		},
		untamt() {
			let arr = this.model.imgInvmod.invlst
			this.model.imgInvmod.untamtin = 0
			arr.forEach((item) => {
				this.model.imgInvmod.untamtin = Number(item.amountin) + Number(this.model.imgInvmod.untamtin)
			});
		},
		changeCli(val){
			if(val == 'X'){
				this.root.$refs["modelForm"].validateField([`imgInvmod.checkTrue`]);
			}
		},
		async deleteRow() {
			if (this.selection1.length == 0) {
				this.$notify.error({
					title: "错误",
					message: "请选择需要删除的数据!"
				});
				return;
			}
			let flg = this.selection1.some(item => {
				return item.seqnum != ''
			})
			let params = {
				invlst: this.selection1
			}
			if (flg) {
				let res = await Api.post(`/manager/invchk/ruleDelN1000 `, params)
				if (res.respCode == SUCCESS) {
					if (res.data.errorMsg) {
						this.$notify.error({
							title: "错误",
							message: res.data.errorMsg
						});
					} else {
						
						for (var i = this.selection1.length - 1; i >= 0; i--) {
							this.model.imgInvmod.invlst.splice(this.selection1[i].index + ((this.model.imgInvmod.pageTable.currentPage -1) * this.model.imgInvmod.pageTable.pageSize), 1);
						}
						let num = parseInt((this.model.imgInvmod.invlst.length-1) /this.model.imgInvmod.pageTable.pageSize) + 1
						if(this.model.imgInvmod.pageTable.currentPage > num){
							this.model.imgInvmod.pageTable.currentPage = num
						}
						this.refresh();
						this.root.$refs["modelForm"].validateField([`imgInvmod.checkTrue`]);
					}
				}
			} else {
				
				for (var i = this.selection1.length - 1; i >= 0; i--) {
					this.model.imgInvmod.invlst.splice(this.selection1[i].index + ((this.model.imgInvmod.pageTable.currentPage -1) * this.model.imgInvmod.pageTable.pageSize), 1);
				}
				let num1 = parseInt((this.model.imgInvmod.invlst.length-1) /this.model.imgInvmod.pageTable.pageSize) + 1
						if(this.model.imgInvmod.pageTable.currentPage > num1){
							this.model.imgInvmod.pageTable.currentPage = num1
						}
				this.refresh();
				this.root.$refs["modelForm"].validateField([`imgInvmod.checkTrue`]);
			}
		},
		//检核按钮
		async checkList() {
			//发票报文(重复性报文和登记报文)需要业务编号
			let ref = ''
			let commonParams = this.root.buildCommonData(this.root.model, this.root.trnName);
			if(commonParams && commonParams.rec){
				ref = commonParams.rec.ownref
				this.model.imgInvmod.ownref = ref
			}
			if(ref == ''){
				this.$message.warning("请首先获取交易Reference编号");
				return
			}
			let list = this.model.imgInvmod.invlst
			if (list.length == 0) {
				this.$notify.error({
					title: "错误",
					message: "请先添加相关发票"
				});
				return
			}
			if('BFTSND_BFTDRV_BFTINV'.includes(this.root.trnName.toUpperCase())){
				if (Number(this.model.imgInvmod.untamtin) < Number(this.model.imgInvmod.docamt)) {
					if (this.root.trnName.toUpperCase() == "BFTDRV") {
						this.$notify.error({
							title: "错误",
							message: "发票占用总金额未覆盖单据增额部分请增加发票"
						});
					} else {
						this.$notify.error({
							title: "错误",
							message: "发票占用总金额未覆盖业务金额,请增加发票"
						});
					}
					return
				}
			}
			this.isCheckRe = false
			this.$refs['invTable'].validate(async (validStatic) => {
				if (validStatic) {
					this.model.imgInvmod.successstm = []
					let flg = false
					for (let i = 0; i < list.length; i++) {
						let number = list[i].invcod + 'tab' + list[i].invnum
						let index = this.model.imgInvmod.successstm.indexOf(number)
						if (index < 0) {
							this.model.imgInvmod.successstm.push(number)
						} else {
							flg = true
							this.$notify.error({
								title: "错误",
								message: '序号为' + (i + 1) + '的发票和序号为'+ (index + 1) + '的发票重复,请勿重复录入'
							});
							break
						}
					}
					if (flg) {
						return
					}
					let param = {
						...this.model.imgInvmod,
						trnNam:this.root.trnName.toUpperCase(),
						pntref: 'BFTSND_BFTDRV_BFTINV'.includes(this.root.trnName.toUpperCase() ) ?  this.model.dedgrp.rec.ownref : ''
					}
					const loading = this.loading()
					let res = await Api.post(`/public/invsel/ruleChkbtnN1000`, param)
					loading.close()
					if (res.respCode == SUCCESS) {
						this.model.imgInvmod.seqnum = res.data.seqnum
						if (res.data.errorMsg) {
							this.$notify.error({
								title: "错误",
								message: res.data.errorMsg
							});
						} else {
							this.model.imgInvmod.invlst = res.data.invlst
							this.model.imgInvmod.pageTable.tableData =this.paginate(this.model.imgInvmod.pageTable.currentPage,this.model.imgInvmod.pageTable.pageSize);
							this.isUpdateRe = 'N'
							this.$notify({
								title: '成功',
								message: '发票真伪核验成功,请点击更新状态',
								type: 'success',
							});
						}
						this.root.$refs["modelForm"].validateField([`imgInvmod.checkTrue`]);
					}
				}
			})
		},
		async checkRepeat() {
			let list = this.model.imgInvmod.invlst
			if (list.length == 0) {
				this.$notify.error({
					title: "错误",
					message: '请先添加相关发票'
				});
				return
			}
			let ref = ''
			let commonParams = this.root.buildCommonData(this.root.model, this.root.trnName);
			if(commonParams && commonParams.rec){
				ref = commonParams.rec.ownref
				this.model.imgInvmod.ownref = ref
			}
			if(ref == ''){
				this.$message.warning("请首先获取交易Reference编号");
				return
			}
			if(this.model.imgInvmod.skipped == ''){
				let flg = list.some(item => {
					return item.state != '0'
				})
				if (flg) {
					this.$notify.error({
						title: "错误",
						message: '请先进行发票真伪校验或者删除异常发票'
					});
					return
				}
			}
			this.isCheckRe = true
			this.$refs['invTable'].validate(async (validStatic) => {
				if (validStatic) {
					let commonParams = this.root.buildCommonData(this.root.model, this.root.trnName);
					if(commonParams && commonParams.rec){
						this.model.imgInvmod.ownref = commonParams.rec.ownref
					}
					let loading = this.loading()
					let res = await Api.post(`/manager/invchk/saveData`, this.model.imgInvmod)
					loading.close()
					if (res.respCode == SUCCESS) {
						if (res.data.errorMsg) {
							this.$notify.error({
								title: "错误",
								message: res.data.errorMsg
							});
						} else {
							this.isUpdateRe = 'Y'
							this.$notify({
								title: '成功',
								message: '人行重复性核验成功,请点击更新状态',
								type: 'success',
							});
							this.model.imgInvmod.invlst = res.data.invlst
							this.model.imgInvmod.pageTable.tableData =this.paginate(this.model.imgInvmod.pageTable.currentPage,this.model.imgInvmod.pageTable.pageSize);
							this.model.imgInvmod.isAddReg = false
						}
						
					}
				}
			})
		},
		inputInvnum(index) {
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invcod`]);
		},
		changeInvdat(index) {
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invcod`]);
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invnum`]);
		},
		inputAmountin(index) {
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invcod`]);
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invnum`]);
		},
		inputUntamt(index){
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invcod`]);
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invnum`]);
		},
		inputAmounttax(index) {
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invnum`]);
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.amountin`]);
			this.$refs['invTable'].validateField([`imgInvmod.pageTable.tableData.${index}.invcod`]);
		},

		async currentChange(num) {
			this.model.imgInvmod.pagination.pageNum = num
			this.serachInv()
		},
		async sizeChange(size) {
			this.model.imgInvmod.pagination.pageSize = size
			this.serachInv()
		},
		async currentChange1(num) {
			this.pagination1.pageNum1 = num

		},

		async currentChange2(num) {
			this.pagination2.pageNum2 = num
			this.serachResult()
		},
		async sizeChange2(size) {
			this.pagination2.pageSize2 = size
			this.serachResult()
		},
		//给发票登记的字段赋值
		setReg(){
			let ownref = this.root.trnName.toUpperCase() == 'BDTSET' ? this.model.didgrp.rec.ownref : this.model.bfdgrp.rec.ownref
			let antdtl1 = this.root.trnName.toUpperCase() == 'BDTSET' ? "开证行名称:" + this.model.didgrp.iss.pts.nam + ",信用证编号:" + this.model.didgrp.rec.ownref + ",合同编号:" + this.model.didgrp.rec.conno
										: "开证行名称:" + this.model.dedgrp.iss.pts.nam + ",信用证编号:" + this.model.dedgrp.rec.kzref + ",合同编号:" + this.model.dedgrp.rec.conno
			Api.post('/manager/invchk/getBchBranch').then(res=>{
				this.model.imgInvmod.invp.bustyp = 'OTLC'
				this.model.imgInvmod.invp.antnum = ownref
				this.model.imgInvmod.invp.antdat = new Date()
				this.model.imgInvmod.invp.antnam = res.data
				this.model.imgInvmod.invp.antdtl = antdtl1.length > 50 ? antdtl1.slice(0,50) : antdtl1
			})
		},
		addReg() {
			let flg = this.model.imgInvmod.invlst.some(item =>{
				return (item.isfnc == "Y" || item.isfnc == "N")
			})
			if(!flg){
				this.$notify({
					title: "提示",
					message: '发票未进行重复性校验',
					type: "info",
				});
				return
			}
			let flg1 = this.model.imgInvmod.invlst.some(item =>{
				return item.regsta != 'DJCG'
			})
			if(!flg1){
				this.$notify({
					title: "提示",
					message: '我行登记状态为已登记,无需重复登记',
					type: "info",
				});
				return
			}
			this.model.imgInvmod.addRegFlg = true
			this.setReg()
		},
		//发送登记报文
		sendMsg(){
			this.$refs['refDj'].validate(async (validStatic) => {
				if (validStatic) {
					let commonParams = this.root.buildCommonData(this.root.model, this.root.trnName);
					if(commonParams && commonParams.rec){
						this.model.imgInvmod.ownref = commonParams.rec.ownref
					}
					let list = this.model.imgInvmod.invlst
					let markList = []
					list.forEach(item =>{
						if(item.regsta !='DJCG' ){
							markList.splice(markList.length,0,item)
						}
					})
					let data = markList.map(item => ({
						filnam: '',
						credat: (new Date()).Format("yyyy-MM-dd"),
						imgcod: item.imagid,
						invtyp: item.invtyp,
						invamt: item.untamt,
						invcod: item.invcod,
						invnum: item.invnum,
						opndat: item.invdat,
						vrfcod: item.checkcode,
						vldflg: item.valflg
					}))
					let params = {
						...this.model.imgInvmod.invp,
						ownref:this.model.imgInvmod.ownref,
						invlst: data
					}
					Api.post("/manager/invchk/reg", params).then((data)=>{
						if (data.respCode == SUCCESS) {
							if (!data.data.errorMsg) {
								this.$notify({
									title: "成功",
									message: "发票登记成功",
									type: "success",
								});
								this.model.imgInvmod.addRegFlg = false
								this.model.imgInvmod.invp = {
									bustyp: '',
									antnum: '',
									opndat: '',
									busdcr: '',
									antnam: '',
									antdtl: ''
								}
								let loading = this.loading()
								setTimeout(() => {
									this.updateStatus()
									loading.close()
								}, 5000)
							} else {
								this.$notify({
									title: "提示",
									message: data.data.errorMsg,
									type: "info",
								});
							}
							
						}
					})
					
				}
			})
		},
		async getInvList(row) {
			this.model.imgInvmod.showCanTab = true
			this.model.imgInvmod.tabVal = 'fpzf'
			let res = await Api.post("/manager/invchk/invdellst", row.smhinr)
			if (res.respCode == SUCCESS) {
				this.model.imgInvmod.tableData4 = res.data
				this.model.imgInvmod.invDelForm = {
					bustyp: res.data[0].bustyp,
					antnum: res.data[0].antnum,
					antdat: res.data[0].antdat,
					busdcr: res.data[0].busdcr,
					antnam: res.data[0].antnam,
					antdtl: res.data[0].antdtl,
				}
			}
		},
		//发票作废发送报文
		async sendInv() {
			let params = {
				invlst: this.model.imgInvmod.tableData4
			}
			let res = await Api.post("/manager/invchk/del", params)
			if (res.respCode == SUCCESS) {
				this.$notify({
					title: '成功',
					message: '提交成功',
					type: 'success',
				})
				this.model.imgInvmod.showCanTab = false
				this.model.imgInvmod.tabVal = 'djzf'
				this.serachInv()
			}
		},
		//核验结果查询
		async serachResult() {
			let params = {
				...this.model.imgInvmod.insel,
				pageNum: this.pagination2.pageNum2,
				pageSize: this.pagination2.pageSize2,
			}
			let res = await Api.post("/manager/invchk/getalllist", params)
			if (res.respCode == SUCCESS) {
				this.tableData2 = res.data.list
				this.pagination2.total2 = res.data.list.length
			}
		},
		closeDialog() {
			this.detailsDialog = false
		},
		async updateStatus() {
			let loading = this.loading()
			let res = await Api.post(`/public/invsel/ruleUptstaN100`, this.model.imgInvmod)
			loading.close()
			if (res.respCode == SUCCESS) {
				if (res.data.errorMsg) {
					this.$notify.error({
						title: "错误",
						message: res.data.errorMsg
					});
				} else {
					this.model.imgInvmod.invlst = res.data.invlst
					this.model.imgInvmod.pageTable.tableData =this.paginate(this.model.imgInvmod.pageTable.currentPage,this.model.imgInvmod.pageTable.pageSize);
					if(this.isUpdateRe == 'Y'){
						let flg = this.model.imgInvmod.pageTable.tableData.some(item=>{
							return item.isfnc == '' || item.isfnc == null
						})
						if(flg){
							this.$alert('等待人行反馈,请继续更新', '提示', {
								confirmButtonText: '确定'
							});
						}else{
							this.$alert('更新成功', '提示', {
								confirmButtonText: '确定'
							});
						}
					}
					if(this.isUpdateRe == 'N'){
						let flg = this.model.imgInvmod.pageTable.tableData.some(item=>{
							return (item.state == '' || item.state == null) && (item.reason == '' || item.reason == null)
						})
						if(flg){
							this.$alert('等待外束反馈,请继续更新', '提示', {
								confirmButtonText: '确定'
							});
						}else{
							this.$alert('更新成功', '提示', {
								confirmButtonText: '确定'
							});
						}
					}
					if(this.isUpdateRe == ''){
						this.$alert('更新成功', '提示', {
							confirmButtonText: '确定'
						});
					}
					this.root.$refs["modelForm"].validateField([`imgInvmod.checkTrue`]);
				}
			}

		},
		getCheck() {
			let list = this.model.imgInvmod.invlst
			let markList = []
			list.forEach(item => {
				if (item.state == '0') {
					markList.splice(markList.length, 0, item)
				}
			})
			if (markList.length == 0) {
				this.$message({
					message: '没有验真成功的发票',
					center: true,
					type: 'warning'
				})
			} else {
				let newData = markList.map(item => ({
					filnam: '',
					credat: '',
					filid: item.imagid,
					invtyp: item.invtyp,
					invnum: item.invnum,
					invcod: item.invcod,
					invamt: item.untamt,
					opndat: item.invdat,
					vrfcod: item.checkcode,
					vldflg: item.valflg,
				}))
				this.model.imgInvmod.tableData = newData
			}
		},
		//发票作废登记查询
		async serachInv() {
			let params = {
				...this.model.imgInvmod.regsel,
				pageNum: this.model.imgInvmod.pagination.pageNum,
				pageSize: this.model.imgInvmod.pagination.pageSize
			}
			let res = await Api.post("/manager/invchk/getinvreglst", params)
			if (res.respCode === SUCCESS) {
				this.model.imgInvmod.tableData1 = res.data.list
				this.model.imgInvmod.pagination.total = res.data.total
			}
		},
		async downFile() {
			let params = {
				path: 'sstf/data/doc/invoiceAuthen.xlsx'
			}
			let res = await Api.post("/manager/fileupdown/fileDown", params);
			if (res.respCode == "AAAAAA") {
				//res.data 内容为 TextResultVo 
				if (res.data.data) {
					let type, code = res.data;
					const loading = this.loading()
					this.base64ToBlob(code, type)
					loading.close()
					this.$notify({
						title: "成功",
						message: "文件下载成功!",
						type: "success",
					});
				}
				else {
					this.$notify({
						title: '失败',
						message: '文件下载失败!',
						type: 'error',
					});
				}
			}
		},
		base64ToBlob(code, type) {
			if (type == 'application/pdf') {
				code.data = code.data.replace(/[\n\r]/g, "")
			}
			const raw = window.atob(code.data);
			const rawLength = raw.length;
			const uInt8Array = new Uint8Array(rawLength);
			for (let i = 0; i < rawLength; ++i) {
				uInt8Array[i] = raw.charCodeAt(i);
			}
			const blob = new Blob([uInt8Array], { type: type });
			// const fileURL = URL.createObjectURL(blob);
			// window.open(fileURL)
			let fileName = code.filename;
			var downloadElement = document.createElement('a');
			var href = window.URL.createObjectURL(blob);
			downloadElement.href = href;
			downloadElement.download = fileName;
			document.body.appendChild(downloadElement);
			downloadElement.click();
			document.body.removeChild(downloadElement);
			window.URL.revokeObjectURL(href);
		},
		async printResult() {
			this.tempRolVisible = true
			this.printResultData = this.selection
		},
		handleCloseDialogTable() {
			this.tempRolVisible = false
		},
		checkInvselList(list) {
			let length = list.length
			for (let i = 0; i < length; i++) {
				switch (list[i].invtyp) {
					case 'SPEC':
					case 'ESPE':
						if (!list[i].invamt) {
							this.$message({
								message: '列表第' + (i + 1) + '行,此发票类型下,未税金额必输',
								center: true,
								type: 'warning'
							})
							return false
						}
						break
					case 'COMM':
					case 'ECOM':
						if (!list[i].vrfcod) {
							this.$message({
								message: '列表第' + (i + 1) + '行,此发票类型下,验证码后六位必输',
								center: true,
								type: 'warning'
							})
							return false
						}
						break
					case 'OTEC':
						if (list[i].invamt || list[i].vrfcod) {
							this.$message({
								message: '列表第' + (i + 1) + '行,此发票类型下,未税金额和验证码后六位不可录入',
								center: true,
								type: 'warning'
							})
							return false
						}
						break
				}

			}
			return true
		},
		async getInvImg() {
			let imgnum = this.model.imgInvmod.imgnum
			let list = imgnum.split('\n')
			// let data  = this.model.imgInvmod.imguseList
			// data.forEach(item=>{
			// 	if(item.sndsta == 'Y'){
			// 		let index = list.indexOf(item.imgnum)
			// 		list.splice(index,1)
			// 	}
			// })
			let res = await Api.post("/manager/imginf/getImginfList", list)
			if (res.respCode == SUCCESS) {
				if (!res.data.errorMsg) {
					this.$notify({
						title: "成功",
						message: "影像下载成功,请更新影像列表",
						type: "success",
					});
					this.model.imgInvmod.updatFlg = false
					this.model.imgInvmod.downLoadFlg = true
					let loading = this.loading()
					setTimeout(() => {
						this.ruleShow()
						loading.close()
					}, 5000)
				} else {
					this.$notify.error({
						title: "错误",
						message: res.data.errorMsg
					});
				}

			}
		},
		async sendInvImg() {
			this.$refs['imgRef'].validate(async (validStatic) => {
				if (validStatic) {
					let commonParams = this.root.buildCommonData(this.root.model, this.root.trnName);
					if(commonParams && commonParams.rec){
						this.model.imgInvmod.ownref = commonParams.rec.ownref
					}
					let params = {
						imgnum: this.model.imgInvmod.imgnum,
						imglst: this.model.imgInvmod.imguseList,
						ownref:this.model.imgInvmod.ownref
					}
					let res = await Api.post("/manager/imginf/ruleSndoneN100", params)
					if (res.respCode == SUCCESS) {
						if (!res.data.errorMsg) {
							this.$notify({
								title: "成功",
								message: "上传人行影像系统成功,请更新影像列表",
								type: "success",
							});
							this.model.imgInvmod.uploadFlg = true
							let loading = this.loading()
							setTimeout(() => {
								this.ruleShow()
								loading.close()
							}, 5000)
						} else {
							this.$notify.error({
								title: "错误",
								message: res.data.errorMsg
							});
						}

					}
				}else{
					this.$notify.error({
						title: "错误",
						message: '影像列表有影像类型未选择'
					});
				}
			})

		},
		async ruleShow() {
			let res = await Api.post("/manager/imginf/updateImguse", this.model.imgInvmod)
			if (res.respCode == SUCCESS) {
				this.model.imgInvmod.imguseList = res.data.imglst
				let invlst = res.data.invlst || []
				if (invlst.length > 0) {
					let list = this.model.imgInvmod.invlst
					let filterList = list.filter((item) => {
						return !item.imgnum || (item.imgnum && invlst.some((invItem) => {
							return invItem.filnam == item.filnam
						}))
					})
					let extList = []
					invlst.forEach((item) => {
						if (item.imgnum) {
							let ind = filterList.findIndex((invItem) => {
								return invItem.filnam == item.filnam
							})
							if (ind > -1) {
								filterList.splice(ind, 1, item)
							} else {
								extList.push(item)
							}
						}
					})
					this.model.imgInvmod.invlst = filterList.concat(extList)
					this.model.imgInvmod.pageTable.total=this.model.imgInvmod.invlst.length
					this.model.imgInvmod.pageTable.tableData =this.paginate(this.model.imgInvmod.pageTable.currentPage,this.model.imgInvmod.pageTable.pageSize);
				}
			}
		},
		//前端模拟分页
		paginate(pageNumber,pageSize){
			const startIndex=(pageNumber-1)*pageSize;
			const endIndex=startIndex+pageSize;
			return this.model.imgInvmod.invlst.slice(startIndex,endIndex);
		},
		//新增发票
		addInvsel() {
			let newRow = {
				filnam: '',
				credat: (new Date()).Format("yyyy-MM-dd"),
				filid: '00000000-0000-0000-0000-000000000000',
				invtyp: '',
				invamt: 0,
				invcod: '',
				invnum: '',
				opndat: '',
				vrfcod: '',
				vldflg: 'VLID'

			};
			let start = 0;
			if (this.model.imgInvmod.tableData) {
				start = this.model.imgInvmod.tableData.length;
			}
			this.model.imgInvmod.tableData.splice(start, 0, newRow);
		},
		//导出excel
		async exportExcel() {
			let params = {
				invlst: this.selection
			}
			if (params.invlst.length == 0) {
				this.$notify.error({
					title: "错误",
					message: '请选择需要导出的数据'
				});
				return
			}
			let loading = this.loading()
			let res = await Api.post("/manager/invchk/exportExcel", params)
			if (res.respCode == SUCCESS) {
				let name = moment(new Date()).format('yyyy-MM-DD HH:mm:ss');
				let list = res.data
				for (let index = 1; index < list.length; index++) {
					list[index][2] = this.getLabel(this.dbCodes.invtyp, list[index][2])
					list[index][12] = this.getLabel(this.dbCodes.bustyp, list[index][12])
				}
				Utils.exportToExcel(list, "发票核验查询结果信息_" + name + ".xlsx", "发票核验查询结果信息");
			}
			loading.close()

		},
		deleteResult(index) {
			this.model.imgInvmod.tableData.splice(index, 1);
		},
		// inputImfref(val){
		// 	this.exportDep = val
		// },
		async exportFormDep(){
			if(!this.model.imgInvmod.imfref){
				this.$message.warning("请输入独立核验编号");
				return
			}
			if(this.exportDep == this.model.imgInvmod.imfref && this.model.imgInvmod.imguseList.length !=0 && this.model.imgInvmod.invlst.length !=0){
				this.$message({
					message:  "此查验编号已经导入,如需重新导入,请先删除发票信息和影像信息",
					type:"info"
				})
				return
			}
			let ref = ''
			let lotnum = ''
			let commonParams = this.root.buildCommonData(this.root.model, this.root.trnName);
			if(commonParams && commonParams.rec){
				ref = commonParams.rec.ownref
			}
			if(ref == ''){
				this.$message.warning("请首先输入交易Reference编号");
				return
			}
			if(!this.root.model.trnInfo || !this.root.model.trnInfo.imginr){ 
				//不存在Imginr则请求新的imginr
				await this.getImginr();
			}
			let params = {
				imfref: this.model.imgInvmod.imfref,
				trnNam: this.root.trnName.toUpperCase(),
				pntref: 'BFTSND_BFTDRV_BFTINV'.includes(this.root.trnName.toUpperCase() ) ?  this.model.dedgrp.rec.ownref : ''
			}
			let res = await Api.post("/manager/invchk/getImgInvmodByImfref",params)
			if(res.respCode == SUCCESS){
				if(res.data.errorMsg){
					this.$message({
						message: res.data.errorMsg,
						type: "info"
					})
					return
				}
				lotnum = res.data.lotnum
				this.exportDep = this.model.imgInvmod.imfref
				//输入的独立交易编号是错误的
				if(!lotnum  && !res.data.imguseList && !res.data.invlst){
					this.$message({
						message:  "查验编号错误",
						type:"info"
					})
					this.model.imgInvmod.imguseList = []
					this.model.imgInvmod.invlst = []
					this.model.imgInvmod.pageTable.tableData = [];
					this.model.imgInvmod.pageTable.total = 0;
					return
				}
				if(res.data.warningMsg){
					this.$alert(res.data.warningMsg, '提示', {
						confirmButtonText: '确定'
					});
				}
				// if(res.data.invlst && res.data.invlst.length >0){
				// 	res.data.invlst.forEach(item =>{
				// 		item.amountin = item.amounttax
				// 	})
				// }
				//独立交易只上传发票没上传影像
				if(!lotnum){
					this.model.imgInvmod.invlst = res.data.invlst.concat(this.model.imgInvmod.invlst)
					this.model.imgInvmod.pageTable.total=this.model.imgInvmod.invlst.length
					this.model.imgInvmod.pageTable.tableData =this.paginate(this.model.imgInvmod.pageTable.currentPage,this.model.imgInvmod.pageTable.pageSize);
					this.root.$refs["modelForm"].validateField([`imgInvmod.checkTrue`]);
					this.bindImfref(this.model.imgInvmod.imfref,ref)
				}else{
					this.doBound(ref,lotnum).then((data)=>{
						if(data.flg){
							this.model.imgInvmod.imguseList = res.data.imguseList
							this.model.imgInvmod.invlst = res.data.invlst.concat(this.model.imgInvmod.invlst)
							this.model.imgInvmod.pageTable.total=this.model.imgInvmod.invlst.length
							this.model.imgInvmod.pageTable.tableData =this.paginate(this.model.imgInvmod.pageTable.currentPage,this.model.imgInvmod.pageTable.pageSize);
							this.model.imgInvmod.imgnum = lotnum
							this.model.imgInvmod.downLoadFlg = true
							this.root.$refs["modelForm"].validateField([`imgInvmod.checkTrue`]);
							this.bindImfref(this.model.imgInvmod.imfref,ref)
						}else{
							this.$message({
								message: data.res.respMsg,
								type: "info"
							})
						}
					})
				}	
			}
		},
		async bindImfref(imfref,ownref){
			let params = {
				imfref:imfref,
				ownref:ownref
			}
			let res = await Api.post("/manager/invchk/bindByInvsel",params)
			if(res.respCode == SUCCESS){
				this.$message({
					message: "独立交易绑定业务编号成功",
					type: "success"
				})
			}
		},
		//获取影像imginr
		async getImginr() {
      await Api.post("/manager/img/generateImgInr").then(res => {
        if (res.respCode == SUCCESS) {
          if(!this.root.model.trnInfo){
            this.$set(this.root.model,"trnInfo",{});
          }
          this.$set(this.root.model.trnInfo,"imginr",res.data.imgInr);
        }
      });
		},
		//绑定业务编号
		async doBound(ref,lotnum){
			//将独立交易上传的影像绑定到业务里
			let imgParams = {
				ownref: ref,
        lotnum: lotnum,
        imginr: this.root.model.trnInfo.imginr,
        trncod: this.root.trnName,
        optype: 0,
        opuser: window.sessionStorage.userName,
        branch: JSON.parse(sessionStorage.getItem('currentOrg')).departmentNumber,
			}
			if (!imgParams.imginr) return;
		 let res = await Api.post("/manager/img/bindOrUnbindForInvsel", imgParams)
		 if (res.respCode == SUCCESS) {
				return {flg:true,res:res}
			}else{
				return {flg:false,res:res}
			}
		},
		//因为外围系统原因导致验真验重登记失败,临时添加三个按钮强制成功
		async checkTrueSuccess(){
			let list = this.model.imgInvmod.invlst
			if(list.length == 0){
				this.$message({
					message:  "请先录入发票信息",
					type:"info"
				})
				return
			}
			list.forEach(item=>{
				item.invtyp = 'ECOM'
				item.checkcode = '876254'
				item.state = '0'
			})
			let params = {
				invlst: list
			}
			let res = await Api.post('/manager/invchk/updateForTemp',params)
			if(res.respCode == SUCCESS){
				this.model.imgInvmod.invlst = res.data.invlst
				this.$message({
					message: "验真成功",
					type: "success"
				})
			}
		},
		async checkRespetSuccess(){
			let list = this.model.imgInvmod.invlst
			if(list.length == 0){
				this.$message({
					message:  "请先录入发票信息",
					type:"info"
				})
				return
			}
			list.forEach(item=>{
				item.isfnc = 'N'
				item.annotacode = '1234'
				item.annotaname = '新晨科技'
				item.annotadate = '2024-05-12'
				item.annotadesc = '临时测试'
				item.salesname = '销售方'
				item.purchasername = '购买方'
				item.regsta = ''
			})
			let params = {
				invlst: list
			}
			let res = await Api.post('/manager/invchk/updateForTemp',params)
			if(res.respCode == SUCCESS){
				this.model.imgInvmod.invlst = res.data.invlst
				this.$message({
					message: "验重成功",
					type: "success"
				})
			}
		},
		async regSuccess(){
			let list = this.model.imgInvmod.invlst
			if(list.length == 0){
				this.$message({
					message:  "请先录入发票信息",
					type:"info"
				})
				return
			}
			list.forEach(item =>{
				item.regsta = 'DJCG'
				item.isfnc = 'Y'
			})
			let params = {
				invlst: list
			}
			let res = await Api.post('/manager/invchk/updateForTemp',params)
			if(res.respCode == SUCCESS){
				this.model.imgInvmod.invlst = res.data.invlst
				this.$message({
					message: "登记成功",
					type: "success"
				})
			}
		}
	}

}