123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- 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 () {}
- })
|