// packageA/contacts/index.js let dowmCount = null, _Http = getApp().globalData.http; Page({ /** * 页面的初始数据 */ data: { systemGroup: [], //系统分组 myGroup: [], //自定义分组 }, /** * 生命周期函数--监听页面加载 */ 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 }) }) } }) }, /* 开始搜索 */ 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(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })