index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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" :style="{'border-bottom':index==news.length-1?'1px solid #fff':'1px solid #e6e6e6'}">
  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. let that = this
  108. that.$request.baseRequest('get', '/newsInfo/unreadMessage', {
  109. reCommonId: this.userInfo.id,
  110. }).then(res3 => {
  111. if (res3.data || res3.data == 0) {
  112. let name = 'myTip';
  113. let value = res3.data
  114. if (value == 0) {
  115. uni.removeTabBarBadge({
  116. index: 3
  117. })
  118. }
  119. that.$store.commit('$uStore', {
  120. name,
  121. value
  122. });
  123. if (value != 0 && value) {
  124. uni.setTabBarBadge({
  125. index: 3,
  126. text: value + ""
  127. })
  128. }
  129. that.$forceUpdate()
  130. }
  131. })
  132. },
  133. confirmClick() {
  134. // #ifdef APP-PLUS
  135. if (this.alertTitle == '账号审核中') {
  136. if (uni.getSystemInfoSync().platform == 'ios') {
  137. plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  138. } else if (uni.getSystemInfoSync().platform == 'android') {
  139. plus.runtime.quit();
  140. }
  141. return
  142. }
  143. // #endif
  144. },
  145. rightClick() {
  146. uni.showLoading({
  147. title: '加载中',
  148. mask: true
  149. })
  150. this.$request.baseRequest('post', '/newsInfo/api/editAllNewsInfo', {
  151. reCommonId: this.userInfo.id,
  152. }).then(res => {
  153. this.mescroll.resetUpScroll()
  154. uni.hideLoading()
  155. uni.removeTabBarBadge({
  156. index: 2
  157. })
  158. this.newsNumber() //消息气泡
  159. })
  160. .catch(res => {
  161. uni.$u.toast(res.message);
  162. });
  163. },
  164. read(val) {
  165. uni.$u.route("/pages/news/newsSee?_obj=" + JSON.stringify(val))
  166. uni.showLoading({
  167. title: '加载中',
  168. mask: true
  169. })
  170. this.$request.baseRequest('post', '/newsInfo/api/editNewsInfo', {
  171. id: val.id,
  172. }).then(res => {
  173. this.mescroll.resetUpScroll()
  174. this.look()
  175. uni.hideLoading()
  176. this.newsNumber() //查询消息气泡
  177. })
  178. .catch(res => {
  179. uni.$u.toast(res.message);
  180. });
  181. },
  182. look() {
  183. let that = this
  184. that.$request.baseRequest('get', '/newsInfo/unreadMessage', {
  185. reCommonId: this.userInfo.id,
  186. }).then(res3 => {
  187. if (res3.data || res3.data == 0) {
  188. let name = 'myTip';
  189. let value = res3.data
  190. if (value == 0) {
  191. uni.removeTabBarBadge({
  192. index: 3
  193. })
  194. }
  195. that.$store.commit('$uStore', {
  196. name,
  197. value
  198. });
  199. if (value != 0 && value) {
  200. uni.setTabBarBadge({
  201. index: 3,
  202. text: value + ""
  203. })
  204. }
  205. }
  206. })
  207. },
  208. back() {
  209. uni.navigateBack({
  210. })
  211. },
  212. mescrollInit(mescroll) {
  213. this.mescroll = mescroll;
  214. },
  215. downCallback() {
  216. // 第2种: 下拉刷新和上拉加载调同样的接口, 则不用第1种, 直接mescroll.resetUpScroll()即可
  217. // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  218. this.mescroll.resetUpScroll()
  219. },
  220. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  221. upCallback(page) {
  222. console.log(page)
  223. // 此处可以继续请求其他接口
  224. if (page.num == 1) {
  225. this.news = []
  226. // 请求其他接口...
  227. }
  228. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  229. // if(!this.isInitxx){
  230. // apiGetxx().then(res=>{
  231. // this.isInitxx = true
  232. // this.mescroll.resetUpScroll() // 重新触发upCallback
  233. // }).catch(()=>{
  234. // this.mescroll.endErr()
  235. // })
  236. // return // 此处return,先获取xx
  237. // }
  238. //联网加载数据
  239. this.$request.baseRequest('get', '/newsInfo/selectNewsInfo', {
  240. reCommonId: this.userInfo.id,
  241. pageSize: page.size,
  242. currentPage: page.num,
  243. }).then(res => {
  244. if (page.num == 1) {
  245. this.news = []
  246. }
  247. this.news = this.news.concat(res.data.records); //追加新数据
  248. this.$forceUpdate()
  249. this.mescroll.endBySize(res.data.records.length, res.data.total);
  250. })
  251. .catch(res => {
  252. uni.$u.toast(res.message);
  253. });
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. /deep/.u-navbar__content__right__text {
  260. font-size: 26rpx;
  261. color: #FFFFFF;
  262. }
  263. /deep/.point1 {
  264. text-overflow: ellipsis;
  265. overflow: hidden;
  266. /* white-space: nowrap; */
  267. display: -webkit-box;
  268. -webkit-line-clamp: 3;
  269. -webkit-box-orient: vertical;
  270. text-overflow: ellipsis;
  271. }
  272. .top-bgc {
  273. position: absolute;
  274. width: 100%;
  275. height: 519rpx;
  276. // background: linear-gradient(180deg, #317AFE 0%, #F8F9FC 100%);
  277. }
  278. .content {
  279. // position: relative;
  280. // top: 0;
  281. background: #FFFFFF;
  282. margin: 20rpx;
  283. width: calc(100% - 40rpx);
  284. // padding: 20rpx;
  285. box-sizing: border-box;
  286. border-radius: 20rpx;
  287. padding-top: 30rpx;
  288. }
  289. .info-item {
  290. padding: 0 30rpx 30rpx 30rpx;
  291. .img {
  292. width: 80rpx;
  293. height: 80rpx;
  294. }
  295. .left {
  296. margin-right: 20rpx;
  297. }
  298. .right {
  299. width: 100%;
  300. border-bottom: 1px solid #E6E6E6;
  301. padding-bottom: 20rpx;
  302. .row1 {
  303. .title {
  304. font-size: 32rpx;
  305. color: #000000;
  306. }
  307. .time {
  308. font-size: 32rpx;
  309. color: #999999;
  310. }
  311. }
  312. .row2 {
  313. .text {
  314. font-size: 28rpx;
  315. color: #999999;
  316. width: 500rpx;
  317. }
  318. .red-point {
  319. width: 10rpx;
  320. height: 10rpx;
  321. background: #EE2F51;
  322. border-radius: 6rpx;
  323. margin-right: 20rpx;
  324. }
  325. }
  326. }
  327. }
  328. </style>