const _Http = getApp().globalData.http;
Component({
    properties: {},
    data: {
        list: [],
        sys_phonebookid: "",
        content: {
            "nacache": true,
            "pageNumber": 1,
            "pageSize": 10,
            "pageTotal": 1,
            "total": null,
            "where": {
                "condition": "",
            }
        },
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    methods: {
        getList(id, init) {
            let content = this.data.content;
            content.sys_phonebookid = id;
            if (init) {
                content.pageNumber = 1
                content.pageTotal = 1
            }
            _Http.basic({
                "id": "2025042213202602",
                content
            }).then(res => {
                console.log("线索列表", res)
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                })
                this.setData({
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    "content.pageNumber": res.pageNumber + 1,
                    "content.pageSize": res.pageSize,
                    "content.pageTotal": res.pageTotal,
                    "content.total": res.total,
                    sys_phonebookid: id
                })
                this.getTags()
            })
        },
        /* 获取列表标签 */
        getTags() {
            let list = this.data.list,
                ownerids = list.map(v => v.sat_orderclueid);
            _Http.basic({
                "id": 20221018102001,
                "content": {
                    nocache: true,
                    "ownertable": "sat_orderclue",
                    ownerids
                }
            }).then(res => {
                console.log("标签", res)
                for (let key in res.data) {
                    let index = list.findIndex(v => v.sat_orderclueid == key);
                    list[index].tags = res.data[key]
                };
                this.setData({
                    list
                })
            })
        },
        updateList() {
            if (this.data.content.total === null) return;
            let content = JSON.parse(JSON.stringify(this.data.content));
            content.sys_phonebookid = this.data.sys_phonebookid;
            content.pageSize = (content.pageNumber - 1) * content.pageSize;
            content.pageNumber = 1;
            _Http.basic({
                id: "2025042213202602",
                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
                })
                this.getTags();
            })
        }
    }
})