message.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="total-page page-env-20 page-box scroll_content">
  3. <Nav :title="'消息'" :genre="1" :fixedHeight="50"></Nav>
  4. <view class="task-tabs" :style="{top:`${$tools.topHeight()}px`}">
  5. <z-tabs ref="tabs" :list="tabsList" :active-style="{color:'#10B261',fontWeight:'bold',fontSize:'30rpx'}"
  6. :bar-style="{background:'#10B261'}" :inactive-style="{fontWeight:'bold',fontSize:'28rpx'}"
  7. :current="current" :bar-animate-mode="'worm'" @change="tabsChange" />
  8. </view>
  9. <EnScroll ref="scroll" class="main" @onRefresh="onRefresh" @onScrollBottom="onScrollBottom">
  10. <view class="m-t20" v-if="list.length <=0">
  11. <Enblank :message="'暂无消息'">
  12. </Enblank>
  13. </view>
  14. <view class="m-lr20 page-env-160">
  15. <view class="row-c page-box-bg-fff m-t20 r-30 p-30 box-shadow-197" @click.stop="goToInfo(index)"
  16. v-for="(item,index) in list" :key="index">
  17. <view class="icon-box">
  18. <view class="read-dot" v-if="item.is_read === 0"></view>
  19. <image class="wh-80" :src="getLeftImg(item.type)" mode=""></image>
  20. </view>
  21. <view class="flex m-l20">
  22. <view class="row-justify-sb center flex">
  23. <text class="text-color-333 sys-weight-400 size-30"> {{item.title}}</text>
  24. <uni-icons type="right" size="18" color="#999999"></uni-icons>
  25. </view>
  26. <view class="row-justify-sb center m-t10">
  27. <text class="size-26 text-color-666"> {{item.content}}</text>
  28. <text class="size-24 text-color-999">{{item.created_date}}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </EnScroll>
  34. </view>
  35. </template>
  36. <script>
  37. // 任务列表
  38. import TaskItem from "@/common/task/task-item.vue";
  39. import {
  40. getNotices,
  41. setRead
  42. } from "@/api/news";
  43. import tools from "@/service/tools";
  44. export default {
  45. components: {
  46. TaskItem
  47. },
  48. data() {
  49. return {
  50. current: 0,
  51. tabsList: [{
  52. name: '全部(0)',
  53. is_dot: true,
  54. dot_color: 'red',
  55. disabled: false
  56. }, {
  57. name: '未读(0)',
  58. is_dot: true,
  59. dot_color: 'red',
  60. disabled: false
  61. }, {
  62. name: '已读',
  63. is_dot: false,
  64. dot_color: '',
  65. disabled: false
  66. }],
  67. leftImg: ['task-house', 'task-house', 'task-business', 'task-repayment'],
  68. iconList: ['task-audit', 'task-do', 'task-stay'],
  69. list: [],
  70. page: 1,
  71. isEnd: false,
  72. }
  73. },
  74. watch: {
  75. },
  76. mounted() {
  77. this.startNotices();
  78. },
  79. methods: {
  80. goToInfo(index) {
  81. let item = this.list[index];
  82. if (item.type === 1) {
  83. this.list[index].is_read = 1;
  84. //跳转详情
  85. uni.navigateTo({
  86. url: 'pages/notice/module/notice-info?id=' + item.id
  87. });
  88. } else {
  89. this.setRead(index);
  90. //调用已读
  91. if (item.type === 2) {
  92. if (item.relevance_id <= 0) {
  93. tools.error('任务信息异常')
  94. return false;
  95. }
  96. //任务详情
  97. uni.navigateTo({
  98. url: '/page_task/task_details/task_details?id=' + item.relevance_id
  99. });
  100. } else {
  101. //领取列表
  102. uni.navigateTo({
  103. url: '/page_task/gain_task/gain_task'
  104. });
  105. }
  106. }
  107. },
  108. setRead(index) {
  109. setRead({
  110. 'id': this.list[index].id
  111. }).then((res) => {
  112. if (res.code === 1) {
  113. this.list[index].is_read = 1;
  114. }
  115. })
  116. },
  117. startNotices() {
  118. this.list = [];
  119. this.page = 1;
  120. this.isEnd = false;
  121. this.getNotices();
  122. },
  123. getNotices() {
  124. if (this.isEnd) {
  125. return;
  126. }
  127. getNotices({
  128. 'page': this.page,
  129. 'type': this.current
  130. }).then((res) => {
  131. if (res.code === 1) {
  132. if (res.data.items.length <= 0) {
  133. this.isEnd = true;
  134. } else {
  135. this.tabsList[0].name = '全部(' + res.data.total + ')'
  136. this.tabsList[1].name = '未读(' + res.data.unreadNum + ')'
  137. res.data.items.forEach((item) => {
  138. item.is_del = false;
  139. this.list.push(item)
  140. })
  141. // this.list.push(...res.data)
  142. }
  143. ++this.page;
  144. }
  145. })
  146. },
  147. tabsChange(index) {
  148. this.current = index;
  149. },
  150. getLeftImg(index) {
  151. return `/static/img/task/${this.leftImg[index]}.png`
  152. },
  153. // 下拉刷新
  154. onRefresh() {
  155. uni.showLoading({
  156. title: '数据加载中'
  157. })
  158. this.startNotices()
  159. setTimeout(() => {
  160. // uni.showToast({
  161. // title: '加载完成',
  162. // icon: 'none'
  163. // })
  164. this.$refs.scroll.onEndPulling()
  165. }, 1000)
  166. console.log("下拉刷新");
  167. },
  168. // 滚动到底部
  169. onScrollBottom() {
  170. uni.showLoading({
  171. title: '数据加载中'
  172. })
  173. this.getNotices()
  174. setTimeout(() => {
  175. uni.showToast({
  176. title: '加载完成',
  177. icon: 'none'
  178. })
  179. }, 1000)
  180. console.log("到底部了");
  181. },
  182. },
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .icon-box {
  187. position: relative;
  188. .read-dot {
  189. width: 14rpx;
  190. height: 14rpx;
  191. border-radius: 50%;
  192. background-color: #E91919;
  193. position: absolute;
  194. top: 0rpx;
  195. right: 10rpx;
  196. }
  197. }
  198. </style>