chatList.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <!-- -->
  2. <template>
  3. <div class="m-container">
  4. <save-form :inline="true" :model="searchForm" @submit="search" @reset="onReSet" ref="searchForm">
  5. <el-form-item>
  6. <el-input v-model.trim="searchForm.search" clearable @keyup.enter.native="e => {
  7. e.target.blur();
  8. $refs.searchForm.save();
  9. search();
  10. }
  11. " placeholder="群聊名称"></el-input>
  12. </el-form-item>
  13. <el-form-item prop="groupType">
  14. <el-select v-model.trim="searchForm.groupType" clearable filterable placeholder="群聊类型">
  15. <el-option v-for="(item, index) in catgGoupTypeList" :key="index" :value="item.value"
  16. :label="item.label"></el-option>
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button native-type="submit" type="primary">搜索</el-button>
  21. <el-button native-type="reset" type="danger">重置</el-button>
  22. </el-form-item>
  23. </save-form>
  24. <div class="btnWraps">
  25. <auth auths="imSendGroupMessage/send">
  26. <el-button @click="postMsg" type="primary" style="margin-bottom: 20px">
  27. 消息群发
  28. </el-button>
  29. </auth>
  30. <auth auths="imGroup/createGroup">
  31. <el-button @click="addChat" type="primary" style="margin-bottom: 20px">
  32. 创建群聊
  33. </el-button>
  34. </auth>
  35. </div>
  36. <div class="tableWrap">
  37. <el-table style="width: 100%" :header-cell-style="{ background: '#EDEEF0', color: '#444' }" :data="tableList"
  38. @selection-change="handleSelectionChange" @select="onTableSelect" ref="multipleSelection">
  39. <el-table-column type="selection" width="55"> </el-table-column>
  40. <el-table-column align="center" prop="id" label="群聊"></el-table-column>
  41. <el-table-column align="center" prop="name" label="群聊名称"></el-table-column>
  42. <el-table-column align="center" prop="memo" label="群备注"></el-table-column>
  43. <el-table-column align="center" prop="groupType" label="群聊类型">
  44. <template slot-scope="scope">
  45. <div>
  46. {{ scope.row.groupType | catgGoupType }}
  47. </div>
  48. </template>
  49. </el-table-column>
  50. <el-table-column align="center" prop="groupType" label="群类型">
  51. <template slot-scope="scope">
  52. <div>
  53. {{ scope.row.type | catType }}
  54. </div>
  55. </template>
  56. </el-table-column>
  57. <el-table-column align="center" prop="memberNum" label="人数"></el-table-column>
  58. <el-table-column align="center" prop="memberNum" label="操作">
  59. <template slot-scope="scope">
  60. <div>
  61. <auth auths="/chatDetail">
  62. <el-button type="text" @click="gotoCatDetail(scope.row)">详情</el-button>
  63. </auth>
  64. <auth auths="imGroup/updateImGroup">
  65. <el-button type="text" @click="cancelCat(scope.row)">解散</el-button>
  66. </auth>
  67. </div>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <pagination sync :total.sync="rules.total" :page.sync="rules.page" :limit.sync="rules.limit"
  72. :page-sizes="rules.page_size" @pagination="getList" />
  73. </div>
  74. <eidtPostMsg ref="eidtPostMsg" @clear="clearCom" />
  75. <eidtCatInfo ref="eidtCatInfo" @getList="getList" />
  76. <addChatForm ref="addChatForm" @getList="getList" />
  77. </div>
  78. </template>
  79. <script>
  80. import axios from "axios";
  81. import { getToken } from "@/utils/auth";
  82. import pagination from "@/components/Pagination/index";
  83. import load from "@/utils/loading";
  84. import { getTimes } from "@/utils";
  85. import { getGroupList, dismissGroup } from "../api";
  86. import { catgGoupTypeList } from "@/utils/searchArray";
  87. import eidtPostMsg from "../model/eidtPostMsg";
  88. import eidtCatInfo from "../model/eidtCatInfo";
  89. import addChatForm from "../model/addChatForm";
  90. export default {
  91. components: { pagination, eidtPostMsg, eidtCatInfo, addChatForm },
  92. data() {
  93. return {
  94. searchForm: {
  95. search: null,
  96. groupType: ""
  97. },
  98. catgGoupTypeList,
  99. tableList: [],
  100. organList: [],
  101. rules: {
  102. // 分页规则
  103. limit: 10, // 限制显示条数
  104. page: 1, // 当前页
  105. total: 0, // 总条数
  106. page_size: [10, 20, 40, 50] // 选择限制显示条数
  107. },
  108. addMuiscVisible: false,
  109. multipleSelection: [],
  110. chioseIdList: [],
  111. isNewPage: false
  112. };
  113. },
  114. //生命周期 - 创建完成(可以访问当前this实例)
  115. created() { },
  116. //生命周期 - 挂载完成(可以访问DOM元素)
  117. mounted() {
  118. // 获取分部
  119. this.init();
  120. },
  121. methods: {
  122. init() {
  123. this.getList();
  124. },
  125. async getList() {
  126. // let { timer, ...rest } = this.searchForm;
  127. // let params = {
  128. // ...rest,
  129. // page: this.rules.page,
  130. // rows: this.rules.limit,
  131. // ...getTimes(timer, ["startTime", "endTime"]),
  132. // };
  133. try {
  134. const res = await getGroupList({
  135. ...this.searchForm,
  136. page: this.rules.page,
  137. rows: this.rules.limit
  138. });
  139. this.tableList = res.data.rows;
  140. this.rules.total = res.data.total;
  141. let idList = this.chioseIdList.map(group => {
  142. return group.id;
  143. });
  144. this.isNewPage = true;
  145. this.$nextTick(() => {
  146. this.tableList.forEach(course => {
  147. if (idList.indexOf(course.id) != -1) {
  148. this.$refs.multipleSelection.toggleRowSelection(course, true);
  149. }
  150. });
  151. this.isNewPage = false;
  152. });
  153. } catch (e) {
  154. console.log(e);
  155. }
  156. },
  157. search() {
  158. this.rules.page = 1;
  159. this.getList();
  160. },
  161. onReSet() {
  162. this.searchForm.search = "";
  163. this.searchForm.groupType = "";
  164. this.rules.page = 1;
  165. this.getList();
  166. },
  167. postMsg() {
  168. if (!this.chioseIdList || this.chioseIdList.length <= 0) {
  169. this.$message.error("请至少选择一个群聊");
  170. return;
  171. }
  172. this.$refs.eidtPostMsg.openDioag(this.chioseIdList);
  173. },
  174. handleSelectionChange(val) {
  175. if (val.length > 0) {
  176. this.chioseIdList = this.chioseIdList.concat(val);
  177. this.chioseIdList = this.$helpers.lodash.uniqBy(
  178. this.chioseIdList,
  179. "id"
  180. );
  181. } else {
  182. if (this.isNewPage) return;
  183. let idList = this.chioseIdList.map(group => {
  184. return group.id;
  185. });
  186. this.$nextTick(() => {
  187. let tableIdList = [];
  188. this.tableList.forEach(group => {
  189. tableIdList.push(group.id);
  190. if (idList.indexOf(group.id) != -1) {
  191. this.$refs.multipleSelection.toggleRowSelection(group, false);
  192. }
  193. });
  194. this.chioseIdList = this.$helpers.lodash.remove(
  195. this.chioseIdList,
  196. function (item) {
  197. return tableIdList.indexOf(item.id) == -1;
  198. }
  199. );
  200. if (this.chioseIdList.length <= 0) {
  201. this.clearCom();
  202. }
  203. });
  204. }
  205. },
  206. clearCom() {
  207. this.chioseIdList = [];
  208. this.$refs.multipleSelection.clearSelection();
  209. },
  210. onTableSelect(rows, row) {
  211. let idList = this.chioseIdList.map(group => {
  212. return group.id;
  213. });
  214. if (idList.indexOf(row.id) != -1) {
  215. this.chioseIdList.splice(idList.indexOf(row.id), 1);
  216. if (this.chioseIdList.length <= 0) {
  217. this.clearCom();
  218. }
  219. }
  220. },
  221. resetCat(row) {
  222. this.$refs.eidtCatInfo.openResetDioag(row);
  223. },
  224. gotoCatDetail(row) {
  225. this.$router.push({
  226. path: "/operateManager/chatDetail",
  227. query: { imGroupId: row.id, name: row.name }
  228. });
  229. console.log(row);
  230. },
  231. addChat() {
  232. this.$refs.addChatForm.openDioag();
  233. },
  234. async cancelCat(row) {
  235. try {
  236. await this.$confirm("是否解散群组" + row.name + "?", "提示", {
  237. type: "warning"
  238. });
  239. const res = await dismissGroup({ imGroupId: row.id });
  240. this.$message.success("取消成功");
  241. this.getList();
  242. } catch (e) {
  243. console.log(e);
  244. }
  245. }
  246. }
  247. };
  248. </script>
  249. <style lang="scss" scoped></style>