

export default{
    data() {
        return {
            projectQuery:{
                queryParams:{
                    current:1,
                    size:10
                },
                loading:false,
                data:[]
            },
            projectId:null,
            projectName:null,
        }
    },
    methods:{
        initProject(data){
            if(data){
                this.$set(this,'projectId',data.projectId)
                // this.projectId = data.projectId
                this.projectName = data.projectName
                this.getProjectQuery(this.projectId)
                return {
                    "field": "projectName",
                    "logical": "AND",
                    "operator": "=",
                    "dataType": 1,
                    "placeholder": "请选择",
                    "show": {
                        "label": "专利数据库"
                    }
                }
            }
            return null
        },
        changeProject(value){
            if(!value){
                this.projectName = null
                return
            }
            var obj = this.projectQuery.data.find(item=>{
                return item.id == this.projectId
            })
            if(obj){
                this.projectName = obj.name
            }
        },
        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
                }
            })
        },
    }
}