create.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. const handleList = require("../../utils/processingData");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. pageType: 0, //页面类型 0是添加成员 1是成员列表
  12. inputValue: '', //群名
  13. buddyList: [], //好友列表
  14. buddyListCopy: [], //备份
  15. activeNames: [], //折叠面板展开项
  16. identity: '全部', //选择身份
  17. result: [],
  18. checkAll: false, //是否全选
  19. numberOfPeople: 0, //全部人员计数
  20. searchText: '', //搜索内容
  21. timdialogid: 0, //群聊id
  22. users: [], //成员列表
  23. closure: false, //截流
  24. itemData: {}, //修改群聊原信息
  25. showRemove: false, //是否开启移除成员
  26. removeList: [], //清楚列表
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. _Http.basic({
  33. "accesstoken": wx.getStorageSync('userData').token,
  34. "classname": "customer.tagents.tagents",
  35. "method": "query_cooperation",
  36. "content": {
  37. "getdatafromdbanyway": true,
  38. "pageNumber": 1,
  39. "pageSize": 999,
  40. "where": {
  41. "condition": "",
  42. "ftype": "",
  43. "fstatus": ""
  44. }
  45. }
  46. }).then(res => {
  47. let activeNames = [];
  48. for (let index = 0; index < res.data.length; index++) {
  49. this.query_CooperationAgentUsers(res.data[index])
  50. activeNames.push(index)
  51. }
  52. this.setData({
  53. activeNames
  54. })
  55. //修改群聊信息
  56. if (options.timdialogid) {
  57. _Http.basic({
  58. "accesstoken": wx.getStorageSync('userData').token,
  59. "classname": "system.im.imdialog.imdialog",
  60. "method": "query_imdialogMain",
  61. "content": {
  62. "timdialogid": options.timdialogid
  63. }
  64. }).then(res => {
  65. console.log("群聊详情", res)
  66. if (res.msg != '成功') return wx.showToast({
  67. title: res.data,
  68. icon: "none"
  69. });
  70. let data = res.data[0],
  71. result = [];
  72. for (let i = 0; i < data.users.length; i++) {
  73. result.push(data.users[i].tenterprise_userid.toString())
  74. }
  75. this.setData({
  76. inputValue: data.fimdialogname,
  77. timdialogid: options.timdialogid,
  78. users: data.users,
  79. result,
  80. itemData: data,
  81. pageType: 1
  82. })
  83. })
  84. }
  85. })
  86. },
  87. /* 移除成员 */
  88. removeMember() {
  89. let list = this.data.removeList,
  90. that = this,
  91. _succeed = 0,
  92. _fail = 0;
  93. if (list.length == 0) return;
  94. wx.showModal({
  95. title: "提示",
  96. content: "是否移除选中成员",
  97. success: async function (res) {
  98. if (res.confirm) {
  99. wx.showLoading({
  100. title: '移除中...',
  101. mask: true
  102. })
  103. for (let i = 0; i < list.length; i++) {
  104. await _Http.basic({
  105. "accesstoken": wx.getStorageSync('userData').token,
  106. "classname": "system.im.imdialog.imdialog",
  107. "method": "updateDialoguser",
  108. "content": {
  109. "timdialogid": that.data.timdialogid,
  110. "tenterprise_userid": list[i],
  111. "fisremove": 1,
  112. "fimdialognotes": ""
  113. }
  114. }, false).then(res => {
  115. (res.msg == '成功') ? _succeed += 1: _fail += 1;
  116. })
  117. };
  118. wx.hideLoading()
  119. wx.showToast({
  120. title: '移除成功' + _succeed + '个,失败' + _fail + '个',
  121. icon: "none"
  122. });
  123. that.setData({
  124. closure: true
  125. })
  126. setTimeout(() => {
  127. wx.navigateBack({
  128. delta: 0,
  129. })
  130. }, 500)
  131. }
  132. }
  133. })
  134. },
  135. /* 移除成员列表更新 */
  136. removeListChange(event) {
  137. if (event.detail.length == this.data.users.length - 1) return wx.showToast({
  138. title: "不可将全部成员移除",
  139. icon: "none"
  140. });
  141. this.setData({
  142. removeList: event.detail,
  143. });
  144. },
  145. /* 修改群名 */
  146. changeName(e) {
  147. if (this.data.users.length == 0) return;
  148. const {
  149. value
  150. } = e.detail,
  151. that = this;
  152. if (value == this.data.itemData.fimdialogname) return;
  153. if (this.data.inputValue != '') {
  154. wx.showModal({
  155. title: "提示",
  156. content: "是否将群聊名称修改为:" + that.data.inputValue,
  157. success: function (res) {
  158. if (res.confirm) {
  159. that.createdGroup(true)
  160. } else {
  161. console.log(that.data.itemData.fimdialogname)
  162. that.setData({
  163. inputValue: that.data.itemData.fimdialogname
  164. })
  165. }
  166. }
  167. })
  168. }
  169. },
  170. /* 返回 */
  171. goBack() {
  172. if (this.data.users.length !== 0) {
  173. this.setData({
  174. showRemove: false,
  175. pageType: 1
  176. })
  177. }
  178. },
  179. /* 编辑群聊,新增或删除成员 */
  180. addAndRemove(e) {
  181. const {
  182. type
  183. } = e.target.dataset;
  184. console.log(type)
  185. if (type == 'add') {
  186. this.setData({
  187. pageType: 0
  188. })
  189. } else {
  190. this.setData({
  191. showRemove: !this.data.showRemove
  192. })
  193. }
  194. },
  195. //本地模糊搜索
  196. indistinct(e) {
  197. const value = e.detail.value.trim();
  198. if (value == this.data.searchText) return;
  199. if (value == '') {
  200. this.setData({
  201. buddyList: buddyListCopy
  202. })
  203. } else {
  204. let list = this.data.buddyListCopy,
  205. newList = [];
  206. for (let i = 0; i < list.length; i++) {
  207. if (list[i].fbrand.includes(value)) newList.push(list[i])
  208. };
  209. this.setData({
  210. buddyList: newList
  211. })
  212. }
  213. },
  214. /* 创建群聊 */
  215. createdGroup(isChangeUsers = false) {
  216. /* if (this.data.users.length == 0) {
  217. if (this.data.result.length == 0) return
  218. } */
  219. if (this.data.result.length == 0) {
  220. wx.showToast({
  221. title: '当前还未选择群聊成员',
  222. icon: "none"
  223. })
  224. } else {
  225. if (this.data.closure) return;
  226. _Http.basic({
  227. "accesstoken": wx.getStorageSync('userData').token,
  228. "classname": "system.im.imdialog.imdialog",
  229. "method": "insertOrModify",
  230. "content": {
  231. "timdialogid": this.data.timdialogid,
  232. "fimdialogname": (this.data.inputValue == '') ? '讨论组' : this.data.inputValue,
  233. "fimdialogtype": "话题",
  234. "ownertable": "",
  235. "ownerid": "",
  236. "users": (isChangeUsers == true) ? [] : this.data.result
  237. }
  238. }).then(res => {
  239. if (res.msg != '成功') return wx.showToast({
  240. title: res.data,
  241. icon: "none"
  242. })
  243. this.setData({
  244. closure: true
  245. })
  246. wx.showToast({
  247. title: '保存成功',
  248. })
  249. if (isChangeUsers == true) return;
  250. setTimeout(() => {
  251. if (this.data.users.length == 0) {
  252. wx.redirectTo({
  253. url: '/pages/chatRoom/dialogbox?id=' + res.data[0].timdialogid,
  254. })
  255. } else {
  256. wx.navigateBack({
  257. delta: 0,
  258. })
  259. }
  260. }, 500)
  261. })
  262. }
  263. },
  264. /* 是否全选 */
  265. allChange({
  266. detail
  267. }) {
  268. this.setData({
  269. checkAll: detail
  270. })
  271. if (detail) {
  272. let result = [];
  273. for (let i = 0; i < this.data.buddyList.length; i++) {
  274. if (this.data.identity == '全部') {
  275. this.batchChange(i, true)
  276. } else {
  277. result.push(this.data.buddyList[i].userList[0].tenterprise_userid.toString())
  278. }
  279. }
  280. if (this.data.identity != '全部') this.setData({
  281. result
  282. })
  283. } else {
  284. this.setData({
  285. result: []
  286. })
  287. }
  288. },
  289. /* 商户成员列表 */
  290. query_CooperationAgentUsers(data) {
  291. _Http.basic({
  292. "accesstoken": wx.getStorageSync('userData').token,
  293. "classname": "customer.tagents.tagents",
  294. "method": "query_CooperationAgentUsers",
  295. "content": {
  296. "getdatafromdbanyway": true,
  297. "tagentsid": data.tcooperationagentsid,
  298. "hasAdministrator": "1"
  299. }
  300. }, false).then(res => {
  301. console.log("成员列表", res)
  302. if (res.msg != '成功') return wx.showToast({
  303. title: res.data,
  304. icon: "none"
  305. })
  306. data.userList = handleList.imageType(res.data, 'headportrait');
  307. let numberOfPeople = this.data.numberOfPeople += data.userList.length; //计数
  308. let buddyList = this.data.buddyList;
  309. buddyList.push(data)
  310. this.setData({
  311. buddyList,
  312. buddyListCopy: buddyList,
  313. numberOfPeople
  314. })
  315. })
  316. },
  317. /* 职位选择类型 */
  318. selectType({
  319. detail
  320. }) {
  321. /* if (detail == '仅老板') {
  322. let list = this.data.buddyList,
  323. result = []
  324. for (let index = 0; index < list.length; index++) {
  325. result.push(list[index].userList[0].tenterprise_userid.toString())
  326. }
  327. this.setData({
  328. result
  329. })
  330. } */
  331. if (this.data.identity != detail) this.setData({
  332. identity: detail
  333. });
  334. this.isAll()
  335. },
  336. /* 编辑群名称 */
  337. nameInput(e) {
  338. const {
  339. value
  340. } = e.detail;
  341. this.setData({
  342. inputValue: value
  343. })
  344. },
  345. /* 折叠面板 */
  346. collapseChange(event) {
  347. this.setData({
  348. activeNames: event.detail,
  349. });
  350. },
  351. //多选选中
  352. userListCheckboxChange(e) {
  353. this.setData({
  354. result: e.detail
  355. })
  356. this.isAll();
  357. },
  358. /* 商户选中 */
  359. titleRadio(e) {
  360. const {
  361. index,
  362. id
  363. } = e.target.dataset;
  364. this.isAll()
  365. if (!this.data.result.some((value) => value == id)) return this.batchChange(index, false);
  366. if (this.data.identity == '全部') this.batchChange(index, true);
  367. },
  368. //批量修改
  369. batchChange(index, bool) {
  370. let data = this.data.buddyList[index].userList,
  371. result = this.data.result;
  372. for (let index = 0; index < data.length; index++) {
  373. if (bool) {
  374. if (!result.some((v) => v == data[index])) {
  375. result.push(data[index].tenterprise_userid.toString())
  376. result = result.reduce((pre, cur) => {
  377. if (!pre.includes(cur)) {
  378. return pre.concat(cur)
  379. } else {
  380. return pre
  381. }
  382. }, [])
  383. }
  384. } else {
  385. result = result.filter((value) => value != data[index].tenterprise_userid);
  386. }
  387. }
  388. this.setData({
  389. result
  390. })
  391. this.isAll();
  392. },
  393. /* 选择子账号同时选中主账号 */
  394. listClick(e) {
  395. const index = e.currentTarget.dataset.index,
  396. itemId = e.currentTarget.dataset.id,
  397. id = e.currentTarget.id;
  398. if (index == 0) return;
  399. let result = this.data.result;
  400. if (!result.some((v) => v == itemId)) return;
  401. if (!result.some((value) => value == id)) {
  402. result.push(id)
  403. this.setData({
  404. result
  405. })
  406. }
  407. },
  408. isAll() {
  409. let checkAll = this.data.checkAll;
  410. if (this.data.identity == '全部') {
  411. checkAll = (this.data.numberOfPeople == this.data.result.length) ? true : false;
  412. } else {
  413. checkAll = (this.data.result.length == this.data.buddyList.length) ? true : false;
  414. }
  415. console.log("isall", checkAll)
  416. this.setData({
  417. checkAll
  418. })
  419. },
  420. /**
  421. * 生命周期函数--监听页面初次渲染完成
  422. */
  423. onReady: function () {},
  424. /**
  425. * 生命周期函数--监听页面显示
  426. */
  427. onShow: function () {},
  428. /**
  429. * 生命周期函数--监听页面隐藏
  430. */
  431. onHide: function () {},
  432. /**
  433. * 生命周期函数--监听页面卸载
  434. */
  435. onUnload: function () {},
  436. /**
  437. * 页面相关事件处理函数--监听用户下拉动作
  438. */
  439. onPullDownRefresh: function () {},
  440. /**
  441. * 页面上拉触底事件的处理函数
  442. */
  443. onReachBottom: function () {},
  444. /**
  445. * 用户点击右上角分享
  446. */
  447. onShareAppMessage: function () {}
  448. })