import { $wuxActionSheet } from "../../../../dist/index" import { getAssociationDetail, modifyAvatar, disbandAssociation, withdrawGroup, getAssociationMember } from "../../utils/api" const config = require("../../../../utils/config") const app = getApp() Page({ data: { groupAvatar: "../../images/ic_tianjiatouxiang@2x.png", userInfo: { id: "", groupName: "", groupAvatar: "", groupCategory: "1", nickname: "", totalNum: "", topicNum: "", changeToIssueNum: "", lordFlag: "" }, groupId: "", noticeVerifyVisible: false, dialogVisible: false, checkPenddingNum: 0 }, onShow () { this.getCheckMemberNum() }, onLoad (options) { this.setData({ groupId: options.groupId }) this.getAssociationDetail() }, onHide () { }, // 跳转到 群介绍 navigateToIntroduce () { wx.navigateTo({ url: `/subpages/association/pages/joinassociation/joinassociation?type=change&id=${this.data.userInfo.id}` }) }, // 跳转到 群成员 navigateToMember () { wx.navigateTo({ url: `/subpages/association/pages/associationMember/associationMember?id=${this.data.userInfo.id}&groupCategory=${this.data.userInfo.groupCategory}` }) }, // 跳转到 邀请好友 navigateToInvitation () { wx.navigateTo({ url: `/subpages/association/pages/inviteFriend/inviteFriend?id=${this.data.userInfo.id}` }) }, // 跳转到 入群审核 navigateToVerify () { wx.navigateTo({ url: `/subpages/association/pages/incomingVerify/incomingVerify?id=${this.data.userInfo.id}` }) }, // 选择图片 chooseImage () { if (app.globalData.groupInfo.lordFlag === "0") { return false } const that = this $wuxActionSheet().showSheet({ buttons: [{ text: "拍照" }, { text: "从相册中获取" }, ], className: "dialog-class", buttonClicked (index) { if (index === 0) { wx.chooseImage({ count: 1, sizeType: ["original", "compressed"], sourceType: ["camera"], success (res) { wx.uploadFile({ url: config.BASEURL() + "group/topic/upload", filePath: res.tempFilePaths[0], name: "file", header: { "Content-Type": "multipart/form-data" }, success (fileres) { const data = JSON.parse(fileres.data) if (data.code === 0 && data.msg === "success") { that.modifyAvatar(data.data) } else { wx.showToast({ title: "上传图片失败,请重试", icon: "none", duration: 2000 }) } }, fail (err) { console.log(err) wx.showToast({ title: "上传图片失败,请重试", icon: "none", duration: 2000 }) } }) } }) } else if (index === 1) { wx.chooseImage({ count: 1, sizeType: ["original", "compressed"], sourceType: ["album"], success (res) { wx.uploadFile({ url: config.BASEURL() + "group/topic/upload", filePath: res.tempFilePaths[0], name: "file", header: { "Content-Type": "multipart/form-data" }, success (fileres) { const data = JSON.parse(fileres.data) if (data.code === 0 && data.msg === "success") { that.modifyAvatar(data.data) } else { wx.showToast({ title: "上传图片失败,请重试", icon: "none", duration: 2000 }) } }, fail (err) { console.log(err) wx.showToast({ title: "上传图片失败,请重试", icon: "none", duration: 2000 }) } }) } }) } return true }, cancelText: "取消", cancel () {}, destructiveButtonClicked () {}, }) }, // 获取群详情 getAssociationDetail () { getAssociationDetail(this.data.groupId).then(res => { console.log("群详情", res) const userInfo = {} for (const key in res.data) { userInfo[key] = res.data[key] } app.globalData.groupInfo = { groupAvatar: res.data.groupAvatar, groupLeader: res.data.nickname, groupName: res.data.groupName, groupId: res.data.id, lordFlag: res.data.lordFlag } this.setData({ userInfo }) }).catch(err => { console.log(err) }) }, // 修改群头像 modifyAvatar (groupAvatar) { const para = { id: this.data.userInfo.id, groupAvatar } wx.showLoading({ title: "加载中", }) modifyAvatar(para).then(res => { wx.hideLoading() console.log("修改群头像", res) wx.showToast({ title: "修改群头像成功", icon: "none", duration: 2000 }) const userInfo = Object.assign(this.data.userInfo, { groupAvatar }) this.setData({ userInfo }) }).catch(err => { console.log(err) }) }, // 解散群 disbandAssociation () { this.setData({ noticeVerifyVisible: !this.data.noticeVerifyVisible }) }, // 解散群弹框确定 confirm (e) { const para = { id: this.data.userInfo.id, processingOpinions: e.detail.value } wx.showLoading({ title: "加载中", }) disbandAssociation(para).then(res => { wx.hideLoading() console.log("解散群",res) wx.showToast({ title: "解散群成功", icon: "none", duration: 2000 }) wx.navigateBack({ delta: 2 }) }).catch(err => { console.log(err) }) }, // 解散群弹框取消 cancel () { console.log("取消") }, // 退群 withdrawGroup () { this.setData({ dialogVisible: !this.data.dialogVisible }) }, // 退群确认弹框 confirmDialog () { wx.showLoading({ title: "加载中", }) withdrawGroup(this.data.userInfo.id).then(res => { console.log("退群", res) wx.hideLoading() wx.showToast({ title: "退群成功", icon: "none", duration: 2000 }) wx.navigateTo({ url: "/pages/association/association" }) }).catch(err => { console.log(err) }) }, // 获取 待审核人数 getCheckMemberNum () { const para = { groupId: this.data.groupId, state: 0 } getAssociationMember(para).then(res => { console.log("待审核群成员人数", res) this.setData({ checkPenddingNum: res.data.length }) }).catch(err => { this.setData({ checkPenddingNum: 0 }) console.log(err) }) } })