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

export default {
	mixins: [commonFunctions],
	methods: {
		async getBranchList() {
			const loading = this.loading();
			let res = await Api.post('/public/quesel/getBranchList');
			if (res.respCode == SUCCESS) {
				this.model.bchtypList = res.data.list;
			}
			loading.close();
        },
        reset(){
            this.model.bopquep.ywcredat = null;
            this.model.bopquep.ywtildat = null;
            this.model.bopquep.rptno = "";

        },
        dealErr(row){
           if(row.errflg==="F"){
            this.$notify.error({ title: '提示', message: '该批次无错误反馈 ' });
            return;
           }
           if(row.bassta==="X"||row.vrfsta==="X"||row.dclsta==="X"){
           
            this.$notify.error({ title: '提示', message: ' 该数据记录已经生成报文请等待反馈再进行修改操作' });
              return;
           }
           if(row.bassta==="G"||row.vrfsta==="G"||row.dclsta==="G"){
           
            this.$notify.error({ title: '提示', message: ' 该数据记录已经撤销,不能进行修改操作' });
              return;
           }
           let objtype = row.objtyp
            switch (objtype) {
                case 'DBA':
                case 'DBG':
                    this.routerPush({
                        path: "/business/dbaame",
                        query: {inr: row.objinr}
                    })
                    break
                case 'DBB':
                case 'DBH':
                case 'DBN':
                    this.routerPush({
                        path: "/business/dbbame",
                        query: {inr: row.objinr}
                    })
                    break
                case 'DBC':
                case 'DBK':
                case 'DBP':
                    this.routerPush({
                        path: "/business/dbcame",
                        query: {inr: row.objinr}
                    })
                    break
                case 'DBD':
                case 'DBR':
              
                    this.routerPush({
                        path: "/business/dbdame",
                        query: {inr: row.objinr}
                    })
                    break
                case 'DBE':
                case 'DBQ':
                    this.routerPush({
                        path: "/business/dbeame",
                        query: {inr: row.objinr}
                    })
                    break
                case 'DBF':
                case 'DBS':
                    this.routerPush({
                        path: "/business/dbfame",
                        query: {inr: row.objinr}
                    })
                    break
                case 'DBJ':
                case 'DBV':
                    this.routerPush({
                        path: "/business/dbjame",
                        query: {inr: row.objinr}
                    })
                    break
                case 'DBW':
                case 'DBY':
                    this.routerPush({
                        path: "/business/dbwame",
                        query: {inr: row.objinr}
                    })
                    break
                default :
                this.$notify.error({title:'错误',message:'该数据有误,请联系管理员'})
                  return ;
                }





        },
        async currentChange(num){
			this.pagination.pageNum = num 
			this.query()
        },
		async query(){
			if (this.model.bopquep.ywcredat == null) {
				this.$notify.error({ title: '错误', message: '查询开始日期必输!' });
              return;
			}
			if (this.model.bopquep.ywtildat == null) {
				this.$notify.error({ title: '错误', message: '查询结束日期必输!' });
				return;
			}
			if(new Date(this.model.bopquep.ywcredat).getTime() > new Date(this.model.bopquep.ywtildat).getTime()){
				this.$notify.error({ title: '错误', message: '开始日期应小于结束日期!' });
				return
			}
			let day = 731 * 24 * 3600 * 1000
			if (new Date(this.model.bopquep.ywtildat).getTime() - new Date(this.model.bopquep.ywcredat).getTime() > day) {
				this.$notify.error({title:'错误',message:'请将查询条件中时间范围控制在2年内(含)'})
				return
			}
			const loading = this.loading();
            const rtnmsg = await Api.post(`/${this.moduleRouter()}/${this.root.trnName}/query`,
            {
                ...this.model.bopquep,
                pageNum: this.pagination.pageNum,
                pageSize: this.pagination.pageSize
            });
			if (rtnmsg.respCode === SUCCESS) {
			  this.model.boperrlst = rtnmsg.data.list;
			  console.log( this.boperrlst);
			  this.pagination.total =rtnmsg.data.total;
			}
			else{
                this.model.boperrlst = rtnmsg.data.list;
                this.pagination.total =rtnmsg.data.total;
			}
			loading.close();
		  }

}
}