数字化园区前端项目
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Message.vue 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="my-message" data-1664346848130>
  3. <div class="message-header">
  4. <Nav />
  5. </div>
  6. <div class="message-content-container">
  7. <div class="title">
  8. <img @click="goBack" src="~@assets/image/myRelated/titleIcon.png" class="title-icon fl" alt="icon" />
  9. <span class="title-span fl">我的消息</span>
  10. </div>
  11. <div class="table-box" v-loading="pageLoading" element-loading-text="数据加载中...">
  12. <div class="table-title">
  13. <span class="title-span fl">我的消息</span>
  14. <span class="unread-span" v-if="notRead > 0">
  15. (您有
  16. <span class="unread-num">{{ notRead }}</span>条未读通知)
  17. </span>
  18. <span class="mark-read fr" @click="markRead('all')">全部标记已读</span>
  19. <span class="mark-read fr" @click="markRead('check')">勾选标记已读</span>
  20. </div>
  21. <div class="table-container">
  22. <el-table class="block-table" :data="tableData" @row-click="openDetail">
  23. <el-table-column width="34" :align="'center'" class-name="checked-column">
  24. <template slot-scope="scope">
  25. <span
  26. class="check-span"
  27. :class="{'is-read' : scope.row.isRead}"
  28. @click.stop="changeCheck(scope.row)"
  29. >
  30. <img
  31. v-if="scope.row.isSelected"
  32. src="~@assets/image/myRelated/checked.png"
  33. alt="checkOk"
  34. />
  35. </span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column
  39. :label="item.label"
  40. v-for="(item,inx) of tableColumn"
  41. :key="inx"
  42. :width="item.width"
  43. :show-overflow-tooltip="true"
  44. >
  45. <template slot-scope="scope">
  46. <div
  47. v-if="item.prop == 'modifiedOn'"
  48. >{{ scope.row[item.prop] | formatDate("YYYY-MM-DD HH:mm") }}</div>
  49. <div v-else-if="item.prop == 'type'">{{ scope.row[item.prop].text }}</div>
  50. <div v-else-if="item.prop == 'isRead'">
  51. <span v-if="scope.row.isRead">已读</span>
  52. <img
  53. v-else
  54. src="~@assets/image/myRelated/notRead.png"
  55. alt="notRead"
  56. />
  57. </div>
  58. <div v-else>{{ scope.row[item.prop] }}</div>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. </div>
  63. <div class="pagination_box">
  64. <Pagination
  65. :currentPage="queryParams.page"
  66. :total="queryParams.total"
  67. @change-page-size="changePageSize"
  68. @change-page="changePage"
  69. />
  70. </div>
  71. </div>
  72. </div>
  73. <!-- 消息详情 -->
  74. <MessageDetailDialog ref="MessageDetailDialog" @close="getMessageNoticeList"/>
  75. <Footer />
  76. </div>
  77. </template>
  78. <script>
  79. import "./Message.scss";
  80. import Nav from "@components/Header.vue";
  81. import Footer from "@components/Footer.vue";
  82. import Pagination from "@components/Pagination.vue";
  83. import { getMessageNoticeList, markReadMessage } from "@api/my-related";
  84. import MessageDetailDialog from "./components/MessageDetailDialog/index.vue";
  85. export default {
  86. components: { Nav, Footer, Pagination, MessageDetailDialog },
  87. data() {
  88. return {
  89. pageLoading: false,
  90. tableColumn: [
  91. {
  92. label: "通知时间",
  93. prop: "modifiedOn",
  94. width: 160,
  95. },
  96. {
  97. label: "标题",
  98. prop: "title",
  99. },
  100. {
  101. label: "类型",
  102. prop: "type",
  103. width: 120,
  104. },
  105. {
  106. label: "是否已读",
  107. prop: "isRead",
  108. width: 100,
  109. },
  110. ],
  111. tableData: [],
  112. queryParams: {
  113. page: 1,
  114. pageSize: 10,
  115. total: 0,
  116. },
  117. // 选中list
  118. checkedList: [],
  119. // 未读数
  120. notRead: 0,
  121. };
  122. },
  123. mounted() {
  124. this.getMessageNoticeList();
  125. },
  126. methods: {
  127. // 分页切换
  128. changePageSize(v){
  129. this.queryParams.pageSize = v;
  130. this.getMessageNoticeList();
  131. },
  132. changePage(v){
  133. this.queryParams.page = v;
  134. this.getMessageNoticeList();
  135. },
  136. // 获取列表数据
  137. getMessageNoticeList() {
  138. this.pageLoading = true;
  139. getMessageNoticeList(this.queryParams)
  140. .then((res) => {
  141. // console.log(res);
  142. if (res.data.status == 0) {
  143. const data = res.data.data;
  144. let { resultData } = data;
  145. this.tableData = resultData.list.map((el) => {
  146. el.isSelected = false;
  147. return el;
  148. });
  149. console.log(
  150. this.$cloneDeep(this.tableData),
  151. "this.tableData"
  152. );
  153. this.queryParams.total = resultData.total;
  154. this.notRead = resultData.total - data.readCount;
  155. this.notRead = this.notRead < 0 ? 0 : this.notRead;
  156. } else if (res.data.status == 102) {
  157. this.$router.push("/login");
  158. } else {
  159. this.$message.error(res.data.msg);
  160. }
  161. this.pageLoading = false;
  162. })
  163. .catch((err) => {
  164. console.log(err);
  165. this.pageLoading = false;
  166. this.$message.error(
  167. `获取数据失败,失败原因${err},请刷新重试!`
  168. );
  169. });
  170. },
  171. /**
  172. * 标记已读
  173. * @param {*} target all 全部 check 勾选已读
  174. */
  175. markRead(target) {
  176. let param = [];
  177. if (target == "check") {
  178. if (this.checkedList.length < 1) {
  179. return this.$message.error("请至少勾选一条数据");
  180. } else {
  181. param = this.checkedList;
  182. }
  183. }
  184. // 设置已读
  185. console.log(this.$cloneDeep(param), "已读传参");
  186. this.markReadMessage(param, true);
  187. },
  188. // 设置已读Api
  189. markReadMessage(list, needRefresh) {
  190. markReadMessage(list)
  191. .then((res) => {
  192. if (res.data.status == 0 && needRefresh) {
  193. this.getMessageNoticeList();
  194. }
  195. })
  196. .catch((err) => {
  197. console.log(err);
  198. });
  199. },
  200. // 单元格点击
  201. changeCheck(row) {
  202. if (row.isRead) {
  203. return;
  204. }
  205. row.isSelected = !row.isSelected;
  206. // 如果已勾选的list里有这个ID,并且此数据为false 需要删除
  207. if (
  208. this.checkedList.includes(row.messageNoticeId) &&
  209. !row.isSelected
  210. ) {
  211. this.checkedList.splice(
  212. this.checkedList.indexOf(row.messageNoticeId),
  213. 1
  214. );
  215. }
  216. // 直接push
  217. else {
  218. this.checkedList.push(row.messageNoticeId);
  219. }
  220. },
  221. // 打开详情弹框
  222. openDetail(row) {
  223. this.$refs.MessageDetailDialog.openDialog(row);
  224. if(!row.isRead){
  225. row.isRead = true;
  226. this.markReadMessage([row.messageNoticeId]);
  227. }
  228. },
  229. // 返回上一页
  230. goBack(){
  231. this.$router.push('/my-business');
  232. },
  233. },
  234. };
  235. </script>