index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
  3. style="background-color: #F5F6FA;">
  4. <u-navbar title="消息中心" leftIconSize='0' :bgColor="bgColor" :placeholder='true' leftIconColor="#fff"
  5. titleStyle='color:#fff' rightText='全部已读' @rightClick="rightClick">
  6. </u-navbar>
  7. <view class="top-bgc"></view>
  8. <view class="content">
  9. <view class="info-item flex" v-for="(item,index) in news" :key="index" @click="read(item)">
  10. <view class="left">
  11. <image src="@/static/images/news/cy.png" class="img" v-if="item.newsType=='承运通知'">
  12. </image>
  13. <image src="@/static/images/news/xt.png" class="img" v-else>
  14. </image>
  15. </view>
  16. <view class="right">
  17. <view class="row1 flex flex-space-between">
  18. <view class="title">
  19. {{item.newsType}}
  20. </view>
  21. <view class="time">
  22. {{item.updateDate}}
  23. </view>
  24. </view>
  25. <view class="row2 flex flex-space-between align-center">
  26. <view class="text point1">
  27. {{item.newsContent}}
  28. </view>
  29. <view class="red-point" v-if="item.newsFlag==0"></view>
  30. </view>
  31. </view>
  32. <!-- <view class="flex flex-space-between">
  33. <view class="left">
  34. <view>系统消息</view>
  35. <u-badge :isDot="true" bgColor='red' :absolute='true' :offset='badgeOffset'></u-badge>
  36. </view>
  37. <view class="">
  38. 今天 21:51
  39. </view>
  40. </view>
  41. <view class="flex flex-space-between">
  42. 您的驾驶证即将到期,请尽快到“我的-身份认证”中更新,逾期将影响运费支付。
  43. </view> -->
  44. <u-modal :show="isShowAlert" :title="alertTitle" :closeOnClickOverlay='true'
  45. :showCancelButton='showCancelButton' confirmColor='#2772FB' @confirm="confirmClick"
  46. @close="cancelClick" @cancel="cancelClick"></u-modal>
  47. </view>
  48. </view>
  49. </mescroll-body>
  50. </template>
  51. <script>
  52. var that
  53. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  54. import {
  55. mapState
  56. } from 'vuex';
  57. export default {
  58. mixins: [MescrollMixin], // 使用mixin
  59. data() {
  60. return {
  61. confirmText: '确定',
  62. showCancelButton: true,
  63. isShowAlert: false,
  64. alertTitle: '',
  65. src: 'https://cdn.uviewui.com/uview/album/1.jpg',
  66. bgColor: '#317AFE',
  67. value: 100,
  68. news: [], // 数据列表
  69. badgeOffset: [0, -5],
  70. mescroll: null
  71. }
  72. },
  73. async onLoad() {
  74. that = this
  75. // #ifdef APP-PLUS
  76. let _status = await that.$request.baseRequest('get', '/driverInfo/firstAuthentication', {
  77. driverPhone: this.userInfo.phone,
  78. }).then(res => {
  79. return res.data.authenticationStatus
  80. })
  81. // if (_status == '已禁用') {
  82. // this.isShowAlert = true
  83. // this.alertTitle == '账号审核中'
  84. // this.confirmText = '退出APP'
  85. // this.showCancelButton = false
  86. // } else {
  87. // console.log(1231233212332312312213)
  88. // }
  89. // #endif
  90. },
  91. onShow() {
  92. that.$request.baseRequest('get', '/newsInfo/unreadMessage', {
  93. reCommonId: this.userInfo.id,
  94. }).then(res3 => {
  95. if (res3.data) {
  96. let name = 'myTip';
  97. let value = res3.data
  98. if (value == 0) {
  99. uni.removeTabBarBadge({
  100. index: 2
  101. })
  102. }
  103. that.$store.commit('$uStore', {
  104. name,
  105. value
  106. });
  107. if (value != 0 && value) {
  108. uni.setTabBarBadge({
  109. index: 2,
  110. text: value + ""
  111. })
  112. }
  113. }
  114. })
  115. // this.mescroll.resetUpScroll()
  116. },
  117. computed: {
  118. ...mapState(['hasLogin', 'userInfo', 'firstAuthentication'])
  119. },
  120. methods: {
  121. confirmClick() {
  122. // #ifdef APP-PLUS
  123. if (this.alertTitle == '账号审核中') {
  124. if (uni.getSystemInfoSync().platform == 'ios') {
  125. plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  126. } else if (uni.getSystemInfoSync().platform == 'android') {
  127. plus.runtime.quit();
  128. }
  129. return
  130. }
  131. // #endif
  132. },
  133. rightClick() {
  134. uni.showLoading({
  135. title: '加载中',
  136. mask: true
  137. })
  138. this.$request.baseRequest('post', '/newsInfo/api/editAllNewsInfo', {
  139. reCommonId: this.userInfo.id,
  140. }).then(res => {
  141. this.mescroll.resetUpScroll()
  142. uni.hideLoading()
  143. uni.removeTabBarBadge({
  144. index: 2
  145. })
  146. })
  147. .catch(res => {
  148. uni.$u.toast(res.message);
  149. });
  150. },
  151. read(val) {
  152. uni.showLoading({
  153. title: '加载中',
  154. mask: true
  155. })
  156. this.$request.baseRequest('post', '/newsInfo/api/editNewsInfo', {
  157. id: val.id,
  158. }).then(res => {
  159. this.mescroll.resetUpScroll()
  160. this.look()
  161. uni.hideLoading()
  162. })
  163. .catch(res => {
  164. uni.$u.toast(res.message);
  165. });
  166. },
  167. look() {
  168. that.$request.baseRequest('get', '/newsInfo/unreadMessage', {
  169. reCommonId: this.userInfo.id,
  170. }).then(res3 => {
  171. if (res3.data || res3.data == 0) {
  172. let name = 'myTip';
  173. let value = res3.data
  174. if (value == 0) {
  175. uni.removeTabBarBadge({
  176. index: 2
  177. })
  178. }
  179. that.$store.commit('$uStore', {
  180. name,
  181. value
  182. });
  183. if (value != 0 && value) {
  184. uni.setTabBarBadge({
  185. index: 2,
  186. text: value + ""
  187. })
  188. }
  189. }
  190. })
  191. },
  192. back() {
  193. uni.navigateBack({
  194. })
  195. },
  196. mescrollInit(mescroll) {
  197. this.mescroll = mescroll;
  198. },
  199. downCallback() {
  200. // 第2种: 下拉刷新和上拉加载调同样的接口, 则不用第1种, 直接mescroll.resetUpScroll()即可
  201. // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  202. this.mescroll.resetUpScroll()
  203. },
  204. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  205. upCallback(page) {
  206. console.log(page)
  207. // 此处可以继续请求其他接口
  208. if(page.num == 1){
  209. this.news=[]
  210. // 请求其他接口...
  211. }
  212. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  213. // if(!this.isInitxx){
  214. // apiGetxx().then(res=>{
  215. // this.isInitxx = true
  216. // this.mescroll.resetUpScroll() // 重新触发upCallback
  217. // }).catch(()=>{
  218. // this.mescroll.endErr()
  219. // })
  220. // return // 此处return,先获取xx
  221. // }
  222. //联网加载数据
  223. this.$request.baseRequest('get', '/newsInfo/selectNewsInfo', {
  224. reCommonId: this.userInfo.id,
  225. pageSize: page.size,
  226. currentPage: page.num,
  227. }).then(res => {
  228. this.news = this.news.concat(res.data.records); //追加新数据
  229. this.mescroll.endBySize(res.data.records.length, res.data.total);
  230. })
  231. .catch(res => {
  232. uni.$u.toast(res.message);
  233. });
  234. }
  235. }
  236. }
  237. </script>
  238. <style lang="scss" scoped>
  239. /deep/.u-navbar__content__right__text {
  240. font-size: 26rpx;
  241. color: #FFFFFF;
  242. }
  243. /deep/.point1 {
  244. text-overflow: ellipsis;
  245. overflow: hidden;
  246. /* white-space: nowrap; */
  247. display: -webkit-box;
  248. -webkit-line-clamp: 3;
  249. -webkit-box-orient: vertical;
  250. text-overflow: ellipsis;
  251. }
  252. .top-bgc {
  253. position: absolute;
  254. width: 100%;
  255. height: 519rpx;
  256. // background: linear-gradient(180deg, #317AFE 0%, #F8F9FC 100%);
  257. }
  258. .content {
  259. // position: relative;
  260. // top: 0;
  261. background: #FFFFFF;
  262. margin: 20rpx;
  263. width: calc(100% - 40rpx);
  264. // padding: 20rpx;
  265. box-sizing: border-box;
  266. border-radius: 20rpx;
  267. padding-top: 30rpx;
  268. }
  269. .info-item {
  270. padding: 0 30rpx 30rpx 30rpx;
  271. .img {
  272. width: 80rpx;
  273. height: 80rpx;
  274. }
  275. .left {
  276. margin-right: 20rpx;
  277. }
  278. .right {
  279. width: 100%;
  280. border-bottom: 1px solid #E6E6E6;
  281. padding-bottom: 20rpx;
  282. .row1 {
  283. .title {
  284. font-size: 32rpx;
  285. color: #000000;
  286. }
  287. .time {
  288. font-size: 32rpx;
  289. color: #999999;
  290. }
  291. }
  292. .row2 {
  293. .text {
  294. font-size: 28rpx;
  295. color: #999999;
  296. width: 500rpx;
  297. }
  298. .red-point {
  299. width: 10rpx;
  300. height: 10rpx;
  301. background: #EE2F51;
  302. border-radius: 6rpx;
  303. margin-right: 20rpx;
  304. }
  305. }
  306. }
  307. }
  308. </style>