import { ApiModel } from "../../utils/api"; const _Http = new ApiModel(); const handleList = require("../../utils/processingData"); Page({ /** * 页面的初始数据 */ data: { inputValue: '', //群名 buddyList: [], //好友列表 activeNames: [], //折叠面板展开项 identity: '全部', //选择身份 result: [], checkAll: false, //是否全选 numberOfPeople: 0, //全部人员计数 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { _Http.basic({ "accesstoken": wx.getStorageSync('userData').token, "classname": "customer.tagents.tagents", "method": "query_cooperation", "content": { "getdatafromdbanyway": true, "pageNumber": 1, "pageSize": 999, "where": { "condition": "", "ftype": "", "fstatus": "" } } }).then(res => { let activeNames = []; for (let index = 0; index < res.data.length; index++) { this.query_CooperationAgentUsers(res.data[index]) activeNames.push(index) } this.setData({ activeNames }) }) }, /* 创建群聊 */ createdGroup() { if (this.data.result.length == 0) { wx.showToast({ title: '当前还未选择群聊成员', icon: "none" }) } else { _Http.basic({ "accesstoken": wx.getStorageSync('userData').token, "classname": "system.im.imdialog.imdialog", "method": "insertOrModify", "content": { "timdialogid": 0, "fimdialogname": (this.data.inputValue == '') ? '讨论组' : this.data.inputValue, "fimdialogtype": "话题", "ownertable": "", "ownerid": "", "users": this.data.result } }).then(res => { console.log("创建群聊", res) if (res.msg != '成功') return wx.showToast({ title: res.data, icon: "none" }) wx.showToast({ title: '创建成功', }) setTimeout(() => { wx.redirectTo({ url: '/pages/chatRoom/dialogbox?id=' + res.data[0].timdialogid, }) }, 500) }) } }, /* 是否全选 */ allChange({ detail }) { this.setData({ checkAll: detail }) if (detail) { let result = []; for (let i = 0; i < this.data.buddyList.length; i++) { if (this.data.identity == '全部') { this.batchChange(i, true) } else { result.push(this.data.buddyList[i].userList[0].tenterprise_userid.toString()) } } if (this.data.identity != '全部') this.setData({ result }) } else { this.setData({ result: [] }) } }, /* 商户成员列表 */ query_CooperationAgentUsers(data) { _Http.basic({ "accesstoken": wx.getStorageSync('userData').token, "classname": "customer.tagents.tagents", "method": "query_CooperationAgentUsers", "content": { "getdatafromdbanyway": true, "tagentsid": data.tcooperationagentsid, "hasAdministrator": "1" } }, false).then(res => { console.log("成员列表", res) if (res.msg != '成功') return wx.showToast({ title: res.data, icon: "none" }) data.userList = handleList.imageType(res.data, 'headportrait'); let numberOfPeople = this.data.numberOfPeople += data.userList.length; //计数 let buddyList = this.data.buddyList; buddyList.push(data) this.setData({ buddyList, numberOfPeople }) }) }, /* 职位选择类型 */ selectType({ detail }) { /* if (detail == '仅老板') { let list = this.data.buddyList, result = [] for (let index = 0; index < list.length; index++) { result.push(list[index].userList[0].tenterprise_userid.toString()) } this.setData({ result }) } */ if (this.data.identity != detail) this.setData({ identity: detail }); this.isAll() }, /* 编辑群名称 */ nameInput(e) { const { value } = e.detail; this.setData({ inputValue: value }) }, /* 折叠面板 */ collapseChange(event) { this.setData({ activeNames: event.detail, }); }, //多选选中 userListCheckboxChange(e) { this.setData({ result: e.detail }) this.isAll(); }, /* 商户选中 */ titleRadio(e) { const { index, id } = e.target.dataset; this.isAll() if (!this.data.result.some((value) => value == id)) return this.batchChange(index, false); if (this.data.identity == '全部') this.batchChange(index, true); }, //批量修改 batchChange(index, bool) { let data = this.data.buddyList[index].userList, result = this.data.result; for (let index = 0; index < data.length; index++) { if (bool) { if (!result.some((v) => v == data[index])) { result.push(data[index].tenterprise_userid.toString()) result = result.reduce((pre, cur) => { if (!pre.includes(cur)) { return pre.concat(cur) } else { return pre } }, []) } } else { result = result.filter((value) => value != data[index].tenterprise_userid); } } this.setData({ result }) this.isAll(); }, /* 选择子账号同时选中主账号 */ listClick(e) { const index = e.currentTarget.dataset.index, itemId = e.currentTarget.dataset.id, id = e.currentTarget.id; if (index == 0) return; let result = this.data.result; if (!result.some((v) => v == itemId)) return; if (!result.some((value) => value == id)) { result.push(id) this.setData({ result }) } }, isAll() { let checkAll = this.data.checkAll; if (this.data.identity == '全部') { checkAll = (this.data.numberOfPeople == this.data.result.length) ? true : false; } else { checkAll = (this.data.result.length == this.data.buddyList.length) ? true : false; } console.log("isall", checkAll) this.setData({ checkAll }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {} })