chatList.vue 5.5 KB

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