| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 | // packageA/contacts/index.jslet dowmCount = null,    _Http = getApp().globalData.http,    dMark = require('../../utils/deleteMark')Page({    /**     * 页面的初始数据     */    data: {        systemGroup: [], //系统分组        myGroup: [], //自定义分组        groupName: '',        sys_phonebookgroupid: 0,        dialogShow: false    },    onLoad(options) {        this.getGroup();    },    toAddContacts() {        wx.navigateTo({            url: './edit',        })    },    /* 获取分组 */    getGroup(condition = '') {        return _Http.basic({            "id": "20220831164603",            "version": 1,            "content": {                "nocache": true,                "where": {                    condition                }            }        }).then(res => {            if (res.msg != '成功') return wx.showToast({                title: res.msg,                icon: "none"            })            console.log(res.data)            if (condition != '') return res.data;            let systemGroup = [],                myGroup = [];            res.data.forEach(v => ['默认群组', '客户联系人', '项目联系人'].includes(v.groupname) ? systemGroup.push(v) : myGroup.push(v));            this.setData({                systemGroup,                myGroup            })        })    },    toCheckList(e) {        const {            item        } = e.currentTarget.dataset;        wx.navigateTo({            url: './list?item=' + JSON.stringify(item),        })    },    /* 删除自定义分组 */    deleteGroup(e) {        const {            item        } = e.currentTarget.dataset,            that = this;        if (item.count) return wx.showToast({            title: '当前状态不可删除',            icon: "none"        });        wx.showModal({            title: "提示",            content: `是否确认删除 "${item.groupname}"`,            success({                confirm            }) {                if (confirm) _Http.basic({                    "id": "20220831164403",                    "version": 1,                    "content": {                        "sys_phonebookgroupid": item.sys_phonebookgroupid                    }                }).then(res => {                    if (res.msg != '成功') return wx.showToast({                        title: res.msg,                        icon: "none"                    })                    const myGroup = that.data.myGroup.filter(v => v.sys_phonebookgroupid != item.sys_phonebookgroupid);                    that.setData({                        myGroup                    })                    wx.showToast({                      title: '删除成功',                    })                })            }        })    },    /* 开始搜索 */    startSearch({        detail    }) {        this.getGroup(detail.trim()).then(res => {            let item = {                groupname: "搜索",                phonebook: [],                sys_phonebookgroupid: 0            };            res.forEach(v => {                if (v.phonebook.length != 0) {                    item.phonebook = item.phonebook.concat(v.phonebook)                }            });            if (item.phonebook.length == 0) {                wx.showToast({                    title: `未找到与'${detail.trim()}'有关内容`,                    icon: "none"                })            } else {                wx.navigateTo({                    url: './list?item=' + JSON.stringify(item),                })            }        })    },    onClose(event) {        const {            instance        } = event.detail;        instance.close();    },    openDialog(e) {        console.log(e)        if (e.currentTarget.dataset.item) {            this.setData({                dialogShow: true,                groupName: e.currentTarget.dataset.item.groupname,                sys_phonebookgroupid: e.currentTarget.dataset.item.sys_phonebookgroupid            })        } else {            this.setData({                dialogShow: true,                groupName: "",                sys_phonebookgroupid: 0            })        }    },    inputName({        detail    }) {        this.setData({            groupName: dMark.queryStr(detail.value)        })    },    handleAddGroup() {        let name = this.data.groupName.trim()        if (name.length == 0) return wx.showToast({            title: '群组名称不可为空',            icon: "none"        })        _Http.basic({            "id": "20220831164203",            "version": 1,            "content": {                "sys_phonebookgroupid": this.data.sys_phonebookgroupid,                "groupname": name            }        }).then(res => {            if (res.msg != '成功') {                wx.showToast({                    title: res.data,                    icon: "none"                })            };            this.getGroup();            wx.showToast({                title: this.data.sys_phonebookgroupid == 0 ? '添加成功' : '修改成功',            })            this.setData({                groupName: "",                sys_phonebookgroupid: 0            })        })    },    onCancel() {        this.setData({            dialogShow: false        })    },    onShareAppMessage() {    }})
 |