import Api from "~/service/Api"
import Utils from "~/utils/index"
export default {
    async onSeaown() {
        const that = this.root;
        that.executeRule("searow").then(res => {
            //TODO 处理数据逻辑
            that.$refs.inftrnps.stmData.data = res.data.trncorco_trnstm.rows;
            this.model.trncorco.trnstm = res.data.trncorco_trnstm;
        })
    },
    async onSeajbh() {
        const that = this.root;
        that.executeRule("seajbh").then(res => {
            //TODO 处理数据逻辑
            that.$refs.inftrnps.stmData.data = res.data.trncorco_trnstm.rows;
        })
    },
    async onSeactr() {
        let rtnmsg = await this.executeRule("seactr")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onSearow() {
        let rtnmsg = await this.executeRule("searow")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onDsp() {
        let rtnmsg = await this.executeRule("dsp")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onImgmodNewimg() {
        let rtnmsg = await this.executeRule("imgmod_newimg")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onImgmodNewhisimg() {
        let rtnmsg = await this.executeRule("imgmod_newhisimg")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onDiaconButdia() {
        let rtnmsg = await this.executeRule("diacon_butdia")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onImgmodHisimg() {
        let rtnmsg = await this.executeRule("imgmod_hisimg")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onHandle(idx,row) {


        let viewurl = "/review/ditopn";

        let pageId = this.model.pageId;
        debugger;

        this.$router.push({path:viewurl,query:{routeParams: {process: "1", commitFlag: "1"},trn:row['INR'],idx:idx,pageId:pageId}});
       
    },

    async onRelrow(idx) {
        this.$confirm('您确定复核该笔交易?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(async ()=>{
            const selIds = [idx+1]; //rowno选中行
            const selDst = "trncorco.trnstm" //列表对应后台模型中的stream
    
            let params = { selDst: selDst, selIds: selIds };
            debugger;
            let initRtnmsg = await this.init();
            if(initRtnmsg.respCode == SUCCESS){
                
            let rtnmsg = await this.executeRule("relrow", params)
            if (rtnmsg.respCode == SUCCESS) {
                debugger;
                let errorMsg = "";
                let fieldErrorsFlag = (JSON.stringify(rtnmsg.fieldErrors) == "{}");
                if(!fieldErrorsFlag){
                    let errorMsgkey = "";
                    let errorMsgVal = "";
                    for (const key in rtnmsg.fieldErrors) {
                        errorMsgkey = key;
                        errorMsgVal = rtnmsg.fieldErrors[key];
                    }
                    errorMsg = errorMsgkey+':'+errorMsgVal;
                    this.$notify.error({title: '错误',message: '复核失败!错误信息['+errorMsg+']'});
                }else{
                    this.$notify({
                        title: '成功',
                        message: '复核成功',
                        type: 'success'
                    });
                    debugger;
                    const that = this.root;
                    that.executeRule("searow").then(res => {
                        //TODO 处理数据逻辑
                        that.$refs.inftrnps.stmData.data = res.data.trncorco_trnstm.rows;
                        this.model.trncorco.trnstm = res.data.trncorco_trnstm;
                    })
                }         
            }
            else {
                let errorMsg = "";
                let fieldErrorsFlag = (JSON.stringify(rtnmsg.fieldErrors) == "{}");
                if(!fieldErrorsFlag){
                    let errorMsgkey = "";
                    let errorMsgVal = "";
                    for (const key in rtnmsg.fieldErrors) {
                        errorMsgkey = key;
                        errorMsgVal = rtnmsg.fieldErrors[key];
                    }
                    errorMsg = errorMsgkey+':'+errorMsgVal;
                }else if(rtnmsg.respMsg){
                    errorMsg = rtnmsg.respMsg;
                }
                this.$notify.error({title: '错误',message: '复核失败!错误信息['+errorMsg+']'});
            }

            }
        
    
        })

    },

    sleep(ms) {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve()
            }, ms)
        })
    },
    async onPrinte() {
        let rtnmsg = await this.executeRule("printe")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onReprow() {
        let rtnmsg = await this.executeRule("reprow")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onRejrow() {
        console.log(this.getSelectedData())

        this.model.trncorco.selinr['rows'] = this.getSelectedData();
        let rtnmsg = await Api.post("trnrel/rejrow", this.wrapper())
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑
            // var cacheFileName = rtnmsg.data.cacheFileName;
            // let rejrowRtnmsg = await Api.post("trncor/init", {params:{"cacheFileName":cacheFileName}})
            // if(rejrowRtnmsg.respCode == SUCCESS){
            //     this.$message({
            //         type: 'success',
            //         message: 'Reject成功!'
            //     });
            //     await this.sleep(2000);
            //     this.$router.go(0);
            // }

            this.$message({
                type: 'success',
                message: 'Reject成功!'
            });
            // await this.sleep(2000);
            // this.$router.go(0);

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onRelcor() {
        let rtnmsg = await this.executeRule("relcor")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onExi() {
        let rtnmsg = await this.executeRule("exi")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },

    async onRecpanDet() {
        let rtnmsg = await this.executeRule("recpan_det")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onSyswrnButshw() {
        let rtnmsg = await this.executeRule("syswrn_butshw")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onRecpanNotmap() {
        let rtnmsg = await this.executeRule("recpan_notmap")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onRecpanButspt() {
        let rtnmsg = await this.executeRule("recpan_butspt")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onRecpanInc() {
        let rtnmsg = await this.executeRule("recpan_inc")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onRecpanButord() {
        let rtnmsg = await this.executeRule("recpan_butord")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onImgmodImage() {
        let rtnmsg = await this.executeRule("imgmod_image")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onRecpanIncben() {
        let rtnmsg = await this.executeRule("recpan_incben")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    async onInftxtButtxmsel() {
        let rtnmsg = await this.executeRule("inftxt_buttxmsel")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败!' });
        }
    },
    onSeainf() {

    },
    display(index, row) {
        const d = this.stmData.data[index]
        const ds = d.split("\t")
        let viewurl = "/#/display/" + ds['10'].toLowerCase() + "?trn=" + ds['1']
        window.open(viewurl, 'newwindow', 'height=1200,width=900,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
    },
    async handleSearch() {
        const that = this.root;
        // if (this.model.searchAllUsers) {
        //     that.executeRule("seajbh").then(res => {
        //         //TODO 处理数据逻辑
        //         that.$refs.inftrnps.stmData.data = res.data.trncorco_trnstm.rows;
        //     })
        // } else {
            // that.executeRule("searow").then(res => {
            //     //TODO 处理数据逻辑
            //     that.$refs.inftrnps.stmData.data = res.data.trncorco_trnstm.rows;
            //     this.model.trncorco.trnstm = res.data.trncorco_trnstm;
            // })
        // }
        const res = await this.executeRule("searow")
        that.$refs.inftrnps.stmData.data = res.data.trncorco_trnstm.rows;
        this.model.trncorco.trnstm = res.data.trncorco_trnstm;
        if(res.data.trncorco_trnstm.rows.length == 0){
            this.$notify({
                title: '成功',
                message: '搜索完毕,无满足条件记录',
                type: 'success'
            });
            }
    },

    async handleReset() {
        this.model.bchcon = "";
        this.model.trncorco.ownref = "";
        this.model.trncorco.relflg = "";
        this.model.usrcon = "";
        this.model.trncorco.inidatfro = "";
        this.model.trncorco.inidattil = "";
        this.model.atp.cod = "";
        this.model.trncorco.dflg = "ALL";
        this.model.atptxt = "";
        this.model.searchAllUsers = false;
    },



}