const _Http = getApp().globalData.http;
Component({
    options: {
        addGlobalClass: true
    },
    properties: {
        ownertable: String,
        ownerid: String,
    },

    data: {
        content: {
            nocache: true,
            pageNumber: 1,
            pageSize: 10,
            pageTotal: 1,
            total: null
        },
        list: []
    },
    methods: {
        getList(id, init = false) {
            let content = {
                ...this.data.content,
                "ownertable": this.data.ownertable,
                "ownerid": this.data.ownerid,
            };
            if (init) {
                content.pageNumber = 1
                content.pageTotal = 1
            }
            _Http.basic({
                "id": 20220930121501,
                content
            }).then(res => {
                console.log("跟进动态", res)
                if (res.msg != '成功') return wx.showToast({
                    title: res.data,
                    icon: "none"
                });
                let deleteList = res.data.filter(v => v.content == "" && v.type == ""),
                    list = res.data.filter(v => v.content != "" || !v.type == "");
                this.handleDeleteList(deleteList);
                this.setData({
                    "content.pageNumber": res.pageNumber + 1,
                    "content.pageTotal": res.pageTotal,
                    "content.total": res.total - deleteList.length,
                    list: res.pageNumber == 1 ? list : this.data.list.concat(list)
                })
            })
        },
        /* 批量删除空模板 */
        handleDeleteList(list) {
            list.forEach(v => {
                _Http.basic({
                    "id": 20220930121701,
                    "content": {
                        "sys_datafollowupid": v.sys_datafollowupid,
                        "deletereason": "系统删除空模板"
                    }
                }, false).then(res => {
                    console.log(res)
                })
            })
        },
        /* 去添加 */
        toAdd() {
            wx.navigateTo({
                url: `/packageA/setclient/modules/trace/add/index?ownertable=${this.data.ownertable}&ownerid=${this.data.ownerid}`,
            })
        },
        //跟进组件设置删除
        setDelete(id) {
            this.setData({
                list: this.data.list.filter(v => v.sys_datafollowupid != id)
            });
            wx.showToast({
                title: '作废成功!',
                icon: "none"
            })
            this.changeTotal()
        },
        changeTotal() {
            this.setData({
                "content.total": this.data.content.total - 1
            })
        }
    }
})