import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import Utils from "~/utils/index";
import Pts from '~/components/business/commonModel/Pts';
import moment from 'moment';
import commonDepend from "~/mixin/commonDepend";
export default {
	mixins: [commonFunctions,commonDepend],
	methods: {
		async getAplInfo() {
			this.model.didgrp.apl.pts.nam = this.model.didgrp.apl.pts.cnnam;
			let datas = {
				ptyinr: this.model.didgrp.apl.pts.ptyinr,
				ptainr: this.model.didgrp.apl.pts.ptainr,
			}
			const loading = this.loading();
			let res = await Api.post(`/Domlc/ditopnRule/getAplInfo`, datas);
			if (res.respCode == SUCCESS) {
				loading.close();
				this.model.didgrp.rec.idcode = res.data.idcode;
				this.model.ditp.aplname = res.data.ptanam;
				this.$set(this.codes, 'actset', res.data.actset);
				if (res.data.actset.length >= 1) {
					this.model.didgrp.apl.pts.extact = res.data.actset[0];
				}
			} else {
				loading.close();
			}
			let data2={
				extkey: this.model.didgrp.apl.pts.extkey.split("-")[0],
			}
			let res2 = await Api.post(`/Domlc/ditopnRule/getEcif0905`,data2);
			if(res2.respCode == "AAAAAA"){
				if ( res2.data.cod == "Y"){
					this.$set(this.codes, 'aplPartygroupNo', res2.data.res.Partground_No);
				}
				else{
					this.$set(this.codes, 'aplPartygroupNo', "");
				}
			}
			this.setfinrenflg();
		},
		async getBenInfo() {
			if(this.model.didgrp.ben.ptytyp!="F"){
				this.$set(this.codes, 'bendisabled', false);
			}
			this.model.didgrp.ben.pts.nam = this.model.didgrp.ben.pts.cnnam;
			if (this.model.didgrp.ben.pts.ptyinr != "") {
				let datas = {
					ptyinr: this.model.didgrp.ben.pts.ptyinr,
					ptainr: this.model.didgrp.ben.pts.ptainr,
				}
				const loading = this.loading();
				let res = await Api.post(`/Domlc/ditopnRule/getBenInfo`, datas);
				if (res.respCode == SUCCESS) {
					loading.close();
					this.model.ditp.bennam = res.data.ptanam;
					this.$set(this.codes, 'actset', res.data.actset);
					if (res.data.actset && res.data.actset.length >= 1) {
						this.model.didgrp.ben.pts.extact = res.data.actset[0];
					}
				} else {
					loading.close();
				}
			}
			if(this.model.didgrp.ben.pts.extkey !=""){
				let data2={
					extkey: this.model.didgrp.ben.pts.extkey.split("-")[0],
				}
				let res2 = await Api.post(`/Domlc/ditopnRule/getEcif0905`,data2);
				if(res2.respCode == "AAAAAA"){
					if ( res2.data.cod == "Y"){
						this.$set(this.codes, 'benPartygroupNo', res2.data.res.Partground_No);
					}
					else{
						this.$set(this.codes, 'benPartygroupNo', "");
					}
				}
			}
			this.setfinrenflg();
		},
		bdflgChange() {
			this.model.didgrp.rmb.pts = new Pts().data;
		},
		lcrtypChange(){
			this.model.didgrp.cmb.pts = new Pts().data;
		},
		fenctgChange() {
			this.model.didgrp.rec.avbwth = "";
			this.model.didgrp.avb.pts = new Pts().data;
		},
		avbbyChange() {
			if (this.model.didgrp.rec.avbby == 'D') {
				this.model.didgrp.blk.defdet = "货物装运日/服务提供日后" + this.model.didgrp.rec.tenmaxday + "天";
			}
			else {
				this.model.didgrp.blk.defdet = "";
				this.model.didgrp.rec.tenmaxday = 0;
			}
		},
		avbwthChange(){
			switch (this.model.didgrp.rec.avbwth) {
				case "A":
					Utils.copyValueFromVoData(this.model.didgrp.avb.pts, this.model.didgrp.adv.pts);
					this.model.didgrp.avb.pts.rol = "AVB";
					break;
				case "C":
					Utils.copyValueFromVoData(this.model.didgrp.avb.pts, this.model.didgrp.cmb.pts);
					this.model.didgrp.avb.pts.rol = "AVB";
					break;
				case "I":
					Utils.copyValueFromVoData(this.model.didgrp.avb.pts, this.model.didgrp.iss.pts);
					this.model.didgrp.avb.pts.rol = "AVB";
					break;
				case "S":
					this.model.didgrp.avb.pts = new Pts().data;
					this.model.didgrp.avb.pts.rol = "AVB";
					break;
				case "O":
					this.model.didgrp.avb.pts = new Pts().data;
					this.model.didgrp.avb.pts.rol = "AVB";
					break;
			}
		},
		hwmsupdateChange(){
			if(this.model.ditamep.hwmsupdate==""){
				this.model.swiadd.lcrgod = "";
			}
		},
		djyqupdateChange(){
			if(this.model.ditamep.djyqupdate==""){
				this.model.swiadd.lcrdoc = "";
			}
		},
		fjtkupdateChange(){
			if(this.model.ditamep.fjtkupdate==""){
				this.model.swiadd.adlcnd = "";
			}
		},
		zsupdateChange(){
			if(this.model.ditamep.zsupdate==""){
				this.model.swiadd.insbnk = "";
			}
		},
		mytypeChange() {
			if(this.model.didgrp.rec.mytype!='3'){
				this.model.didgrp.rec.hmyamt = 0;
				this.model.didgrp.rec.fmyamt = 0;
			}
			if(this.model.didgrp.rec.mytype=='F'){
				this.model.didgrp.rec.shpfro="";
				this.model.didgrp.rec.shpto="";
				this.model.didgrp.rec.shptrs = "";
			}
			if(this.model.didgrp.rec.mytype=='H'){
				this.model.didgrp.rec.shppro="";
			}
			this.model.didgrp.rec.tratyp="";
			this.model.didgrp.rec.sdsrfs="";
		},
		tratypChange(){
			if(this.model.didgrp.rec.tratyp!='08'){
				this.model.didgrp.rec.sdsrfs="";
			}
		},
		shpparChange(){
			if(this.model.didgrp.rec.shppar!='ALWD'){
				this.model.didgrp.rec.fqzytgfw="";
				this.model.didgrp.rec.fqtime="";
			}
		},
		fqzytgfwChange(){
			if(this.model.didgrp.rec.fqzytgfw!='ALWD'){
				this.model.didgrp.rec.fqtime="";
			}
		},
		litameadvChange(){
			if(this.model.litameadv!='SPEC'){
				this.model.ameadvrmk="";
			}
		},
		newexpdatChange(){
			if(this.model.swiadd.newexpdat!=null&&this.model.swiadd.newexpdat!=""){
				this.model.didgrp.rec.expdat = this.model.swiadd.newexpdat;
			}
			else{
				this.model.didgrp.rec.expdat = this.model.olddidgrp.rec.expdat;
			}
			if (moment(this.model.didgrp.rec.expdat).diff(moment(this.model.olddidgrp.rec.expdat)) !=0) {
				this.customAddModify(this.model.didgrp.rec, 'expdat');
			}
			this.root.$refs["modelForm"].validateField([`swiadd.newshpdat`]);
		},
		newshpdatChange(){
			if(this.model.swiadd.newshpdat!=null&&this.model.swiadd.newshpdat!=""){
				this.model.didgrp.rec.shpdat = this.model.swiadd.newshpdat;
			}
			else{
				this.model.didgrp.rec.shpdat = this.model.olddidgrp.rec.shpdat;
			}
			if (moment(this.model.didgrp.rec.shpdat).diff(moment(this.model.olddidgrp.rec.shpdat)) !=0) {
				this.customAddModify(this.model.didgrp.rec, 'shpdat');
			}
			this.root.$refs["modelForm"].validateField([`swiadd.newexpdat`]);
		},
		changeNam(){
			this.model.didgrp.ben.pts.nam = this.model.didgrp.ben.pts.cnnam;
			this.model.didgrp.apl.pts.nam = this.model.didgrp.apl.pts.cnnam;
			this.setfinrenflg();
		},
		amedatChange(){
			this.root.$refs["modelForm"].validateField([`swiadd.newexpdat`]);
		},
		setfinrenflg(){
			if (this.model.didgrp.apl.pts.cnnam.indexOf("租赁") != -1||this.model.didgrp.ben.pts.cnnam.indexOf("租赁") != -1) {
				this.model.didgrp.rec.finrenflg = "Y";
				this.customRemoveModify(this.model.didgrp.rec,"finrenflg");
			}
			if (this.model.didgrp.rec.modifySet && this.model.didgrp.rec.modifySet.includes('finrenflg')) {
				return;
			}
			this.model.didgrp.rec.finrenflg = "N";
		},
		setOldAmenbr(){
			if (this.model.swiadd.modifySet && this.model.swiadd.modifySet.includes('amenbr')) {
			}
			else{
				this.model.swiadd.amenbr =this.model.olddidgrp.rec.amenbr;
			}
			this.model.didgrp.rec.amenbr =this.model.olddidgrp.rec.amenbr;
			this.model.ditamep.amenbr =this.model.olddidgrp.rec.amenbr;
		},
		setNewAmenbr(){
			if (this.model.swiadd.modifySet && this.model.swiadd.modifySet.includes('amenbr')) {
			}
			else{
				this.model.swiadd.amenbr =this.model.olddidgrp.rec.amenbr+1;
			}
			this.model.didgrp.rec.amenbr =this.model.olddidgrp.rec.amenbr+1;
			this.model.ditamep.amenbr =this.model.olddidgrp.rec.amenbr+1;
		},
		ifBankChange(newrol,oldrol){
			if(newrol.bankno&&newrol.bankno.trim()!=""&&newrol.bankno.trim()!=oldrol.bankno.trim()){
			  return true;
			}
			if(newrol.jigomc&&newrol.jigomc.trim()!=""&&newrol.jigomc.trim()!=oldrol.jigomc.trim()){
			  return true;
			}
			if(newrol.dizhii&&newrol.dizhii.trim()!=""&&newrol.dizhii.trim()!=oldrol.dizhii.trim()){
			  return true;
			}
			if(newrol.youzbm&&newrol.youzbm.trim()!=""&&newrol.youzbm.trim()!=oldrol.youzbm.trim()){
			  return true;
			}
			if(newrol.dihdig&&newrol.dihdig.trim()!=""&&newrol.dihdig.trim()!=oldrol.dihdig.trim()){
			  return true;
			}
			return false;
		},
		ifAplBenChange(newrol,oldrol,newbankrol,oldbankrol){
			if(newrol.cnnam&&newrol.cnnam.trim()!=""&&newrol.cnnam.trim()!=oldrol.cnnam.trim()){
			  return true;
			}
			if(newrol.cnadr&&newrol.cnadr.trim()!=""&&newrol.cnadr.trim()!=oldrol.cnadr.trim()){
			  return true;
			}
			if(newrol.youzbm&&newrol.youzbm.trim()!=""&&newrol.youzbm.trim()!=oldrol.youzbm.trim()){
			  return true;
			}
			if(newrol.dihdig&&newrol.dihdig.trim()!=""&&newrol.dihdig.trim()!=oldrol.dihdig.trim()){
			  return true;
			}
			if(newrol.extact&&newrol.extact.trim()!=""&&newrol.extact.trim()!=oldrol.extact.trim()){
			  return true;
			}
			if(newbankrol.bankno&&newbankrol.bankno.trim()!=""&&newbankrol.bankno.trim()!=oldbankrol.bankno.trim()){
			  return true;
			}
			if(newbankrol.jigomc&&newbankrol.jigomc.trim()!=""&&newbankrol.jigomc.trim()!=oldbankrol.jigomc.trim()){
			  return true;
			}
			return false;
		}
	}
}