index.vue 8.4 KB

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