import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import Utils from "~/utils";
import Pts from '~/components/business/commonModel/Pts';

export default {
	mixins: [commonFunctions],
	methods: {
		// gcdgrp.rec.ownref
		onGetRef() {
			let params = this.model.gcdgrp.rec
			if (!this.model.gcdgrp.ben.pts.ptainr) {
				return
			}
			let ptainr = this.model.gcdgrp.ben.pts.ptainr;
			const loading = this.loading();
			Api.post(`/business/ref/gcd?ptaInr=${ptainr}`, params).then(res => {
				if (res.respCode == SUCCESS) {
					loading.close();
					this.model.gcdgrp.rec.ownref = res.data;
				}
			}).catch(() => {
				loading.close();
			});
		},
		setIfnxtflg() {
			this.ifnxtflg = "X";
		},
		// gcdgrp.rec.docprbrol
		calcPrb() {
			let prbref = this.model.gcdgrp.prb.pts.ref;
			switch (this.model.gcdgrp.rec.docprbrol) {
				case "BEN":
					Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.ben.pts);
					this.model.gcdgrp.prb.pts.rol = "PRB";
					if (prbref == "" && this.model.gcdgrp.ben.pts.ref != "") {
						this.model.gcdgrp.prb.pts.ref = this.model.gcdgrp.ben.pts.ref;
					} else {
						this.model.gcdgrp.prb.pts.ref = prbref;
					}
					break;
				case "ISS":
					Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.iss.pts);
					this.model.gcdgrp.prb.pts.rol = "PRB";
					if (prbref == "" && this.model.gidgrp.iss.pts.ref != "") {
						this.model.gcdgrp.prb.pts.ref = this.model.gidgrp.iss.pts.ref;
					} else {
						this.model.gcdgrp.prb.pts.ref = prbref;
					}
					break;
				case "ATB":
					Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.atb.pts);
					this.model.gcdgrp.prb.pts.rol = "PRB";
					if (prbref == "" && this.model.gidgrp.atb.pts.ref != "") {
						this.model.gcdgrp.prb.pts.ref = this.model.gidgrp.atb.pts.ref;
					} else {
						this.model.gcdgrp.prb.pts.ref = prbref;
					}
					break;
				case "AT2":
					Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.at2.pts);
					this.model.gcdgrp.prb.pts.rol = "PRB";
					if (prbref == "" && this.model.gidgrp.at2.pts.ref != "") {
						this.model.gcdgrp.prb.pts.ref = this.model.gidgrp.at2.pts.ref;
					} else {
						this.model.gcdgrp.prb.pts.ref = prbref;
					}
					break;
				case "PRB":
					this.model.gcdgrp.prb.pts = new Pts().data;
					this.model.gcdgrp.prb.pts.rol = "PRB";
					this.model.gcdgrp.prb.pts.ref = prbref;
					break;
			}
		},
		// gcdgrp.rec.payrol
		calcOth() {
			switch (this.model.gcdgrp.rec.payrol) {
				case "APL":
					Utils.copyValueFromVoData(this.model.gcdgrp.oth.pts, this.model.gidgrp.apl.pts);
					this.model.gcdgrp.oth.pts.rol = "OTH";
					break;
				case "ISS":
					Utils.copyValueFromVoData(this.model.gcdgrp.oth.pts, this.model.gidgrp.iss.pts);
					this.model.gcdgrp.oth.pts.rol = "OTH";
					break;
				case "OTH":
					this.model.gcdgrp.oth.pts = new Pts().data;
					this.model.gcdgrp.oth.pts.rol = "OTH";
					break;
			}
		},
		// gcdgrp.rec.nam
		// gcdgrp.cbs.max.cur
		// gcdgrp.cbs.max.amt
		// gcdgrp.apl.pts.nam
		calcName() {
			this.model.gcdgrp.rec.nam = this.model.gcdgrp.cbs.max.cur + " " + this.model.gcdgrp.cbs.max.amt + " " + this.model.gcdgrp.ben.pts.nam;
			this.model.gcdgrp.rec.nam = this.model.gcdgrp.rec.nam.slice(0, 40);
		},
		// gcdgrp.rec.demstat
		clearPresentdet() {
			if (this.model.gcdgrp.rec.demstat != "INCP") {
				this.model.gcdgrp.blk.presentdet = "";
			}
		},
		setNxtflg() {
			if (this.model.extpay == 'X') {
				this.model.nxtflg = "FP";
			} else {
				this.model.nxtflg = "SN";
			}
		},
		setNewexpdatAndNxtflg() {
			if (this.model.extpay !== 'X') {
				this.model.gcdgrp.rec.newexpdat = "";
				this.model.gcdgrp.rec.expludat = "";
			}
			if (this.ifnxtflg === "") {
				this.setNxtflg();
			}
		},
	}
}