create.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. inputValue: '', //群名
  12. buddyList: [], //好友列表
  13. activeNames: [], //折叠面板展开项
  14. identity: '全部', //选择身份
  15. result: [],
  16. checkAll: false, //是否全选
  17. numberOfPeople: 0, //全部人员计数
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. _Http.basic({
  24. "accesstoken": wx.getStorageSync('userData').token,
  25. "classname": "customer.tagents.tagents",
  26. "method": "query_cooperation",
  27. "content": {
  28. "getdatafromdbanyway": true,
  29. "pageNumber": 1,
  30. "pageSize": 999,
  31. "where": {
  32. "condition": "",
  33. "ftype": "",
  34. "fstatus": ""
  35. }
  36. }
  37. }).then(res => {
  38. let activeNames = [];
  39. for (let index = 0; index < res.data.length; index++) {
  40. this.query_CooperationAgentUsers(res.data[index])
  41. activeNames.push(index)
  42. }
  43. this.setData({
  44. activeNames
  45. })
  46. })
  47. },
  48. /* 创建群聊 */
  49. createdGroup() {
  50. if (this.data.result.length == 0) {
  51. wx.showToast({
  52. title: '当前还未选择群聊成员',
  53. icon: "none"
  54. })
  55. } else {
  56. _Http.basic({
  57. "accesstoken": wx.getStorageSync('userData').token,
  58. "classname": "system.im.imdialog.imdialog",
  59. "method": "insertOrModify",
  60. "content": {
  61. "timdialogid": 0,
  62. "fimdialogname": (this.data.inputValue == '') ? '讨论组' : this.data.inputValue,
  63. "fimdialogtype": "话题",
  64. "ownertable": "",
  65. "ownerid": "",
  66. "users": this.data.result
  67. }
  68. }).then(res => {
  69. console.log("创建群聊", res)
  70. if (res.msg != '成功') return wx.showToast({
  71. title: res.data,
  72. icon: "none"
  73. })
  74. wx.showToast({
  75. title: '创建成功',
  76. })
  77. setTimeout(() => {
  78. wx.redirectTo({
  79. url: '/pages/chatRoom/dialogbox?id=' + res.data[0].timdialogid,
  80. })
  81. }, 500)
  82. })
  83. }
  84. },
  85. /* 是否全选 */
  86. allChange({
  87. detail
  88. }) {
  89. this.setData({
  90. checkAll: detail
  91. })
  92. if (detail) {
  93. let result = [];
  94. for (let i = 0; i < this.data.buddyList.length; i++) {
  95. if (this.data.identity == '全部') {
  96. this.batchChange(i, true)
  97. } else {
  98. result.push(this.data.buddyList[i].userList[0].tenterprise_userid.toString())
  99. }
  100. }
  101. if (this.data.identity != '全部') this.setData({
  102. result
  103. })
  104. } else {
  105. this.setData({
  106. result: []
  107. })
  108. }
  109. },
  110. /* 商户成员列表 */
  111. query_CooperationAgentUsers(data) {
  112. _Http.basic({
  113. "accesstoken": wx.getStorageSync('userData').token,
  114. "classname": "customer.tagents.tagents",
  115. "method": "query_CooperationAgentUsers",
  116. "content": {
  117. "getdatafromdbanyway": true,
  118. "tagentsid": data.tcooperationagentsid,
  119. "hasAdministrator": "1"
  120. }
  121. }, false).then(res => {
  122. console.log("成员列表", res)
  123. if (res.msg != '成功') return wx.showToast({
  124. title: res.data,
  125. icon: "none"
  126. })
  127. data.userList = handleList.imageType(res.data, 'headportrait');
  128. let numberOfPeople = this.data.numberOfPeople += data.userList.length; //计数
  129. let buddyList = this.data.buddyList;
  130. buddyList.push(data)
  131. this.setData({
  132. buddyList,
  133. numberOfPeople
  134. })
  135. })
  136. },
  137. /* 职位选择类型 */
  138. selectType({
  139. detail
  140. }) {
  141. /* if (detail == '仅老板') {
  142. let list = this.data.buddyList,
  143. result = []
  144. for (let index = 0; index < list.length; index++) {
  145. result.push(list[index].userList[0].tenterprise_userid.toString())
  146. }
  147. this.setData({
  148. result
  149. })
  150. } */
  151. if (this.data.identity != detail) this.setData({
  152. identity: detail
  153. });
  154. this.isAll()
  155. },
  156. /* 编辑群名称 */
  157. nameInput(e) {
  158. const {
  159. value
  160. } = e.detail;
  161. this.setData({
  162. inputValue: value
  163. })
  164. },
  165. /* 折叠面板 */
  166. collapseChange(event) {
  167. this.setData({
  168. activeNames: event.detail,
  169. });
  170. },
  171. //多选选中
  172. userListCheckboxChange(e) {
  173. this.setData({
  174. result: e.detail
  175. })
  176. this.isAll();
  177. },
  178. /* 商户选中 */
  179. titleRadio(e) {
  180. const {
  181. index,
  182. id
  183. } = e.target.dataset;
  184. this.isAll()
  185. if (!this.data.result.some((value) => value == id)) return this.batchChange(index, false);
  186. if (this.data.identity == '全部') this.batchChange(index, true);
  187. },
  188. //批量修改
  189. batchChange(index, bool) {
  190. let data = this.data.buddyList[index].userList,
  191. result = this.data.result;
  192. for (let index = 0; index < data.length; index++) {
  193. if (bool) {
  194. if (!result.some((v) => v == data[index])) {
  195. result.push(data[index].tenterprise_userid.toString())
  196. result = result.reduce((pre, cur) => {
  197. if (!pre.includes(cur)) {
  198. return pre.concat(cur)
  199. } else {
  200. return pre
  201. }
  202. }, [])
  203. }
  204. } else {
  205. result = result.filter((value) => value != data[index].tenterprise_userid);
  206. }
  207. }
  208. this.setData({
  209. result
  210. })
  211. this.isAll();
  212. },
  213. /* 选择子账号同时选中主账号 */
  214. listClick(e) {
  215. const index = e.currentTarget.dataset.index,
  216. itemId = e.currentTarget.dataset.id,
  217. id = e.currentTarget.id;
  218. if (index == 0) return;
  219. let result = this.data.result;
  220. if (!result.some((v) => v == itemId)) return;
  221. if (!result.some((value) => value == id)) {
  222. result.push(id)
  223. this.setData({
  224. result
  225. })
  226. }
  227. },
  228. isAll() {
  229. let checkAll = this.data.checkAll;
  230. if (this.data.identity == '全部') {
  231. checkAll = (this.data.numberOfPeople == this.data.result.length) ? true : false;
  232. } else {
  233. checkAll = (this.data.result.length == this.data.buddyList.length) ? true : false;
  234. }
  235. console.log("isall", checkAll)
  236. this.setData({
  237. checkAll
  238. })
  239. },
  240. /**
  241. * 生命周期函数--监听页面初次渲染完成
  242. */
  243. onReady: function () {},
  244. /**
  245. * 生命周期函数--监听页面显示
  246. */
  247. onShow: function () {},
  248. /**
  249. * 生命周期函数--监听页面隐藏
  250. */
  251. onHide: function () {},
  252. /**
  253. * 生命周期函数--监听页面卸载
  254. */
  255. onUnload: function () {},
  256. /**
  257. * 页面相关事件处理函数--监听用户下拉动作
  258. */
  259. onPullDownRefresh: function () {},
  260. /**
  261. * 页面上拉触底事件的处理函数
  262. */
  263. onReachBottom: function () {},
  264. /**
  265. * 用户点击右上角分享
  266. */
  267. onShareAppMessage: function () {}
  268. })