index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. import {
  16. toast,
  17. showConfirm,
  18. tansParams
  19. } from '@/utils/common'
  20. let isOver = ref(true)
  21. // 切换
  22. let switchActiveArr = ['未读', '已读', '自发'];
  23. let switchActive = ref('未读');
  24. const switchSetActive = function(val) {
  25. defaultCurrent.value = val;
  26. switchActive.value = switchActiveArr[val];
  27. searchInfo.value.pageNo = 1
  28. isOver.value = true
  29. if (switchActive.value === "已读") {
  30. searchInfo.value.read = true
  31. getList();
  32. }
  33. if (switchActive.value === "未读") {
  34. searchInfo.value.read = false
  35. getList();
  36. }
  37. if (switchActive.value === "自发") {
  38. getCreateList();
  39. }
  40. };
  41. // swiper
  42. let defaultCurrent = ref(0);
  43. const chgangeSwiperItem = function(e) {
  44. switchActive.value = switchActiveArr[e.detail.current];
  45. }
  46. // 数据
  47. let unReadList = ref([]);
  48. let readList = ref([]);
  49. let createList = ref([]);
  50. // 获取数据
  51. let searchInfo = ref({
  52. pageNo: 1,
  53. pageSize: 10,
  54. read: false,
  55. beginDate: '',
  56. endDate: '',
  57. userName: '',
  58. content: '',
  59. });
  60. function getList() {
  61. if (searchInfo.value.pageNo == 1) {
  62. readList.value = []
  63. unReadList.value = []
  64. }
  65. console.log(searchInfo.value, '列表请求参数');
  66. if (isOver.value) {
  67. getMessageList(searchInfo.value).then(res => {
  68. if (res.data.pageTotal == 0 || res.data.pageTotal <= searchInfo.value.pageNo) {
  69. isOver.value = false
  70. }
  71. if (searchInfo.value.read) {
  72. readList.value = readList.value.concat(res.data.list);
  73. } else {
  74. unReadList.value = unReadList.value.concat(res.data.list);
  75. }
  76. });
  77. }
  78. };
  79. let searchObj = {};
  80. function getCreateList() {
  81. if (searchInfo.value.pageNo == 1) {
  82. createList.value = []
  83. }
  84. console.log(searchInfo.value, '列表请求参数');
  85. if (isOver.value) {
  86. getMessageCreateList(searchInfo.value).then(res => {
  87. if (res.data.pageTotal == 0 || res.data.pageTotal <= searchInfo.value.pageNo) {
  88. isOver.value = false
  89. }
  90. createList.value = createList.value.concat(res.data.list);
  91. })
  92. }
  93. }
  94. // 跳转页面
  95. function goToPage(url) {
  96. uni.navigateTo({
  97. url
  98. })
  99. }
  100. // 去详情
  101. function goToDetail(type, id, userName, content) {
  102. if (type === "unread") {
  103. console.log(unReadList.value);
  104. let index = unReadList.value.findIndex(item => item.id === id);
  105. unReadList.value.splice(index, 1)
  106. }
  107. uni.navigateTo({
  108. url: `/pages/message/detail/index?type=${type}&id=${id}&userName=${userName}&content=${content}`
  109. })
  110. }
  111. // 改数量
  112. function getMessageCount() {
  113. getMessageNum().then(res => {
  114. if (res.data.count) {
  115. uni.setTabBarBadge({ //显示数字
  116. index: 1, //tabbar下标
  117. text: res.data.count //数字
  118. })
  119. } else {
  120. uni.removeTabBarBadge({ //显示数字
  121. index: 1, //tabbar下标
  122. })
  123. }
  124. })
  125. }
  126. //触底加载
  127. function onScrolltData() {
  128. searchInfo.value.pageNo++
  129. if (switchActive.value === "已读") {
  130. searchInfo.value.read = true
  131. getList();
  132. }
  133. if (switchActive.value === "未读") {
  134. searchInfo.value.read = false
  135. getList();
  136. }
  137. if (switchActive.value === "自发") {
  138. getCreateList();
  139. }
  140. if (!isOver.value) {
  141. toast('无更多消息')
  142. }
  143. }
  144. //跳转搜索
  145. function gotoSearch(e) {
  146. uni.$u.route({
  147. url: 'pages/message/search/index',
  148. params: searchInfo.value
  149. })
  150. }
  151. function search() {
  152. isOver.value = true
  153. searchInfo.value.pageNo = 1
  154. if (switchActive.value === "已读") {
  155. searchInfo.value.read = true
  156. getList();
  157. }
  158. if (switchActive.value === "未读") {
  159. searchInfo.value.read = false
  160. getList();
  161. }
  162. if (switchActive.value === "自发") {
  163. getCreateList();
  164. }
  165. }
  166. onLoad(() => {
  167. uni.$on('messageSearch', resolve => {
  168. searchInfo.value.pageNo = 1
  169. isOver.value = true
  170. searchInfo.value.content = resolve.content
  171. searchInfo.value.beginDate = resolve.beginDate
  172. searchInfo.value.endDate = resolve.endDate
  173. searchInfo.value.userName = resolve.userName
  174. search();
  175. console.log('执行搜索', resolve);
  176. })
  177. search()
  178. })
  179. onShow(() => {
  180. getMessageCount();
  181. })
  182. onUnload(() => {
  183. uni.$off('messageSearch');
  184. })
  185. </script>
  186. <template>
  187. <view class="container" style="padding-top: 0 !important;">
  188. <view class="top-box">
  189. <view class="tabs-layer">
  190. <view class="tabs-search" @click="gotoSearch()">
  191. <image src="@/static/images/messageSearch.svg" mode=""></image>
  192. <text>查询</text>
  193. </view>
  194. <view class="tabs-box">
  195. <view class="switch-item" :class="switchActive === '未读'?'active':''" @click="switchSetActive(0)">未读
  196. </view>
  197. <view class="switch-item" :class="switchActive === '已读'?'active':''" @click="switchSetActive(1)">已读
  198. </view>
  199. <view class="switch-item" :class="switchActive === '自发'?'active':''" @click="switchSetActive(2)">自发
  200. </view>
  201. </view>
  202. </view>
  203. </view>
  204. <view class="content">
  205. <swiper class="swiper" :current="defaultCurrent" @change="chgangeSwiperItem">
  206. <swiper-item>
  207. <scroll-view class="swiper-item-content" scroll-y @scrolltolower="onScrolltData">
  208. <view class="card" v-for="(item,index) in unReadList" :key="index">
  209. <view class="card-status-message no-read">
  210. 未读
  211. </view>
  212. <view class="card-massage-top">
  213. <view class="time">
  214. {{item.createTime}}
  215. </view>
  216. <view class="view-btn" @click="goToDetail('unread',item.id,item.userName,item.content)">
  217. 查看
  218. </view>
  219. </view>
  220. <view class="card-massage-from">
  221. <view class="card-massage-from-item">
  222. <view class="item-label">
  223. 发送人
  224. </view>
  225. <view class="item-text">
  226. {{item.userName}}
  227. </view>
  228. </view>
  229. <view class="card-massage-from-item">
  230. <view class="item-label">
  231. 内&nbsp;&nbsp;&nbsp;容
  232. </view>
  233. <view class="item-text">
  234. {{item.content}}
  235. </view>
  236. </view>
  237. </view>
  238. </view>
  239. <view class="item-empty" v-if="unReadList.length === 0">
  240. <empty-show onlyText showText='暂无消息'></empty-show>
  241. </view>
  242. </scroll-view>
  243. </swiper-item>
  244. <swiper-item>
  245. <scroll-view class="swiper-item-content" scroll-y @scrolltolower="onScrolltData">
  246. <view class="card" v-for="(item,index) in readList" :key="index">
  247. <view class="card-status-message over-read">
  248. 已读
  249. </view>
  250. <view class="card-massage-top">
  251. <view class="time">
  252. {{item.createTime}}
  253. </view>
  254. <view class="view-btn" @click="goToDetail('read',item.id,item.userName,item.content)">
  255. 查看
  256. </view>
  257. </view>
  258. <view class="card-massage-from">
  259. <view class="card-massage-from-item">
  260. <view class="item-label">
  261. 发送人
  262. </view>
  263. <view class="item-text">
  264. {{item.userName}}
  265. </view>
  266. </view>
  267. <view class="card-massage-from-item">
  268. <view class="item-label">
  269. 内&nbsp;&nbsp;&nbsp;容
  270. </view>
  271. <view class="item-text">
  272. {{item.content}}
  273. </view>
  274. </view>
  275. </view>
  276. </view>
  277. <view class="item-empty" v-if="readList.length === 0">
  278. <empty-show onlyText showText='暂无消息'></empty-show>
  279. </view>
  280. </scroll-view>
  281. </swiper-item>
  282. <swiper-item>
  283. <scroll-view class="swiper-item-content" scroll-y @scrolltolower="onScrolltData">
  284. <view class="card" v-for="(item,index) in createList" :key="index">
  285. <view class="card-status-message no-read" v-if="item.status == '0'">
  286. 未读
  287. </view>
  288. <view class="card-status-message over-read" v-if="item.status == '1'">
  289. 已读
  290. </view>
  291. <view class="card-massage-top">
  292. <view class="time">
  293. {{item.createTime}}
  294. </view>
  295. <!-- <view class="view-btn" @click="goToDetail('unread',item.id,item.userName,item.content)">
  296. 查看
  297. </view> -->
  298. </view>
  299. <view class="card-massage-from">
  300. <view class="card-massage-from-item">
  301. <view class="item-label">
  302. 接收人
  303. </view>
  304. <view class="item-text">
  305. {{item.userName}}
  306. </view>
  307. </view>
  308. <view class="card-massage-from-item">
  309. <view class="item-label">
  310. 内&nbsp;&nbsp;&nbsp;容
  311. </view>
  312. <view class="item-text">
  313. {{item.content}}
  314. </view>
  315. </view>
  316. </view>
  317. </view>
  318. <view class="item-empty" v-if="createList.length === 0">
  319. <empty-show onlyText showText='暂无消息'></empty-show>
  320. </view>
  321. </scroll-view>
  322. </swiper-item>
  323. </swiper>
  324. </view>
  325. <view class="send-massage">
  326. <text @click="goToPage('/pages/message/send/index')">发送<br />消息</text>
  327. </view>
  328. </view>
  329. </template>
  330. <style lang="scss" scoped>
  331. .item-empty {
  332. width: 100%;
  333. height: calc(100% - 32rpx);
  334. }
  335. .send-massage {
  336. position: relative;
  337. position: fixed;
  338. bottom: calc(var(--window-bottom) + 16rpx);
  339. right: 8rpx;
  340. width: 160rpx;
  341. height: 160rpx;
  342. font-weight: 500;
  343. font-size: 28rpx;
  344. color: #FFFFFF;
  345. line-height: 36rpx;
  346. background-image: url('@/static/massage-send-icon.svg');
  347. text {
  348. position: absolute;
  349. top: 50%;
  350. left: 50%;
  351. transform: translate(-58%, -55%);
  352. }
  353. }
  354. .top-box {
  355. height: calc(var(--status-bar-height) + 88rpx);
  356. display: flex;
  357. justify-content: center;
  358. align-items: flex-end;
  359. background-color: #002F69;
  360. }
  361. .tabs-layer {
  362. padding: 0 2.5% 0 2.5%;
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. gap: 20rpx;
  367. width: 100%;
  368. background-color: #002F69;
  369. height: 88rpx;
  370. .tabs-search {
  371. display: flex;
  372. justify-content: center;
  373. align-items: center;
  374. gap: 5rpx;
  375. width: 128rpx;
  376. height: 56rpx;
  377. // background: #FFFFFF;
  378. border: 2rpx solid #244B7E;
  379. border-radius: 12rpx;
  380. opacity: 0.9;
  381. font-weight: 500;
  382. font-size: 24rpx;
  383. color: #333333;
  384. image {
  385. width: 40rpx;
  386. height: 40rpx;
  387. }
  388. text {
  389. font-weight: 500;
  390. font-size: 32rpx;
  391. color: #FFFFFF;
  392. }
  393. }
  394. .tabs-box {
  395. flex-grow: 1;
  396. display: flex;
  397. justify-content: center;
  398. align-items: center;
  399. gap: 72rpx;
  400. .switch-item {
  401. font-size: 32rpx;
  402. font-weight: 500;
  403. color: rgba(255, 255, 255, 0.6);
  404. }
  405. }
  406. }
  407. .active {
  408. font-size: 32rpx;
  409. color: #FFFFFF !important;
  410. }
  411. .over-read {
  412. background-color: #C7FDD9;
  413. color: #03872F;
  414. }
  415. .no-read {
  416. background-color: #FFCBC1 !important;
  417. color: #B00909;
  418. }
  419. .content {
  420. width: 100%;
  421. height: calc(100vh - var(--status-bar-height) - 88rpx - var(--window-bottom));
  422. .swiper {
  423. width: 100%;
  424. height: 100%;
  425. .swiper-item-content {
  426. height: 100%;
  427. .line {
  428. width: 100%;
  429. height: 32rpx;
  430. }
  431. }
  432. }
  433. }
  434. .card {
  435. width: 95%;
  436. padding: 18rpx 44rpx !important;
  437. margin: auto;
  438. margin-top: 32rpx;
  439. .card-status-message {
  440. position: absolute;
  441. top: 18rpx;
  442. right: 0;
  443. display: flex;
  444. justify-content: center;
  445. align-items: center;
  446. width: 96rpx;
  447. height: 48rpx;
  448. background: #D3F4FF;
  449. border-radius: 16rpx 0rpx 0rpx 16rpx;
  450. }
  451. .card-massage-top {
  452. display: flex;
  453. justify-content: space-between;
  454. align-items: center;
  455. width: 100%;
  456. padding-right: 80rpx;
  457. .time {
  458. font-size: 24rpx;
  459. font-weight: 300;
  460. color: #444444;
  461. }
  462. .view-btn {
  463. display: flex;
  464. justify-content: center;
  465. align-items: center;
  466. width: 96rpx;
  467. height: 48rpx;
  468. background: #F6F6F6;
  469. border-radius: 16rpx;
  470. font-size: 28rpx;
  471. color: #275797;
  472. font-weight: 500;
  473. }
  474. }
  475. .card-massage-from {
  476. margin-top: 16rpx;
  477. padding-top: 28rpx;
  478. display: flex;
  479. flex-direction: column;
  480. align-items: flex-start;
  481. justify-content: flex-start;
  482. gap: 14rpx;
  483. width: 100%;
  484. border-top: 1px dashed #DDDDDD;
  485. min-height: 150rpx;
  486. .card-massage-from-item {
  487. display: flex;
  488. justify-content: flex-start;
  489. align-items: flex-start;
  490. gap: 20rpx;
  491. .item-label {
  492. width: 100rpx;
  493. font-weight: 500;
  494. font-size: 28rpx;
  495. color: #B5B5B5;
  496. white-space: nowrap;
  497. }
  498. .item-text {
  499. width: calc(100% - 140rpx);
  500. flex-grow: 1;
  501. font-size: 28rpx;
  502. font-weight: 500;
  503. color: #222222;
  504. line-break: anywhere;
  505. }
  506. }
  507. }
  508. .card-item-page {
  509. display: flex;
  510. width: 100%;
  511. padding: 20rpx 26rpx;
  512. box-sizing: border-box;
  513. font-size: 28rpx;
  514. font-weight: 400;
  515. .card-item-key {
  516. color: #939AA5;
  517. min-width: 140rpx;
  518. }
  519. .card-item-value {
  520. display: flex;
  521. justify-content: space-between;
  522. align-items: center;
  523. width: 100%;
  524. color: #343437;
  525. line-height: 46rpx;
  526. line-break: anywhere;
  527. }
  528. .card-item-look {
  529. color: #1763E7;
  530. }
  531. .card-item-read {
  532. width: 62rpx;
  533. height: 32rpx;
  534. line-height: 32rpx;
  535. text-align: center;
  536. background-color: #C7FDD9;
  537. border-radius: 12rpx;
  538. font-size: 24rpx;
  539. color: #03872F;
  540. }
  541. .unread {
  542. background-color: #FFCBC1;
  543. color: #B00909;
  544. }
  545. }
  546. }
  547. </style>