const _Http = getApp().globalData.http;
Component({
    properties: {},
    data: {
        content: {
            nocache: true,
            pageNumber: 1,
            pageSize: 20,
            pageTotal: 1,
            total: null,
        },
        total: 0,
        list: []
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    methods: {
        getList(id, init = false) {
            if (id == 0) return;
            let content = this.data.content;
            content.sys_phonebookid = id;
            if (init) content.pageNumber = 1
            _Http.basic({
                id: "20231215134204",
                content
            }).then(res => {
                console.log("关联客户", res)
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                });
                this.setData({
                    "content.pageNumber": res.pageNumber + 1,
                    "content.pageTotal": res.pageTotal,
                    "content.total": res.total,
                    total: res.total,
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    id: id
                })
            })
        },
        updateList() {
            if (this.data.content.total === null) return;
            let content = JSON.parse(JSON.stringify(this.data.content));
            content.sys_phonebookid = this.data.id;
            content.pageSize = (content.pageNumber - 1) * content.pageSize;
            content.pageNumber = 1;
            _Http.basic({
                id: "20231215134204",
                content
            }).then(res => {
                console.log("更新关联客户", res)
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                });
                this.setData({
                    "content.total": res.total,
                    total: res.total,
                    list: res.data
                })
            })
        }
    }
})