message.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view class="page">
  3. <u-sticky zIndex="999">
  4. <view class="tabView">
  5. <view class="item dis f-c a-c " v-for="(item, index) in tabViewList" :key="index"
  6. @click="tabClick(item)">
  7. <view class="iconImage">
  8. <image :src="item.image" mode=""></image>
  9. <view class="badge dis a-c j-c" v-if="item.sum">{{ item.sum > 99 ? '...' : item.sum }}</view>
  10. </view>
  11. <text>{{ item.text }}</text>
  12. </view>
  13. </view>
  14. </u-sticky>
  15. <view class="content" v-show="datalist.length != 0">
  16. <!-- 系统消息列表 -->
  17. <view class="viewitem dis f-c mb-2" v-if="pageQuery.type == '1'" v-for="(item, index) in datalist"
  18. :key="index" @click="detailClick(item)">
  19. <view class="title dis a-c ">
  20. <image src="/static/icon/message/message.png" mode=""></image>
  21. <text class="font-weight ml-1">{{ item.title }}</text>
  22. <text class="time">{{ item.createTime }}</text>
  23. </view>
  24. <view class="message-content">
  25. {{ item.content }}
  26. </view>
  27. </view>
  28. <!-- 订单消息列表 -->
  29. <view class="viewitem dis f-c mb-2 " v-if="pageQuery.type == '2'" v-for="(item, index) in datalist"
  30. :key="index">
  31. <view class="title dis a-c ">
  32. <view class="status ">{{ item.content.orderStatus }}</view>
  33. <text class="font-weight ml-1">{{ item.title }}</text>
  34. </view>
  35. <view class="order-content dis j-s a-end">
  36. <view class="dis f-c ">
  37. <view class="item mb-1">
  38. <text>车牌</text>
  39. <text class="ml-3">{{ item.content.licenseNo }}</text>
  40. </view>
  41. <view class="item">
  42. <text>保费</text>
  43. <text class="ml-3">{{ item.content.amount }}</text>
  44. </view>
  45. </view>
  46. <text class="time">{{ item.createTime }}</text>
  47. </view>
  48. </view>
  49. <!-- 佣金消息列表 -->
  50. <view class="viewitem dis f-c mb-2" v-if="pageQuery.type == '3'" v-for="(item, index) in datalist"
  51. :key="index">
  52. <view class="title dis a-c ">
  53. <image src="/static/icon/message/commission.png" mode=""></image>
  54. <text class="font-weight ml-1">订单佣金到账</text>
  55. </view>
  56. <view class="commission-content dis f-wrap a-end j-s">
  57. <view class="item mb-1">
  58. <text>手续费</text>
  59. <text>+ 236.20元</text>
  60. </view>
  61. <view class="item mb-1">
  62. <text>跟单费</text>
  63. <text>+ 236.20元</text>
  64. </view>
  65. <view class="item">
  66. <text>出单积分</text>
  67. <text style="margin-left: 30rpx;">+ 263</text>
  68. </view>
  69. <text class="time">2022.05.12 12:06</text>
  70. </view>
  71. </view>
  72. <!-- 增员信息列表 -->
  73. <view class="viewitem dis f-c mb-2" v-if="pageQuery.type == '0'" v-for="(item, index) in datalist"
  74. :key="index">
  75. <view class="title dis a-c ">
  76. <image src="/static/icon/message/addmember.png" mode=""></image>
  77. <text class="font-weight ml-1">订单佣金到账</text>
  78. </view>
  79. <view class="commission-content dis f-wrap a-end j-s">
  80. <view class="item mb-1">
  81. <text>姓名</text>
  82. <text>Zhangjie</text>
  83. </view>
  84. <view class="item mb-1">
  85. <text>手机号</text>
  86. <text style="margin-left: 30rpx;">18335592986</text>
  87. </view>
  88. <view class="item">
  89. <text>推荐人</text>
  90. <text style="margin-left: 30rpx;">Zhangjie</text>
  91. </view>
  92. <text class="time">2022.05.12 12:06</text>
  93. </view>
  94. </view>
  95. </view>
  96. <u-loadmore v-if="datalist.length!=0" :status="status" />
  97. <u-popup :show="qrcodePopup" mode="center" round="20rpx" closeable mask-close-able @close="qrcodePopup = false">
  98. <div class="popup-content">
  99. <image :src="qrcode" style="width:400rpx;height:400rpx" mode=""></image>
  100. <div class="text">请截图扫码后进行抽奖</div>
  101. </div>
  102. </u-popup>
  103. </view>
  104. </template>
  105. <script>
  106. export default {
  107. data() {
  108. return {
  109. status: 'loadmore',
  110. tabViewList: [{
  111. sum: 0,
  112. text: '系统信息',
  113. image: "/static/icon/message/tab-message.png",
  114. type: "1",
  115. }, {
  116. sum: 0,
  117. text: '订单进度',
  118. image: "/static/icon/message/tab-order.png",
  119. type: "2",
  120. }, {
  121. sum: 0,
  122. text: '佣金消息',
  123. image: "/static/icon/message/tab-commission.png",
  124. type: "3",
  125. }, {
  126. sum: 0,
  127. text: '增员信息',
  128. image: "/static/icon/message/tab-addmember.png",
  129. type: '0',
  130. }],
  131. pageQuery: {
  132. type: '1',
  133. pages: 1,
  134. size: 20,
  135. },
  136. totalPages: 0, //数据总页数
  137. datalist: [], //消息数据列表
  138. qrcodePopup: false, //二维码弹窗
  139. qrcode: '', //二维码
  140. }
  141. },
  142. onShow() {
  143. this.getmessage();
  144. this.getMessageCount();
  145. },
  146. onLoad() { },
  147. onReachBottom() {
  148. this.loadNextPage(); //触底加载(加载中/没有更多时内部自动忽略)
  149. },
  150. computed: {
  151. },
  152. methods: {
  153. // 加载下一页(触底与自动补屏共用)
  154. loadNextPage() {
  155. if (this.status == 'loading' || this.status == 'nomore') return; //加载中/没有更多:忽略
  156. this.status = 'loading';
  157. this.pageQuery.pages = this.pageQuery.pages + 1;
  158. setTimeout(async () => {
  159. let res = await this.$http.post('/message/messageList', this.pageQuery);
  160. if (res.code == '200') {
  161. this.datalist = [...this.datalist, ...res.data.records];
  162. this.totalPages = res.data.pages; //以接口返回的总页数为准
  163. if (this.pageQuery.pages >= this.totalPages) this.status = 'nomore';
  164. else this.status = 'loadmore'; //还有下一页:回到"加载更多"
  165. this.autoLoadMore(); //追加后若仍不满一屏,继续自动补页
  166. } else {
  167. this.status = 'loadmore'; //请求失败:回到"加载更多",允许重试
  168. }
  169. }, 1000)
  170. },
  171. // 列表内容不满一屏时自动加载,直到占满或没有更多(消息少于一屏时触底事件不会触发)
  172. autoLoadMore() {
  173. this.$nextTick(() => {
  174. uni.createSelectorQuery().in(this)
  175. .select('.content').boundingClientRect()
  176. .selectViewport().boundingClientRect()
  177. .exec((res) => {
  178. if (!res || !res[0] || !res[1]) return;
  179. // 内容底部已超出可视区底部:已占满一屏,无需补页
  180. if (res[0].bottom >= res[1].height) return;
  181. // 没有更多数据:直接置为"没有更多"
  182. if (this.pageQuery.pages >= this.totalPages) {
  183. if (this.datalist.length > 0) this.status = 'nomore';
  184. return;
  185. }
  186. // 还有数据:自动翻页(loadNextPage 成功后还会再次检查)
  187. this.loadNextPage();
  188. });
  189. });
  190. },
  191. //获取未读数量
  192. async getMessageCount() {
  193. let res = await this.$http.get('/message/getMessageCount')
  194. if (res.code == 200) {
  195. this.tabViewList.map(item => {
  196. if (res.data.hasOwnProperty(Number(item.type))) {
  197. item.sum = res.data[Number(item.type)];
  198. }
  199. return item;
  200. });
  201. uni.setTabBarBadge({
  202. index: 2,//tabbar的索引
  203. text: res.data['999'] + ''
  204. })
  205. }
  206. },
  207. //获取信息
  208. async getmessage() {
  209. this.pageQuery.pages = 1; //每次重新查询都从第一页开始
  210. this.status = 'loadmore'; //重置加载状态
  211. let res = await this.$http.post('/message/messageList', this.pageQuery)
  212. if (res.code == 200) {
  213. res.data.records.map(val => {
  214. const obj = JSON.parse(val.content);
  215. if (['template_13'].includes(val.tplCode)) {
  216. val.content = obj.message
  217. val.activityId = obj.eventId
  218. val.localActivityTableId = obj.localActivityTableId
  219. }
  220. if (['template_14'].includes(val.tplCode)) {
  221. val.content = obj.message
  222. val.qrcode = obj.qrcode
  223. }
  224. return val;
  225. })
  226. this.datalist = res.data.records;
  227. this.totalPages = res.data.pages; //总页数
  228. this.autoLoadMore(); //数据不满一屏时自动补页/置为"没有更多"
  229. }
  230. },
  231. //
  232. detailClick(item) {
  233. if (item.tplCode === 'template_13') {
  234. uni.navigateTo({
  235. url: '/pages/lottery/index?activityId=' + item.activityId + '&localActivityTableId=' + item.localActivityTableId,
  236. })
  237. }
  238. if (item.tplCode === 'template_14') {
  239. this.qrcodePopup = true
  240. this.qrcode = item.qrcode
  241. }
  242. },
  243. //设置已读
  244. async markAsRead(type) {
  245. let res = await this.$http.post('/message/readEdit', {
  246. type: type
  247. })
  248. },
  249. //切换消息
  250. tabClick(item) {
  251. this.pageQuery.type = item.type;
  252. this.pageQuery.pages = 1;
  253. this.pageQuery.size = 20;
  254. this.getmessage();
  255. //未读消息>0,设置已读
  256. if (item.sum > 0) {
  257. this.markAsRead(item.type)
  258. }
  259. this.getMessageCount();
  260. },
  261. }
  262. }
  263. </script>
  264. <style lang="scss" scoped>
  265. page {
  266. background-color: #f8f8f8;
  267. }
  268. .page {
  269. background-color: #f8f8f8;
  270. padding-bottom: 20rpx;
  271. box-sizing: border-box;
  272. }
  273. .tabView {
  274. width: 100%;
  275. background-color: #fff;
  276. padding: 25rpx 22rpx 20rpx;
  277. box-sizing: border-box;
  278. display: grid;
  279. grid-template-columns: repeat(4, 1fr);
  280. grid-template-rows: auto;
  281. .item {
  282. font-size: 30rpx;
  283. color: #333;
  284. .iconImage {
  285. position: relative;
  286. image {
  287. width: 120rpx;
  288. height: 120rpx;
  289. }
  290. // 徽标数
  291. .badge {
  292. position: absolute;
  293. top: 14rpx;
  294. right: 14rpx;
  295. width: 28rpx;
  296. height: 28rpx;
  297. background: #FF4545;
  298. border-radius: 50%;
  299. font-size: 18rpx;
  300. color: #fff;
  301. line-height: 1;
  302. }
  303. }
  304. }
  305. }
  306. .content {
  307. padding: 20rpx;
  308. box-sizing: border-box;
  309. .viewitem {
  310. width: 100%;
  311. background: #FFFFFF;
  312. padding: 25rpx 30rpx 30rpx;
  313. box-sizing: border-box;
  314. border-radius: 10rpx 10rpx 10rpx 10rpx;
  315. .title {
  316. image {
  317. width: 48rpx;
  318. height: 48rpx;
  319. }
  320. .status {
  321. padding: 5rpx 11rpx;
  322. box-sizing: border-box;
  323. background: linear-gradient(270deg, #FDE935 0%, #F1FF91 100%);
  324. border-radius: 20rpx 20rpx 0rpx 20rpx;
  325. font-size: 22rpx;
  326. color: #1F1F1F;
  327. font-weight: bold;
  328. text-align: center;
  329. }
  330. .time {
  331. font-size: 20rpx;
  332. color: #999;
  333. margin-left: auto;
  334. }
  335. font-size: 32rpx;
  336. color: #333;
  337. font-family: PingFang SC,
  338. PingFang SC;
  339. margin-bottom: 20rpx;
  340. }
  341. .message-content {
  342. font-size: 28rpx;
  343. color: #666;
  344. }
  345. .order-content {
  346. .item {
  347. font-size: 28rpx;
  348. text:first-child {
  349. color: #999;
  350. }
  351. text:last-child {
  352. color: #333;
  353. }
  354. }
  355. .time {
  356. font-size: 20rpx;
  357. color: #999;
  358. }
  359. }
  360. .commission-content {
  361. .item {
  362. width: 50%;
  363. font-size: 28rpx;
  364. text:first-child {
  365. color: #999;
  366. }
  367. text:last-child {
  368. color: #333;
  369. margin-left: 58rpx;
  370. }
  371. }
  372. .time {
  373. font-size: 20rpx;
  374. color: #999;
  375. }
  376. }
  377. }
  378. }
  379. .popup-content {
  380. width: 500rpx;
  381. padding: 40rpx;
  382. border-radius: 20rpx;
  383. background-color: #fff;
  384. display: flex;
  385. flex-direction: column;
  386. align-items: center;
  387. .text {
  388. margin-top: 20rpx;
  389. }
  390. }
  391. </style>