海南旅游项目 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.2 KiB

  1. <template>
  2. <view>
  3. <view class="card" v-for="(item, index) in list" :key="index" @click="goDetails(item.id)">
  4. <view class="lf-row-between lf-m-b-20">
  5. <view class="lf-color-black lf-flex">
  6. <text class="hot" v-if="item.is_read == 0"></text>
  7. <text class="gray" v-else></text>
  8. <text class="lf-font-28 lf-m-l-10">收到一条新消息</text>
  9. </view>
  10. <view class="lf-color-gray lf-font-22">{{timer(item.created_at*1000) || ''}} </view>
  11. </view>
  12. <view class="lf-font-24 lf-color-555">{{item.title}}</view>
  13. </view>
  14. <!-- 加载 -->
  15. <view class="loading-more">
  16. <text v-if="list.length" :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text>
  17. <lf-nocontent v-else></lf-nocontent>
  18. </view>
  19. <!-- 回到顶部 -->
  20. <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data(){
  26. return {
  27. list: [],
  28. loadingClass: true,
  29. loadingText: '正在加载中',
  30. page: 1,
  31. isPage: false
  32. }
  33. },
  34. onLoad(){
  35. this.getMessageList()
  36. },
  37. methods: {
  38. timer(value, fmt) {
  39. if(!value) return;
  40. let newTime = new Date(value)
  41. if(!fmt){
  42. fmt = 'yyyy-MM-dd hh:mm';
  43. }
  44. if(/(y+)/.test(fmt)) {
  45. fmt = fmt.replace(RegExp.$1, (newTime.getFullYear() + '').substr(4 - RegExp.$1.length));
  46. }
  47. let o = {
  48. 'M+': newTime.getMonth() + 1,
  49. 'd+': newTime.getDate(),
  50. 'h+': newTime.getHours(),
  51. 'm+': newTime.getMinutes(),
  52. 's+': newTime.getSeconds()
  53. };
  54. function padLeftZero(str) {
  55. return ('00'+str).substr(str.length);
  56. }
  57. // 遍历这个对象
  58. for (let k in o) {
  59. if (new RegExp(`(${k})`).test(fmt)) {
  60. // console.log(`${k}`)
  61. let str = o[k] + '';
  62. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
  63. }
  64. }
  65. return fmt;
  66. },
  67. goDetails(id) {
  68. this.$url('/pages/message/detail?news_id='+id)
  69. },
  70. getMessageList() {
  71. this.$http(this.API.API_MESSAGELIST,{page: this.page}).then(res => {
  72. let isPage = res.data.next_page_url == null?false:true;
  73. this.isPage = isPage;
  74. if(!isPage){
  75. this.loadingClass = false;
  76. this.loadingText = '没有更多数据啦~';
  77. }
  78. if(this.page == 1){
  79. this.list = res.data.data;
  80. }else{
  81. this.list.push(...res.data.data);
  82. }
  83. uni.stopPullDownRefresh();
  84. console.log(this.list)
  85. }).catch(err => {
  86. })
  87. }
  88. },
  89. onReachBottom(){
  90. if(this.isPage){
  91. this.page = this.page + 1;
  92. this.getMessageList();
  93. }
  94. },
  95. onPullDownRefresh(){
  96. this.getMessageList()
  97. }
  98. }
  99. </script>
  100. <style>
  101. page{
  102. background-color: #F6F6F6;
  103. }
  104. </style>
  105. <style lang="scss" scoped="scoped">
  106. .card{
  107. margin: 0 auto;
  108. margin-top: 30rpx;
  109. width: 686rpx;
  110. height: max-content;
  111. background-color: #FFFFFF;
  112. padding: 20rpx;
  113. border-radius: 20rpx;
  114. box-sizing: border-box;
  115. .hot{
  116. display: inline-block;
  117. margin-right: 10rpx;
  118. width: 15rpx;
  119. height: 15rpx;
  120. border-radius: 50rpx;
  121. background-color: #FF0000;
  122. }
  123. .gray {
  124. display: inline-block;
  125. margin-right: 10rpx;
  126. width: 15rpx;
  127. height: 15rpx;
  128. border-radius: 50rpx;
  129. background-color: #999;
  130. }
  131. }
  132. .lf-font-22{
  133. font-size: 22rpx;
  134. }
  135. </style>