const _Http = getApp().globalData.http;
Component({
    options: {
        addGlobalClass: true
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    data: {
        list: [],
        "content": {
            "nocache": true,
            "pageNumber": 1,
            "pageTotal": 1,
            "total": null,
            "where": {
                begdate: "",
                enddate: "",
            }
        }
    },
    methods: {
        getList(id, init) {
            let content = this.data.content;
            content.sa_projectid = id;
            content.type = this.data.isAll;
            if (init) {
                content.pageNumber = 1;
                content.total = null;
            }
            if (!this.data.showList && content.total != null) return;
            if (content.pageNumber > content.pageTotal) return;
            _Http.basic({
                "id": 20230715112004,
                content
            }).then(res => {
                console.log("项目竞争对手", res)
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                })
                content.pageNumber = res.pageNumber + 1;
                content.pageSize = res.pageSize;
                content.pageTotal = res.pageTotal;
                content.total = res.total;
                this.setData({
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    content,
                    id: id,
                });
            })
        },
        upDateList() {
            let content = JSON.parse(JSON.stringify(this.data.content));
            try {
                content.sa_projectid = this.data.id;
                content.type = this.data.isAll;
                content.pageSize = (content.pageNumber - 1) * content.pageSize;
                content.pageNumber = 1;
            } catch (error) {
                console.log("error", error)
            }
            _Http.basic({
                id: '20230715112004',
                content
            }).then(res => {
                console.log("更新项目竞争对手列表", res);
                if (res.code == '1') {
                    page.setData({
                        list: res.data,
                        "content.total": res.total
                    })
                }
            })
        }
    }
})