import event from "../event/index";
import Api from "~/service/Api";
import commonFunctions from '~/mixin/commonFunctions.js';
export default {
	mixins: [event, commonFunctions],
	methods: {
		changePridsp(e) {
      if (e == undefined) {
				return;
			}
			this.model.dnfenc.zhruzh = '';
			this.zhruzhList = [];
			if (!this.model.dnfenc.pridsp || !this.model.dnfenc.kehuzh) {
				return;
			}
			var cur = '';
			for (var i = 0; i < this.accountList.length; i++) {
				if (this.accountList[i].value == this.model.dnfenc.kehuzh) {
					cur = this.accountList[i].cur;
				}
			}
			let params = {
				ptyinr: this.model.nidgrp.apl.pts.ptyinr,
				cur: cur,
				pridsp: this.model.dnfenc.pridsp,
				wrkbchinr: this.model.nidgrp.rec.branchinr,
				transName: "nitenc"
			};
			const loading = this.loading('正在请求数据');
			Api.post(`/business/nitenc/rulePridspN1000`, params).then(res => {
				if (res.respCode == SUCCESS) {
          console.log(res.data);
          if (res.data.length == 1 && res.data[0].indexOf('\r\n') !== -1) {
            let tempList = res.data[0].split('\r\n')
            for (let i = 0; i < tempList.length; i++) {
              this.zhruzhList.push({
                value: tempList[i],
                label: tempList[i]
              });
            }
          } else {
						for (let i = 0; i < res.data.length; i++) {
							this.zhruzhList.push({value : res.data[i], label : res.data[i]});
						}
					}
					if (this.zhruzhList.length > 0) {
						this.model.dnfenc.zhruzh = this.zhruzhList[0].value;
					}
				} else {
					this.$message.error("本金转入账户查询异常:" + res.respMsg);
				}
				loading.close();
			});
		},
		changeIntdsp(e) {
      if (e == undefined) {
				return;
			}
			this.lxzyzhList = [];
			this.model.dnfenc.lxzyzh = '';
			if (!this.model.dnfenc.intdsp || !this.model.dnfenc.kehuzh) {
				return;
			}
			var cur = '';
			for (var i = 0; i < this.accountList.length; i++) {
				if (this.accountList[i].value == this.model.dnfenc.kehuzh) {
					cur = this.accountList[i].cur;
				}
			}
			let params = {
				ptyinr: this.model.nidgrp.apl.pts.ptyinr,
				cur: cur,
				intdsp: this.model.dnfenc.intdsp,
				wrkbchinr: this.model.nidgrp.rec.branchinr,
				transName: "nitenc"
			};
			const loading = this.loading('正在请求数据');
			Api.post(`/business/nitenc/ruleIntdspN1000`, params).then(res => {
				if (res.respCode == SUCCESS) {
          console.log(res.data);
          if (res.data.length == 1 && res.data[0].indexOf('\r\n') !== -1) {
            let tempList = res.data[0].split('\r\n')
            for (let i = 0; i < tempList.length; i++) {
              this.lxzyzhList.push({
                value: tempList[i],
                label: tempList[i]
              });
            }
          } else {
						for (let i = 0; i < res.data.length; i++) {
							this.lxzyzhList.push({value : res.data[i], label : res.data[i]});
						}
					}
					if (this.lxzyzhList.length > 0) {
						this.model.dnfenc.lxzyzh = this.lxzyzhList[0].value;
					}
				} else {
					this.$message.error("利息转入账户查询异常:" + res.respMsg);
				}
				loading.close();
			});
		},
    changeKehuzh(e) { //根据保证金账户下拉框改变操作类型
      if (e == undefined) {
				return;
			}
			this.model.dnfenc.ccvtyp = '';
			this.changeCcvtyp(e);
			this.operationsList = [];
			this.tableData = [];
			// if (this.model.dnfenc.kehuzh != '') {
			// 	this.operationsList.push({ label:"保证金账户冻结",value: "A"});
			// 	this.operationsList.push({ label:"保证金账户解冻",value: "B"});
			// 	this.operationsList.push({ label:"定期转活期",value: "C"});
			// }
		},
		changeZhqtyp(e) {
      if (e == undefined) {
				return;
			}
      this.model.dnfenc.tizamt = '0';
			if (!this.model.dnfenc.zhqtyp) {
				this.model.dnfenc.pridsp = '';
				this.model.dnfenc.zhruzh = '';
				this.model.dnfenc.intdsp = '';
				this.model.dnfenc.lxzyzh = '';
			}
			else{
				if(this.model.dnfenc.zhqtyp == "B" && this.model.dnfenc.zhqucs != "0"){
					this.model.dnfenc.zhqtyp = '';
					this.$message.error("该定期保证金账户已经办理过一次部分提支,不能再次办理,请选择“存款销户”");
				}	
			}

			// else if (this.model.dnfenc.zhqtyp != 'B') {
			// 	this.model.dnfenc.tizamt = '';
			// } 
			// if (this.model.dnfenc.zhqtyp == 'B') {
			// 	if (Number(this.model.dnfenc.zhqucs) != 0) {
			// 		this.model.dnfenc.zhqtyp = '';
			// 		this.$message.error("该定期保证金账户已经办理过一次部分提支,不能再次办理,请选择“存款销户”");
			// 	}
			// 	if (!this.model.dnfenc.qicuje) {
			// 		this.$message.warning("起存金额为空,请点Get获取!");
			// 	}
			// }
		},
		changeCcvtyp(e) {
      if (e == undefined) {
				return;
			}
			if (!this.model.dnfenc.ccvtyp) {
				this.clear(1);
			} else if (this.model.dnfenc.ccvtyp != 'C') {
				this.model.dnfenc.zhqtyp = '';
				this.model.dnfenc.tizamt = '';
				this.changeZhqtyp(e);
			}
			if (this.model.dnfenc.ccvtyp == 'C') {
				if (!this.model.dnfenc.zhqucs) {
					this.onDnfencGet();
				}
				if(!this.model.dnfenc.yewudh)
			  {
			    this.$message.error("请先点击查询按钮,再进行操作!")
			  }
				if (this.model.dnfenc.jiluzt == '1') {
					this.$message.error("当前账号已经在核心销户,国结不允许进行操作!");
					this.model.dnfenc.ccvtyp = '';
				}
			}
		},
		changeTizamt() {
			if (!this.model.dnfenc.tizamt) {
				this.model.dnfenc.tizamt = '0.00';
				return;
			}
			var tizamt = Number(this.model.dnfenc.tizamt);
			var sum = Number(this.model.dnfenc.zhhuye) - Number(this.model.dnfenc.qicuje);
			if (tizamt > 0 && tizamt > sum) {
				this.model.dnfenc.tizamt = '0';
				this.$message.error('金额输入有误!错误原因:部分提支金额<=(账户余额-起存金额)');
			}
		},
		clear(e) {
      if (e == undefined) {
				return;
			}
			this.model.dnfenc.zhqtyp = '';
			this.model.dnfenc.tizamt = '';
			this.model.dnfenc.zhqucs = '';
			this.model.dnfenc.qicuje = '';
			this.model.dnfenc.qixirq = '';
			this.model.dnfenc.zhhuye = '';
			this.model.dnfenc.yewudh = '';	
			this.model.dnfenc.intdsp = '';
			this.model.dnfenc.lxzyzh = '';
			this.model.dnfenc.zhruzh = '';
			this.model.dnfenc.pridsp = '';	
    },
    initTableData(){
      if(!this.model.dnfenc.kehuzh){
        return;
      }
      let tableData = [];
      tableData.push(this.transTableData(this.model.dnfenc));
      this.$set(this.codes,'tableData',tableData);
    },
    transTableData(tableData) {
			if (!tableData) {
				return;
			}
			let result = tableData;
			if (tableData.jiluzt) {
				result.jiluzt = this.tranSta(tableData.jiluzt);
			}
			if (tableData.kemucc) {
				result.kemucc = this.tranKemucc(tableData.kemucc);
			}
			if (tableData.lilvbh) {
				result.lilvbh = this.tranLilvbh(tableData.lilvbh);
			}
			if (tableData.cunqii) {
				result.cunqii = this.tranCunq(tableData.cunqii);
			}
			if (tableData.cunkzl) {
				result.cunkzl = this.tranCunkzl(tableData.cunkzl);
			}
			return result;
		},
		tranSta(jiluzt) {
			switch (jiluzt) {
				case "0":
					return "正常";
				case "1":
					return "销户";
				case "2":
					return "只收不付冻结";
				case "3":
					return "封闭冻结";
				case "4":
					return "删除";
				case "5":
					return "未使用";
				case "6":
					return "结清";
				case "7":
					return "打印";
				case "8":
					return "碰库";
				case "9":
					return "不动户";
				case "A":
					return "不动户转收益";
				case "B":
					return "死亡户";
				case "C":
					return "报案户";
				case "D":
					return "请与开户行接洽";
				case "E":
					return "不能在他行销记户";
				case "F":
					return "准客户";
				case "G":
					return "未复核";
				case "R":
					return "被当日冲正";
				case "S":
					return "被隔日冲正";
				case "J":
					return "禁用";
				case "Y":
					return "预销户";
				case "Z":
					return "质押冻结";
				case "T":
					return "凭证在途";
				default:
					return "";
			}
		},
		tranKemucc(kemucc) {
			switch (kemucc) {
				case "S":
					return "对私活期";
				case "C":
					return "对公活期";
				case "F":
					return "对私定期";
				case "E":
					return "对公定期";
				case "V":
					return "贷款";
				case "Q":
					return "欠息";
				case "I":
					return "内部账";
				case "O":
					return "表外账";
				case "T":
					return "拆借贴现投资账";
				case "Y":
					return "存放同业主文件";
				default:
					return "";
			}
		},
		tranLilvbh(lilvbh) {
			switch (lilvbh) {
				case "100":
					return "定活两便";
				case "101":
					return "活期储蓄存款";
				case "102":
					return "整存整取定期存款";
				case "103":
					return "零存整取";
				case "105":
					return "存本取息";
				case "106":
					return "通知存款";
				case "107":
					return "大面额定期";
				case "108":
					return "活期对公存款";
				case "109":
					return "公积金存款";
				default:
					return "";
			}
		},
		tranCunq(cunqii) {
			switch (cunqii) {
				case "200":
					return "活期";
				case "201":
					return "一天";
				case "207":
					return "七天";
				case "101":
					return "一月";
				case "103":
					return "三月";
				case "106":
					return "六月";
				case "109":
					return "九月";
				case "001":
					return "一年";
				case "002":
					return "二年";
				case "003":
					return "三年";
				case "005":
					return "五年";
				case "006":
					return "六年";
				case "008":
					return "八年";
				case "010":
					return "十年";
				case "020":
					return "二十年";
				case "000":
					return "自定义";
				default:
					return "";
			}
		},
		tranCunkzl(cunkzl) {
			switch (cunkzl) {
				case "00":
					return "普通活期";
				case "01":
					return "整存整取";
				case "02":
					return "定活两便";
				case "03":
					return "存本取息";
				case "04":
					return "零存整取";
				case "05":
					return "通知存款";
				case "06":
					return "教育储蓄";
				case "07":
					return "整存零取";
				case "08":
					return "凭证式国债";
				case "09":
					return "理财通";
				case "10":
					return "对公活期";
				case "11":
					return "对公整存整取";
				case "12":
					return "对公大额存款";
				case "15":
					return "对公通知存款";
				case "16":
					return "对公大额通知存款";
				case "17":
					return "储寿保";
				case "18":
					return "理财产品";
				case "19":
					return "购汇保证金";
				case "20":
					return "对公结构性存款";
				case "21":
					return "对公存款周计划";
				case "28":
					return "储蓄国债";
				case "29":
					return "黄金理财";
				case "30":
					return "活期宝";
				default:
					return "";
			}
    },
    //操作类型
    defaulCcvtyp(){
      let businessType = this.$route.query.businessType;
      if (businessType &&  (businessType == 'TRN' || businessType == 'SPT')) {
        let operationsList = [];
        if(this.model.dnfenc.ccvtyp == 'A'){
          operationsList.push({
            label: "保证金账户冻结",
            value: "A"
          });
        }else if(this.model.dnfenc.ccvtyp == 'B'){
          operationsList.push({
            label: "保证金账户解冻",
            value: "B"
          });
        }else if(this.model.dnfenc.ccvtyp == 'C'){
          operationsList.push({
            label: "定期转活期",
            value: "C"
          });
        }
        this.$set(this.codes, 'operationsList', operationsList);
      }
    },
	},
}
//你可以添加自动default处理