<template>
    <div>
    </div>
</template>

<script>
import CryptoJS from "crypto-js";
export default {
    data() {
        return {
        oaurl:'',    
        }
    },    
    created() {
        let Wopinions = {
            taskActorName:'第三方注册系统编码',
            actUserName:'1',
            opinionDate:'Web接口',
            opinionConfirm:'调取OA用户密码',
            opinionText:'调取OA地址',
        }
        this.$store.dispatch('GetUserVM',Wopinions).then(restPwd=>{
            this.opinionDate = restPwd.opinionDate;
            
                //获取url参数
                let roterS = window.location.href.toString();
                let r1 = roterS.split('?');
                let procedureCode = '';//
                let caseCode = '';//caseCodeCode
                let applicationCode='';//applicationCode
                let userCode='';//发送人code
                let actCode = '';//合同code
                let projectCode = '';//项目code
                let work = '';//判断发送退回
                let isAudit = '';//
                let canManual = '';//
                let opinion = '';//内容
                let bUserCode = '';//接收人code
                
                let DBSZ = [];//待办数据
                let title = '';//主题
                let procedureName = '';//流程名称
                let flowNumber = '';//流水号
                let lastActCode = '';//下个人的lasActCode
                let titleS ='';//主题2
                let taskId = '';//OA主键(actCode+fromDate);
                let userName = '';//发送人姓名
                let senduserid = '';//发送者userid
                let casecode = '';
                let createdatetime = '';//此流程接收时间
                var nowDate = new Date();
                //当前日期
                let date = nowDate.getFullYear()+'-'+((nowDate.getMonth()+1)<10?'0'+(nowDate.getMonth()+1):(nowDate.getMonth()+1))+'-'+(nowDate.getDate()<10?'0'+nowDate.getDate():nowDate.getDate())+' '+(nowDate.getHours()<10?'0'+nowDate.getHours():nowDate.getHours())+':'+(nowDate.getMinutes()<10?'0'+nowDate.getMinutes():nowDate.getMinutes())+':'+(nowDate.getSeconds()<10?'0'+nowDate.getSeconds():nowDate.getSeconds());
                //校验(PC/移动)
                if(r1.length!=1){
                    let r2 = r1[1].split('&');
                    procedureCode = r2[0].substring(14);
                    caseCode = r2[1].substring(9);
                    applicationCode = r2[2].substring(16);
                    userCode = r2[3].substring(9);
                    actCode = r2[4].substring(8);
                    projectCode = r2[5].substring(12);
                    work = r2[6].substring(5);
                    isAudit = r2[7].substring(8);
                    canManual = r2[8].substring(10);
                    opinion =decodeURIComponent(r2[9].substring(8));
                    bUserCode = r2[10].substring(10);
                    let GX ={//OA更新接口数据参数
                        syscode:restPwd.taskActorName,//注册编码
                        flowid:'',
                        requestname:'',
                        workflowname:'地产业务事项', 
                        receiver:'',  
                    }
                    let Wopinions = {//取发送者userID
                        actUserName:userCode,
                        
                    }
                    this.$store.dispatch('GetUserVM',Wopinions).then(rid=>{
                        senduserid = rid.userID; 
                        GX.receiver = senduserid;})
                        
                    let taskActor2 = bUserCode.split(',');//接收人code
                    this.$axios({
                        url: this.opinionDate+"/GetWorkFlowPage?userCode="+userCode+"&actCode="+actCode,
                        method:'get',
                        //发送格式为json
                        headers:{
                        'Content-Type': 'application/json'
                        }
                    }).then(rxx=>{
                        title = rxx.data.data.title;
                        procedureName = rxx.data.data.procedureName;
                        flowNumber = rxx.data.data.flowNumber;
                        GX.requestname = title;
                        let key = CryptoJS.enc.Utf8.parse('absoietlj32fai12');
                        // 取当前人的往OA传过去的待办id
                        this.$axios({
                            url: this.opinionDate+"/GetWorkFlowActListDone?userCode="+userCode+"&procedureName="+encodeURIComponent(procedureName),
                            method:'get',
                            //发送格式为json
                            headers:{
                            'Content-Type': 'application/json'
                            }
                        }).then(r2=>{
                            let tid = '';
                            for(let o of r2.data.data){
                                if(o.flowNumber == flowNumber){
                                    let kmid = o.actCode+o.fromDate;
                                    createdatetime = o.fromDate;
                                    tid = kmid.replace('-','').replace(' ','').replace(':','');
                                }
                            }
                            GX.flowid = tid.replace('-','');
                            let tasklenght = taskActor2.length;
                            if(taskActor2[taskActor2.length-1]==''){
                                tasklenght = tasklenght-1
                            }
                            for(let opop of taskActor2){
                                if(opop!=''){
                                    // 取下个人的往OA传过去的待办id
                                    this.$axios({
                                        url: this.opinionDate+"/GetWorkFlowActListNotSigned?userCode="+opop+"&procedureName="+encodeURIComponent(procedureName),
                                        method:'get',
                                        //发送格式为json
                                        headers:{
                                        'Content-Type': 'application/json'
                                        }
                                    }).then(r11=>{
                                        for(let o of r11.data.data){
                                            if(o.flowNumber == flowNumber){
                                                let ksid = o.actCode+o.fromDate;
                                                
                                                lastActCode = o.actCode
                                                titleS = o.title;
                                                taskId = ksid.replace('-','').replace(' ','').replace(':','');
                                            }
                                        }
                                        let encrypted1 = CryptoJS.AES.encrypt(opop, key, {mode: CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});//加密userCode
                                        let encrypted2 = CryptoJS.AES.encrypt(lastActCode, key, {mode: CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});//加密actCode
                                        let opinions = {
                                            taskActorName:'',
                                            actUserName:opop,
                                            opinionDate:'第三方注册系统编码',
                                            opinionConfirm:'调取地产云地址',
                                            opinionText:'调取OA地址',
                                        }
                                        this.$store.dispatch('GetUserVM',opinions).then(redate=>{
                                            userName = redate.userName;
                                            let encrypted3 = CryptoJS.AES.encrypt(this.userName, key, {mode: CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});//加密userName
                                            let encrypted4 = CryptoJS.AES.encrypt(caseCode, key, {mode: CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});//加密caseCode
                                            let encrypted5 = CryptoJS.AES.encrypt(applicationCode, key, {mode: CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});//加密caseCode
                                            let DB ={//OA待办接口数据参数

                                                syscode: redate.opinionDate,
                                                flowid: taskId.replace('-',''),
                                                requestname: titleS,
                                                workflowname: '地产业务事项',
                                                nodename: procedureName,
                                                pcurl: `${redate.pwd}reception?&amp;type=1&amp;userCode=${encrypted1.toString()}&amp;frameType=info&amp;caseCode=${encrypted4.toString()}&amp;actCode=${encrypted2.toString()}&amp;applicantion=${encrypted5.toString()}&amp;PName=${encodeURIComponent(procedureName)}`,
                                                appurl: `${redate.pwd}reception?&amp;type=0&amp;userCode=${encrypted1.toString()}&amp;actCode=${encrypted2.toString()}&amp;un=${encrypted3.toString()}&amp;PName=${encodeURIComponent(procedureName)}`,
                                                creator: senduserid,
                                                createdatetime: createdatetime,
                                                receiver: redate.userID,
                                                receivedatetime: date,
                                            }
                                            DBSZ.push(DB);
                                            
                                            
                                            if(DBSZ.length==tasklenght){
                                                //校验是否调用OA待办接口
                                                if(DBSZ.length!=0){
                                                    for(let daiban of DBSZ){
                                                        let b = JSON.stringify(daiban)
                                                        this.$axios({
                                                            url: `${redate.url}`,
                                                            method:'post',
                                                            data:'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="webservices.ofs.weaver.com.cn"><soapenv:Header/><soapenv:Body><web:receiveTodoRequestByJson><web:in0>'+b.toString()+'</web:in0></web:receiveTodoRequestByJson></soapenv:Body></soapenv:Envelope>',
                                                            headers:{
                                                                'Content-Type': 'text/xml; charset=utf-8'
                                                            }
                                                        }).then(r=>{
                                                            //校验是否调用OA更新接口
                                                            if(JSON.stringify(GX)!='{}'){
                                                                let g = JSON.stringify(GX);
                                                                this.$axios({
                                                                    url:`${redate.url}`,
                                                                    method:'post',
                                                                    data:'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="webservices.ofs.weaver.com.cn"><soapenv:Header/><soapenv:Body><web:processOverRequestByJson><web:in0>'+g.toString()+'</web:in0></web:processOverRequestByJson></soapenv:Body></soapenv:Envelope>',
                                                                    headers:{
                                                                        'Content-Type': 'text/xml; charset=utf-8'
                                                                    }
                                                                }).then(r=>{
                                                                    window.location.href="about:blank";
                                                                    window.close();  
                                                                })
                                                            }
                                                        })
                                                    }
                                                }
                                                
                                                
                                             
                                            }
                                            
                                        })
                                    })
                                }
                            }
                        })
                    })
                
                
                }

        
        else
        {
            let daiBans = this.$store.getters.daiBans;//待办
            let gengXins = this.$store.getters.gengXins;//更新
            
            this.$store.dispatch('GetDongLong',encodeURIComponent('调取OA地址')).then(res=>{
                this.oaurl = res;
                //校验是否调用OA待办接口
                if(daiBans.length!=0)
                {
                    for(let daiban of daiBans)
                    {
                        let b = JSON.stringify(daiban);
                        let a = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="webservices.ofs.weaver.com.cn"><soapenv:Header/><soapenv:Body><web:receiveTodoRequestByJson><web:in0>'+b.toString()+'</web:in0></web:receiveTodoRequestByJson></soapenv:Body></soapenv:Envelope>';
                        
                        this.$axios({
                            url: `${res}`,
                            method:'post',
                            data:a,
                            headers:{'Content-Type': 'text/xml; charset=utf-8'}
                                }).then(r=>{                                  
                                            
                                            })
                    }
                            }
                            //校验是否调用OA更新接口
                            if(JSON.stringify(gengXins)!='{}')
                            {
                                let g = JSON.stringify(gengXins);
                                this.$axios({
                                    url:`${res}`,
                                    method:'post',
                                    data:'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="webservices.ofs.weaver.com.cn"><soapenv:Header/><soapenv:Body><web:processOverRequestByJson><web:in0>'+g.toString()+'</web:in0></web:processOverRequestByJson></soapenv:Body></soapenv:Envelope>',
                                    headers:{
                                        'Content-Type':'application/xml'
                                    }
                                }).then(r=>{
                                
                                })
                            }
                            
                            this.$router.push('/main');
                        })
                    }
            })
        
        },
    
}
</script>