index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <script setup>
  2. import {
  3. ref
  4. } from "vue";
  5. import {
  6. onLoad,
  7. onShow,
  8. onUnload,
  9. } from "@dcloudio/uni-app";
  10. import {
  11. getMessageList,
  12. getMessageCreateList,
  13. getMessageNum
  14. } from "@/api/work/message.js";
  15. // 切换
  16. let switchActiveArr = ['未读', '已读', '消息'];
  17. let switchActive = ref('未读');
  18. const switchSetActive = function(val) {
  19. defaultCurrent.value = val;
  20. switchActive.value = switchActiveArr[val];
  21. if (switchActive.value === "未读" || switchActive.value === "已读") getList();
  22. if (switchActive.value === "消息") getCreateList();
  23. };
  24. // swiper
  25. let defaultCurrent = ref(0);
  26. const chgangeSwiperItem = function(e) {
  27. switchActive.value = switchActiveArr[e.detail.current];
  28. }
  29. // 数据
  30. let unReadList = ref([]);
  31. let readList = ref([]);
  32. let createList = ref([]);
  33. // 获取数据
  34. let searchInfo = ref({
  35. // pageNo: 1,
  36. // pageSize: 10,
  37. });
  38. function getList() {
  39. const params = Object.assign(searchInfo.value, {
  40. read: switchActive.value === "已读"
  41. });
  42. getMessageList(params).then(res => {
  43. if (searchInfo.value.read) {
  44. readList.value = res.data.list;
  45. } else {
  46. unReadList.value = res.data.list;
  47. }
  48. });
  49. };
  50. let searchObj = {};
  51. function getCreateList(params = searchObj) {
  52. getMessageCreateList(params).then(res => {
  53. createList.value = res.data.list;
  54. })
  55. }
  56. // 跳转页面
  57. function goToPage(url) {
  58. uni.navigateTo({
  59. url
  60. })
  61. }
  62. // 去详情
  63. function goToDetail(type, id, userName, content) {
  64. if (type === "unread") {
  65. console.log(unReadList.value);
  66. let index = unReadList.value.findIndex(item => item.id === id);
  67. unReadList.value.splice(index, 1)
  68. }
  69. uni.navigateTo({
  70. url: `/pages/message/detail/index?type=${type}&id=${id}&userName=${userName}&content=${content}`
  71. })
  72. }
  73. // 改数量
  74. function getMessageCount() {
  75. getMessageNum().then(res => {
  76. if (res.data.count) {
  77. uni.setTabBarBadge({ //显示数字
  78. index: 1, //tabbar下标
  79. text: res.data.count //数字
  80. })
  81. } else {
  82. uni.removeTabBarBadge({ //显示数字
  83. index: 1, //tabbar下标
  84. })
  85. }
  86. })
  87. }
  88. onLoad(() => {
  89. uni.$on('messageSearch', resolve => {
  90. searchObj = resolve;
  91. getCreateList(searchObj);
  92. })
  93. getList();
  94. })
  95. onShow(() => {
  96. getMessageCount();
  97. })
  98. onUnload(() => {
  99. uni.$off('messageSearch');
  100. })
  101. </script>
  102. <template>
  103. <view class="main">
  104. <view class="title">
  105. <view class="send-box">
  106. <view class="title-search" @click="goToPage('/pages/message/search/index')"></view>
  107. <view class="text">
  108. 查询消息
  109. </view>
  110. </view>
  111. <view class="title-text">消息</view>
  112. <view class="send-box">
  113. <view class="title-send" @click="goToPage('/pages/message/send/index')"></view>
  114. <view class="text">
  115. 发送消息
  116. </view>
  117. </view>
  118. </view>
  119. <view class="switch">
  120. <view class="switch-item" :class="switchActive === '未读'?'active':''" @click="switchSetActive(0)">未读</view>
  121. <view class="switch-item" :class="switchActive === '已读'?'active':''" @click="switchSetActive(1)">已读</view>
  122. <view class="switch-item" :class="switchActive === '消息'?'active':''" @click="switchSetActive(2)">发消息</view>
  123. </view>
  124. <view class="content">
  125. <swiper class="swiper" :current="defaultCurrent" @change="chgangeSwiperItem">
  126. <swiper-item>
  127. <scroll-view class="swiper-item-content" scroll-y>
  128. <view class="card-page" v-for="(item,index) in unReadList" :key="index"
  129. @click="goToDetail('unread',item.id,item.userName,item.content)">
  130. <view class="card-item-page">
  131. <view class="card-item-key">发送人:</view>
  132. <view class="card-item-value">
  133. <text>{{item.userName}}</text>
  134. <text class="card-item-look">前往查看</text>
  135. </view>
  136. </view>
  137. <view class="card-item-page">
  138. <view class="card-item-key">消息时间:</view>
  139. <view class="card-item-value">
  140. <text>{{item.createTime}}</text>
  141. <view class="card-item-read unread">未读</view>
  142. </view>
  143. </view>
  144. <view class="card-item-page">
  145. <view class="card-item-key">内容:</view>
  146. <view class="card-item-value">{{item.content}}</view>
  147. </view>
  148. </view>
  149. <view class="item-empty" v-if="unReadList.length === 0">
  150. <empty-show onlyText showText='暂无消息'></empty-show>
  151. </view>
  152. </scroll-view>
  153. </swiper-item>
  154. <swiper-item>
  155. <scroll-view class="swiper-item-content" scroll-y>
  156. <view class="card-page" v-for="(item,index) in readList" :key="index"
  157. @click="goToDetail('read',item.id,item.userName,item.content)">
  158. <view class="card-item-page">
  159. <view class="card-item-key">发送人:</view>
  160. <view class="card-item-value">
  161. <text>{{item.userName}}</text>
  162. <text class="card-item-look">前往查看</text>
  163. </view>
  164. </view>
  165. <view class="card-item-page">
  166. <view class="card-item-key">消息时间:</view>
  167. <view class="card-item-value">
  168. <text>{{item.createTime}}</text>
  169. <view class="card-item-read">已读</view>
  170. </view>
  171. </view>
  172. <view class="card-item-page">
  173. <view class="card-item-key">内容:</view>
  174. <view class="card-item-value">{{item.content}}</view>
  175. </view>
  176. </view>
  177. <view class="item-empty" v-if="readList.length === 0">
  178. <empty-show onlyText showText='暂无消息'></empty-show>
  179. </view>
  180. </scroll-view>
  181. </swiper-item>
  182. <swiper-item>
  183. <scroll-view class="swiper-item-content" scroll-y>
  184. <view class="card-page" v-for="(item,index) in createList" :key="index">
  185. <view class="card-item-page">
  186. <!-- <view class="card-item-key">发送人:</view> -->
  187. <view class="card-item-key">接收人:</view>
  188. <view class="card-item-value">
  189. <text>{{item.userName}}</text>
  190. <view class="card-item-read unread" v-if="item.status == '0'">未读</view>
  191. <view class="card-item-read" v-if="item.status == '1'">已读</view>
  192. </view>
  193. </view>
  194. <view class="card-item-page">
  195. <view class="card-item-key">消息时间:</view>
  196. <view class="card-item-value">
  197. <text>{{item.createTime}}</text>
  198. </view>
  199. </view>
  200. <view class="card-item-page">
  201. <view class="card-item-key">内容:</view>
  202. <view class="card-item-value">{{item.content}}</view>
  203. </view>
  204. </view>
  205. <view class="item-empty" v-if="createList.length === 0">
  206. <empty-show onlyText showText='暂无消息'></empty-show>
  207. </view>
  208. </scroll-view>
  209. </swiper-item>
  210. </swiper>
  211. </view>
  212. </view>
  213. </template>
  214. <style lang="scss" scoped>
  215. .main {
  216. position: relative;
  217. width: 100%;
  218. height: 100%;
  219. background-color: #1869F6;
  220. }
  221. .item-empty {
  222. width: 100%;
  223. height: 500rpx;
  224. }
  225. .title {
  226. position: absolute;
  227. top: 98rpx;
  228. left: 4%;
  229. display: flex;
  230. justify-content: space-between;
  231. width: 92%;
  232. text-align: center;
  233. font-weight: 700;
  234. color: #FFFFFF;
  235. font-size: 36rpx;
  236. .title-search {
  237. width: 46rpx;
  238. height: 46rpx;
  239. background-image: url("@/static/search.png");
  240. background-size: 100% 100%;
  241. }
  242. .send-box {
  243. display: flex;
  244. flex-direction: column;
  245. align-items: center;
  246. justify-content: center;
  247. color: #fff;
  248. .title-send {
  249. width: 48rpx;
  250. height: 42rpx;
  251. background-image: url("@/static/message-send.png");
  252. background-size: 100% 100%;
  253. }
  254. .text {
  255. padding-top: 10rpx;
  256. font-size: 24rpx;
  257. font-weight: 400;
  258. }
  259. .title-search {
  260. width: 46rpx;
  261. height: 46rpx;
  262. background-image: url("@/static/search.png");
  263. background-size: 100% 100%;
  264. }
  265. }
  266. .no-bg {
  267. background: none;
  268. }
  269. }
  270. .switch {
  271. position: absolute;
  272. top: 196rpx;
  273. left: 66rpx;
  274. display: flex;
  275. align-items: center;
  276. width: calc(100% - 132rpx);
  277. height: 72rpx;
  278. .switch-item {
  279. flex: 1;
  280. text-align: center;
  281. color: #FFF;
  282. line-height: 46rpx;
  283. font-size: 32rpx;
  284. }
  285. .active {
  286. height: 72rpx;
  287. line-height: 72rpx;
  288. background-size: 100% 100%;
  289. background-image: url('@/static/message-switch.png');
  290. color: #1763E7;
  291. }
  292. }
  293. .content {
  294. position: absolute;
  295. top: 268rpx;
  296. left: 0;
  297. width: 100%;
  298. min-height: calc(100% - 268rpx);
  299. background-color: #fff;
  300. border-radius: 40rpx 40rpx 0 0;
  301. .swiper {
  302. width: 100%;
  303. height: calc(100vh - 268rpx);
  304. .swiper-item-content {
  305. height: 100%;
  306. padding: 42rpx 0 30rpx;
  307. }
  308. }
  309. }
  310. .card-page {
  311. width: 670rpx;
  312. min-height: 282rpx;
  313. margin: 0 auto 32rpx;
  314. border-radius: 26rpx;
  315. border: 2rpx solid #D0D9E7;
  316. .card-item-page {
  317. display: flex;
  318. width: 100%;
  319. padding: 20rpx 26rpx;
  320. box-sizing: border-box;
  321. font-size: 28rpx;
  322. font-weight: 400;
  323. .card-item-key {
  324. color: #939AA5;
  325. min-width: 140rpx;
  326. }
  327. .card-item-value {
  328. display: flex;
  329. justify-content: space-between;
  330. align-items: center;
  331. width: 100%;
  332. color: #343437;
  333. line-height: 46rpx;
  334. line-break: anywhere;
  335. }
  336. .card-item-look {
  337. color: #1763E7;
  338. }
  339. .card-item-read {
  340. width: 62rpx;
  341. height: 32rpx;
  342. line-height: 32rpx;
  343. text-align: center;
  344. background-color: #C7FDD9;
  345. border-radius: 12rpx;
  346. font-size: 24rpx;
  347. color: #03872F;
  348. }
  349. .unread {
  350. background-color: #FFCBC1;
  351. color: #B00909;
  352. }
  353. }
  354. }
  355. </style>