const _Http = getApp().globalData.http;

Page({
    data: {
        sys_enterpriseid: "",
        parems: {
            id: '20221102110003',
            content: {
                nocache: true,
                pageNumber: 1,
                pageSize: 20,
                pageTotal: 1,
                total: 0,
                where: {
                    "condition": "",
                }
            }
        },
        list: [],
        radio: "",
        acitonItem: {},
    },
    onLoad(options) {
        if (options.sys_enterpriseid) this.setData({
            sys_enterpriseid: options.sys_enterpriseid
        });
        this.getList();
    },
    /* 默认添加 */
    created() {
        wx.redirectTo({
            url: '/packageA/setclient/modules/contacts/add/index?sys_enterpriseid=' + this.data.sys_enterpriseid,
        })
    },
    /* 快速添加 */
    quickly() {
        console.log(this.data.acitonItem)
        wx.redirectTo({
            url: `/packageA/setclient/modules/contacts/add/index?sys_enterpriseid=${this.data.sys_enterpriseid}&data=${JSON.stringify(this.data.acitonItem)}`,
        })
    },
    onClick(e) {
        const {
            item
        } = e.currentTarget.dataset;
        delete(item.tag1)
        this.setData({
            radio: item.sys_phonebookid,
            acitonItem: item
        })
    },
    onSearch({
        detail
    }) {
        this.setData({
            'parems.content.where.condition': detail ? detail : ""
        });
        this.getList(true);
    },
    onClear() {
        this.setData({
            'parems.content.where.condition': ""
        });
        this.getList(true);
    },
    getList(init = false) {
        const parems = this.data.parems;
        if (init) parems.content.pageNumber = 1;
        if (parems.content.pageNumber > parems.content.pageTotal) return;
        _Http.basic(parems).then(res => {
            console.log("通讯录列表", res)
            if (res.msg != '成功') return wx.showToast({
                title: res.data,
                icon: "none"
            });
            parems.content.pageNumber = res.pageNumber + 1;
            parems.content.pageTotal = res.pageTotal;
            parems.content.total = res.total;
            this.setData({
                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                parems
            })
        })
    },
    onReachBottom() {
        this.getList();
    },
})