export default class imgInvmodCheck {
	constructor(_this) {
		// 可以再当前方法中取_this,此this即为根组件的this
		this.check = {
			"imgInvmod.addList": [
				{
					validator(rule, value, callback) {

						//先写寄单交易,后面别的交易再补充
						if (!_this.model.imgInvmod.skipped) {
							let trnName = _this.trnName.toUpperCase()
							switch (trnName) {
								case 'BFTSND':
									if (_this.model.dedgrp.rec.elcflg == 'Y' && _this.model.imgInvmod.invlst.length == 0) {
										return callback(new Error('请录入寄单索款发票影像'));
									}
									if(Number(_this.model.imgInvmod.untamtin) > 0 && Number(_this.model.imgInvmod.untamtin) < Number(_this.model.imgInvmod.docamt) ){
										return callback(new Error('发票占用总金额未覆盖业务金额'))
									}
									callback()
									break
								case 'BFTDRV':
								case 'BFTINV':
									if(Number(_this.model.imgInvmod.untamtin) > 0 && Number(_this.model.imgInvmod.untamtin) < Number(_this.model.imgInvmod.docamt) ){
										return callback(new Error('发票占用总金额未覆盖业务金额'))
									}
									callback()
									break
								default:
									callback()
							}
						}else{
							if(_this.trnName.toUpperCase() == 'BFTSND'){
								if (_this.model.dedgrp.rec.elcflg == 'Y') {
									if(_this.model.imgInvmod.invlst.length == 0){
										return callback(new Error('请录入寄单索款发票影像'));
									}else{
										let flg = _this.model.imgInvmod.invlst.some(item=>{
											return (item.invnum == '' || item.invnum == null) || (item.invnum != '' && item.invnum.length != 20 && item.invcod == '')
										})
										if(flg){
											return callback(new Error('请录入发票号码和发票代码'));
										}
									}
									callback()
								}
								callback()
							}
							callback()
						}
						callback()
					}, trigger: ['blur', 'change']
				}
			],
			// "imgInvmod.fpdj": [
			// 	{
			// 		validator(rule, value, callback) {
			// 			if (!_this.model.imgInvmod.skipped) {
			// 				let elcflg = false
			// 				switch (_this.trnName.toUpperCase()) {
			// 					case "DITOPN":
			// 					case "DITAME":
			// 					case "DITDCK":
			// 					case "BDTDCK":
			// 					case "BDTINV":
			// 						if (_this.model.didgrp.rec.elcflg == "Y") {
			// 							elcflg = true;
			// 						} else {
			// 							elcflg = false;
			// 						}
			// 						break;
			// 					case "BFTSND":
			// 					case "BFTDRV":
			// 					case "BFTINV":
			// 						if (_this.model.dedgrp.rec.elcflg == "Y") {
			// 							elcflg = true;
			// 						} else {
			// 							elcflg = false;
			// 						}
			// 						break;
			// 					default:
			// 						elcflg = false;
			// 				}
			// 				if(_this.model.imgInvmod.addRegFlg){
			// 					return callback(new Error('请在下面录入发票登记必输信息后点击发票登记'))
			// 				}
			// 				let flg = _this.model.imgInvmod.invlst.some(item => {
			// 					return (item.invtyp == 'ECOM' || item.invtyp == 'SEPE') && (item.isfnc == "Y" || item.isfnc == "N") && item.regsta != 'DJCG'
			// 				})
			// 				if (!elcflg && !_this.model.imgInvmod.isElcflg && flg) {
			// 					return callback(new Error('非电证的电子发票需要进行发票登记'));
			// 				}
			// 				callback()
			// 			}

			// 			callback()
			// 		}
			// 	}
			// ],
			"imgInvmod.checkTrue": [
				{
					validator(rule, value, callback) {
						if (!_this.model.imgInvmod.skipped) {
							switch (_this.trnName.toUpperCase()) {
								case 'BFTSND':
									if (_this.model.imgInvmod.invlst.length == 0) {
										return callback(new Error('请输入发票信息,并进行发票真伪核验'));
									} else {
										let flg = _this.model.imgInvmod.invlst.some(item => {
											return item.state != '0' && (item.reason == '' || item.reason == null)
										})
										if (flg) {
											return callback(new Error('请进行发票验真'))
										}
										let flg1 = _this.model.imgInvmod.invlst.some(item => {
											return (item.state == null || item.state == "" ) && (item.reason != '' && item.reason != null)
										})
										if (flg1) {
											return callback(new Error('请删除非正常发票'))
										}
									}
									callback()
									break
								default:
									if (_this.model.imgInvmod.invlst.length != 0) {
										let flg = _this.model.imgInvmod.invlst.some(item => {
											return item.state != '0'
										})
										if (flg) {
											return callback(new Error('请进行发票真伪核验'));
										}

									}
									callback()
							}
						}
						callback()

					}, trigger: ['blur', 'change']
				}
			],
			"imgInvmod.skpreason": [
				{ type: "string", required: _this.model.imgInvmod.skipped == 'X', message: "必输项" },
			],
			"untamtin":[{
				validator(rule, value, callback) {
					if(_this.trnName.toUpperCase() == 'BFTINV'){
						if(_this.model.imgInvmod.invrep.invfunc == 'X' && Number(_this.model.imgInvmod.untamtin) < Number(_this.model.imgInvmod.invrep.totalamountin) ){
							return callback(new Error('发票占用总金额应该覆盖被替换发票占用总金额'))
						}
						callback()
					}
					callback()
				}
			}]
		}
	}
}