import Api from "~/service/Api"
import Utils from "~/utils/index"
export default {
    async onDitpButgetref() {
        let rtnmsg = await Api.post("ditopn/executeRule/ditp.butgetref", Utils.flatObject(this.model))
        if (rtnmsg.respCode == "AAAAAA") {
            //TODO 处理数据逻辑
            const ownref = rtnmsg.data.didgrp_rec_ownref

            const h = this.$createElement;
            this.$msgbox({
                title: '获取结果',
                message: h('p', null, [
                    h('div', { style: 'margin-left: 25%'}, `参考号：${ownref}`),
                    h('div', { style: 'margin-left: 25%' }, '是否将结果填入表单？')
                ]),
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(action => {
                this.model.didgrp.rec.ownref = ownref
                this.$message({
                    type: 'success',
                    message: '填入成功！'
                });
            }).catch(action => {
                this.$message({
                    type: 'info',
                    message: "已取消"
                })
            });
        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败！' });
        }
    },
    async onAplpDet() {
        let rtnmsg = await Api.post("ditopn/executeRule/ditp.aplp.det", Utils.flatObject(this.model))
        if (rtnmsg.respCode == "AAAAAA") {
            //TODO 处理数据逻辑
            // console.log(rtnmsg.data);
        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败！' });
        }
    },
    onBenpDet() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/benp_det", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onRevclauseButtxmsel() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/revclause_buttxmsel", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLcrgodButtxmsel() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/lcrgod_buttxmsel", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLcrdocButtxmsel() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/lcrdoc_buttxmsel", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onAdlcndButtxmsel() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/adlcnd_buttxmsel", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onInsbnkButtxmsel() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/insbnk_buttxmsel", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onRmbpDet() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/rmbp_det", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onDefdetButtxmsel() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/defdet_buttxmsel", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onPreperButtxmsel() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/preper_buttxmsel", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onSetmodDet() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/setmod_det", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLiaallButmisamt() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/liaall_butmisamt", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLiaallButmissig() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/liaall_butmissig", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onWrkpDet() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/wrkp_det", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onOthpDet() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/othp_det", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLimptsGet1() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/limpts_get1", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLimptsGet2() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/limpts_get2", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLimmodTrycal() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/limmod_trycal", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLiaccvAdd() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/liaccv_add", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
    },
    onLiaccvDel() {
        this.$parent.$parent.$parent.$parent.$refs.modelForm.validate(async valid => {
            if (!valid)
                return;
            let rtnmsg = await Api.post("ditopn/liaccv_del", Utils.flatObject(this.model))
            if (rtnmsg.respCode == "AAAAAA") {
                //TODO 处理数据逻辑

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

    },
    async handleDisplay(index, row){
        let cortyp = row.cortyp
        let rtnmsg
        if (cortyp == 'SWT'|| cortyp == 'FMT' || cortyp == 'CMT') {
            this.model.setmod.msgmod.doccod = row.id
            rtnmsg = await Api.post('cptopn/msgmod_butshw', {  data: Utils.flatObject(this.model) })
        } else {
            this.model.trnmod.trndoc.doccod = row.id
            this.model.trnmod.trndoc.cortyp = cortyp
            const params = {
                index: index
            }
            rtnmsg = await Api.post("ditopn/executeDocpan/trnmod.trndoc.doccur.butshw", {  ...Utils.flatObject(this.model), params })
        }
        if (rtnmsg.respCode == "AAAAAA") {
            if (cortyp == 'SWT' || cortyp == 'FMT' || cortyp == 'CMT') {
                let viewurl = rtnmsg.data.setmod_msgmod_docpth; 
                this.viewurl = viewurl
                this.title="报文"
                //window.open(viewurl, 'newwindow', 'height=1200,width=800,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
            } 
            else if(cortyp == 'ELC')
            {
                 Modal.info({title:'电证报文',content:<div style={{height:400,overflow:'auto'}}><ELCMessage mty={row.id} message={rtnmsg.data["\\trnmod\\trndoc\\docinf"]}/></div>,
                         width:1000,
                        
                     })
            }
            else {
                // let url = rtnmsg.data.trnmod_trndoc_smh_docpth;
                this.title = "面函"
                let viewurl = "/#/docpan/show";
                let XMLdata;
                if(row.pandsc=="国内信用证"){
                    window.sessionStorage.docTXT = ''
                    window.sessionStorage.docXML = rtnmsg.data.litbenl1blk;
                }
                else if(row.pandsc=="开立国内信用证备查表"){
                    window.sessionStorage.docTXT = ''
                    window.sessionStorage.docXML= rtnmsg.data.litapll1blk
                }
                else if(row.pandsc=="elcs.101.001.01"){
                    console.log(rtnmsg.data.trnmod_trndoc_doceot[index].doctxt);
                    window.sessionStorage.docXML = ''
                    window.sessionStorage.docTXT = ''
                    rtnmsg.data.trnmod_trndoc_doceot[index].doctxt.rows.forEach(element => {
                        window.sessionStorage.docTXT +=element+"\r\n"
                    });
                    console.log( window.sessionStorage.docTXT);
                }  
                else if(row.pandsc=="MT799"){
                    window.sessionStorage.docTXT = ''
                    XMLdata = rtnmsg.data.litbenl1blk
                }
                
                
                
                
                window.open(viewurl, 'newwindow', 'height=1200,width=800,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
            }
            this.dialogOpen=true
        }
        else {
            this.$notify.error({title: '错误',message: '服务请求失败！'})
        }
    },
    async handleDetail(index, row){
        const params = {
            index: index
        }
        let rtnmsg = await Api.post("ditopn/executeDocpanDetail/trnmod.trndoc.doccur.butadd", {  ...Utils.flatObject(this.model), params })
        if (rtnmsg.respCode == "AAAAAA") {
            //TODO 处理数据逻辑
            let viewurl ="/#/docpan/detail";
            window.open(viewurl, 'newwindow', 'height=1200,width=900,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
        }
    },
    async BlurBennam(e){
        let rtnmsg = await Api.post("ditopn/default/ditp.remark", Utils.flatObject(this.model))
        if (rtnmsg.respCode == "AAAAAA") {
            //TODO 处理数据逻辑
            this.model.ditp.remark = rtnmsg.data.ditp_remark
        }
    },
    async BlurAplname(e){
        let rtnmsg = await Api.post("ditopn/default/ditp.remark", Utils.flatObject(this.model))
        if (rtnmsg.respCode == "AAAAAA") {
            //TODO 处理数据逻辑
            this.model.ditp.remark = rtnmsg.data.ditp_remark
        }
    },
    async BlurSignam(e){
        let rtnmsg = await Api.post("ditopn/default/ditp.remark", Utils.flatObject(this.model))
        if (rtnmsg.respCode == "AAAAAA") {
            //TODO 处理数据逻辑
            this.model.ditp.remark = rtnmsg.data.ditp_remark
        }
    },
    async onExtkey(e){

    }
}