const _Http = getApp().globalData.http;
Component({
    properties: {
        disabled: {
            type: Boolean
        },
        type: {
            type: String,
            value: "客户"
        }
    },
    options: {
        addGlobalClass: true
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    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 || this.data.sys_enterpriseid;
            if (init) {
                content.pageNumber = 1
                content.pageTotal = 1
            }
            _Http.basic({
                "id": "20221022165503",
                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_enterpriseid: content.sys_enterpriseid
                })
                // this.getTags();
                setTimeout(() => {
                    this.selectComponent("#List").initRadio();
                }, 300)

            })
        },
        toSearch() {
            if (this.data.showSearch && this.data.content.where.condition) {
                this.data.content.where.condition = '';
                this.getList("", true);
            } else if (this.data.condition) {
                this.data.content.where.condition = this.data.condition;
                this.setData({
                    condition: this.data.condition
                })
                this.getList("", true);
            }
            this.setData({
                showSearch: !this.data.showSearch
            })
            setTimeout(() => {
                this.setData({
                    focus: this.data.showSearch
                })
            }, 300)
        },
        onChange({
            detail
        }) {
            this.data.condition = detail;
        },
        onSearch({
            detail
        }) {
            this.data.content.where.condition = detail;
            this.getList("", true)
        },
    }
})