const _Http = getApp().globalData.http;

Component({
    options: {
        addGlobalClass: true
    },
    properties: {
        list: {
            type: Array
        },
        ownertable: {
            type: String
        },
        ownerid: {
            type: String
        },
        changeTotal: {
            type: Function
        },
        disabled: {
            type: Boolean
        }
    },
    lifetimes: {
        attached: function () {
          this.setData({
            userid: wx.getStorageSync('userMsg').userid,
          })
          getApp().globalData.Language.getLanguagePackage(this)
        }
      },
    methods: {
        toDetail(e) {
            const {
                item
            } = e.currentTarget.dataset;
            wx.navigateTo({
                url: `/prsx/trace/detail/index?data=` + JSON.stringify({
                    "sys_datafollowupid": item.sys_datafollowupid,
                    "ownertable": this.data.ownertable,
                    "ownerid": this.data.ownerid
                }),
            })
        },
        editItem(e) {
            const {
                item
            } = e.currentTarget.dataset;
            wx.navigateTo({
                url: `/prsx/trace/add/index?ownertable=${this.data.ownertable}&ownerid=${this.data.ownerid}&sys_datafollowupid=${item.sys_datafollowupid}`
            });
        },
        deleteItem(e) {
            const {
                item
            } = e.currentTarget.dataset;
            _Http.traceHandleDelete(item)
        },
        comment(e) {
            let page = this.selectComponent('#' + e.currentTarget.id);
            page.changeShow()
        },
        updateCommentList({
            detail
        }) {
            console.log("detail", detail)
            detail.pageSize = 99999;
            _Http.basic({
                "id": 20240920092204,
                content: detail
            }).then(res => {
                console.log("更新评论列表", res)
                if (res.code == 1) {
                    let idName = detail.ownertable + 'id';
                    const index = this.data.list.findIndex(v => v[idName] == detail.ownerid)
                    if (index != -1) {
                        let item = this.data.list[index];
                        item.commentqty = res.total == 0 ? 0 : res.data[0].totalqty;
                        item.comment = res.data;
                        this.setData({
                            [`list[${index}]`]: item
                        })
                    }
                }
            })
        }
    }
})