import Api from "~/service/Api"
import Utils from "~/utils"
import commonFunctions from '~/mixin/commonFunctions.js';
import moment from 'moment'

export default {
	mixins: [commonFunctions],
	methods: {
		async handleSearch() {

			if (this.model.opndatfrom == null) {
				this.$notify.error({ title: '错误', message: '查询开始日期必输!' });
				return;
			}
			if (this.model.opndatto == null) {
				this.$notify.error({ title: '错误', message: '查询结束日期必输!' });
				return;
			}
			if(new Date(this.model.opndatfrom).getTime() > new Date(this.model.opndatto).getTime()){
				this.$notify.error({ title: '错误', message: '开始日期应小于结束日期!' });
				return
			}
			if(this.model.seasta != '' && this.model.seaauthorized == ''){
				this.$notify.error({ title: '错误', message: '选择Status时请先选择 是否已授权!' });
				return
			}
			if(this.model.searol != '' && (this.model.ptyExtkey == '' && this.model.seapty == '') ){
				this.$notify.error({ title: '错误', message: '选择角色时请先输入 当事人编号 或者 当事人名称/BIC编码!' });
				return
			}
			if(this.model.seacur == '' && (this.model.seaamtfr > 0 || this.model.seaamtto > 0)){
				this.$notify.error({ title: '错误', message: '输入金额前请先选择 币种!' });
				return
			}
			if((this.model.seaamtfr > 0 && this.model.seaamtto > 0) && (this.model.seaamtfr > this.model.seaamtto)){
				this.$notify.error({ title: '错误', message: '起始金额不能大于结束金额!' });
				return
			}

			// // 前端检验
			// this.$refs['paramsForm'].validate(async (validStatic) => {
			// 	if (validStatic) {

			const loading = this.loading();
					this.load = true;
					this.model.branch = JSON.parse(sessionStorage.getItem('currentOrg')).departmentNumber
					let rtnmsg = await Api.post("/business/infncd/queryInfncd",
						{
							...this.model,
							pageNum: this.pagination.pageNum,
							pageSize: this.pagination.pageSize
						});
					if (rtnmsg.respCode == SUCCESS) {
						this.load = false;
						this.tableData = rtnmsg.data.list || [];
						this.pagination = {
							pageNum: rtnmsg.data.pageNum || 1,
							pageSize: rtnmsg.data.pageSize || 10,
							total: rtnmsg.data.total
						};
					}
			loading.close();
			// 	} else {
			// 		// 前端校验失败
			// 		this.$notify({
			// 			title: '失败',
			// 			message: '校验失败',
			// 			type: 'error',
			// 		});
			// 	}
			// })

		},
		handleReset() {
			this.model.seaownref = "";
			this.model.isGuarantee = "";
			this.model.nam = "";
			this.model.ptyExtkey = "";
			this.model.seapty = "";
			this.model.searef = "";
			this.model.ptyNam = "";
			this.model.searol = "";
			this.model.usrExtkey = "";
			this.model.seasta = "";
			this.model.seacur = "";
			this.model.seaamtfr = "";
			this.model.seaamtto = "";
			this.model.seagtyp = "";
			this.model.relflg = "";
			this.model.segtyp = "";
			this.model.seaauthorized = "";
			this.ptyExtkeyChange();
			this.seaptyChange();
		},
		async exportExcel(){
			const loading = this.loading();
			let res = await Api.post("/business/infncd/exportExcel",{
				...this.model,
				// pageNum: this.pagination.pageNum,
				// pageSize: this.pagination.pageSize
			});
			if (res.respCode == SUCCESS) {
			let name=moment(new Date()).format('yyyy-MM-DD HH:mm:ss') ;
				Utils.exportToExcel (res.data, "索偿查询"+name+".xlsx", "索偿查询") ;
			}
			loading.close();
		  },
	}
}