

export default{
    data() {
        return {
            projectQuery:{
                queryParams:{
                    current:1,
                    size:10
                },
                loading:false,
                data:[]
            }
        }
    },
    methods: {
        //检索
        inputSearch(){
            this.searchBth()
            this.refreshCount()
        },
        //过滤
        filterSearch(){
            this.$refs.filterDialog.open()
        },
        initProjectSelect(){
            if(this.condition.otherCondition.projectId){
                this.getProjectQuery(this.condition.otherCondition.projectId)
            }
        },
        //切换检索范围
        changeDBType(){
            this.inputSearch()
        },
        //切换检索数据库
        changeProject(value){
            if(!value){
                this.condition.otherCondition.projectName = null
                this.inputSearch()
                return
            }
            var obj = this.projectQuery.data.find(item=>{
                return item.id == value
            })
            if(obj){
                this.condition.otherCondition.projectName = obj.name
            }
            this.inputSearch()
        },
        getProjectQuery(id){
            var obj = this.projectQuery
            obj.data=[]
            obj.queryParams.current = 1
            obj.id = id
            obj.name = ''
            this.getProject()
        },
        //懒加载事件
        lazyLoading(){
            var obj = this.projectQuery
            if(obj.queryParams.current * obj.queryParams.size>=obj.queryParams.total){
                return false
            }
            obj.queryParams.current += 1
            this.getProject()
        },
        //远程搜索
        remoteMethod(query){
            var obj = this.projectQuery
            obj.data=[]
            obj.queryParams.current = 1
            obj.name = query.trim()
            this.getProject()
        },
        //获取专题库数据
        async getProject(){
            var obj = this.projectQuery
            obj.loading = true;
            var str = ''
            if(obj.name){
                str+=`name=${obj.name}`
            }
            if(obj.id){
                str+=`id=${obj.id}`
            }
            let params = {
                ...obj.queryParams,//分页信息
                searchQuery:str,//检索条件
                orderDTOList: [
                {
                    orderBy: "createTime",
                    orderType: 1
                },
                ]//排序
            }
            await this.$api.queryPatentProject(params).then(response => {
                if(response.code == 200){
                    obj.loading = false;
                    obj.data.push(...response.data.data)
                    obj.id = null
                    obj.queryParams.total = response.data.total
                }
            })
        },

        //图表分析
        async handleAnalyses() {
            var params = {
                condition: this.condition.searchCondition || '',//检索条件
                numberQuery:this.condition.NO,
                customFields:  [],
                groupField:null,
                orderDTOList: [
                    {
                        orderBy:this.queryParams.OrderBy,
                        orderType:this.queryParams.OrderByType == 'DESC'?1:0
                    }
                ],//排序信息
                projectId:null
            }
            const router = this.$router.resolve({
                path: '/customChart',
                query: {
                    projectId: null,
                    search:JSON.stringify(params),
                    patentNum:this.total
                }
            })
            window.open(router.href, '_blank');
        },
        //导出专利
        async handleExport(val) {
            if (val) {
                if ( this.endNumber < 1 && this.queryParams.isAdd.length == 0) {
                    this.$message.error('请先选择专利')
                    return false
                }
            }
            let obj = {
                isAdd: this.queryParams.isAdd,
                isDelete: this.queryParams.isDelete,
                startNumber: this.startNumber,
                endNumber: this.endNumber,
                searchQuery: this.condition.searchCondition || '',//检索条件
                customFields:  [],
                groupField:null,
                orderDTOList:[
                    {
                        orderBy:this.queryParams.OrderBy,
                        orderType:this.queryParams.OrderByType == 'DESC'?1:0
                    }
                ],
            }
            if (!val) {
                // 如果是导出全部，endNumber是当前的全部专利
                obj.endNumber=this.total
            }
            let router = this.$router.resolve({
            path: '/exportPatent',
            query: {
                projectId: null,
                condition: JSON.stringify(obj)
            }
            })
            window.open(router.href, '_blank')
        },
        //PDF首页导出
        exportPDF(sign) {
            if (sign) {
                if ( this.endNumber < 1 && this.queryParams.isAdd.length == 0) {
                    this.$message.error('请先选择专利')
                    return false
                }
            }
            if(sign){
            var params = {
                projectId: null,
                isAdd: this.queryParams.isAdd,
                isDelete: this.queryParams.isDelete,
                startNumber: this.startNumber,
                endNumber: this.endNumber,
                searchQuery: this.condition.searchCondition || '',//检索条件
                customFields:  [],
                groupField:null,
                orderDTOList:[
                    {
                        orderBy:this.queryParams.OrderBy,
                        orderType:this.queryParams.OrderByType == 'DESC'?1:0
                    }
                ],
            }
            }else{
            var params = {
                projectId: null,
                searchQuery: this.condition.searchCondition || '',//检索条件
                customFields:  [],
                groupField:null,
                orderDTOList:[
                    {
                        orderBy:this.queryParams.OrderBy,
                        orderType:this.queryParams.OrderByType == 'DESC'?1:0
                    }
                ],
                isAdd: [],
                isDelete: [],
                startNumber: 1,
                endNumber: this.total,//默认是当前全部
            }
            }
            
            this.$api.exportPDFFirstPage(params).then(res => {
            if (res.code == 200) {
                const h = this.$createElement;
                this.$msgbox({
                title: '提示',
                message: h('p', null, [
                    h('span', null, '任务正在导入，查看任务进度请前往 '),
                    h('span', {
                    style: 'color: #ff7d38;cursor: pointer;',
                    // on: {
                    //     click: () => {//
                    //     let router = this.$router.resolve({
                    //         path: '/taskList',
                    //         query: {
                    //         importToId: null,
                    //         }
                    //     })
                    //     window.open(router.href, '_blank')
                    //     this.$msgbox.close(false)
                    //     }
                    // }
                    }, '立即前往',)
                ]),
                type: 'warning',
                showConfirmButton: false,
                }).then(action => {
                });
            }
            })
        },
    },
}