const _Http = getApp().globalData.http;
Component({
    properties: {
        disabled: Boolean
    },
    options: {
        addGlobalClass: true
    },
    data: {
        sys_enterpriseid: 0,
        list: [],
        content: {
            "nacache": true,
            "pageNumber": 1,
            "pageSize": 15,
            "pageTotal": 1,
            "total": null,
            "where": {
                "condition": "",
                "workaddress": 1
            }
        }
    },
    methods: {
        changeTotal() {
            this.setData({
                "content.total": this.data.content.total - 1
            })
        },
        /* 获取地址列表 */
        getList(id, init) {
            let content = this.data.content;
            content.sys_enterpriseid = id;
            if (init) {
                content.pageNumber = 1
                content.pageTotal = 1
            }
            _Http.basic({
                "id": "20221022165503",
                content
            }).then(res => {
                console.log("地址列表", res)
                if (res.msg != '成功') 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_enterpriseid: id
                })
                this.getTags();
                setTimeout(() => {
                    this.selectComponent("#List").initRadio();
                }, 300)

            })
        },
        /* 获取列表标签 */
        getTags() {
            let list = this.data.list,
                ownerids = list.map(v => v.contactsid);
            _Http.basic({
                "id": 20221018102001,
                "content": {
                    nocache: true,
                    "ownertable": "sys_enterprise_contacts",
                    ownerids
                }
            }).then(res => {
                console.log("地址标签", res)
                for (let key in res.data) {
                    let index = list.findIndex(v => v.contactsid == key);
                    list[index].tags = res.data[key]
                };
                this.setData({
                    list
                })
                console.log(list)
            })
        },
        toSearch() {
            wx.navigateTo({
                url: '/packageA/setclient/modules/address/search/index?perams=' + JSON.stringify({
                    sys_enterpriseid: this.data.sys_enterpriseid,
                    "nacache": true,
                    "pageNumber": 1,
                    "pageSize": 20,
                    "pageTotal": 1,
                    "total": 0,
                    "where": {
                        "condition": "",
                        "workaddress": 1
                    }
                }),
            })
        }
    }
})