index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  6. <view class="list-scroll-view">
  7. <view class="one_1" @tap="toNotice()"><text
  8. class="iconfont icon-a-qingchuquanbuyidu"></text>全部已读</view>
  9. <view class="list" v-for="(item,index) in list" :key="index">
  10. <uni-badge class="badge" :text="item.num" absolute="leftTop" size="normal">
  11. <view class="list_1">
  12. <view class="source">来源:<text>{{item.zhSource||'暂无'}}</text></view>
  13. <view class="content">内容:<text>{{item.content||'暂无'}}</text></view>
  14. </view>
  15. <view class="list_2">
  16. 发送时间:<text>{{item.time||'暂无'}}</text>
  17. </view>
  18. </uni-badge>
  19. </view>
  20. </view>
  21. </scroll-view>
  22. </view>
  23. </view>
  24. </mobile-frame>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. user: {},
  31. list: [],
  32. // 状态
  33. statusList: [],
  34. // 来源
  35. sourceList: [],
  36. total: 0,
  37. page: 0,
  38. skip: 0,
  39. limit: 10,
  40. };
  41. },
  42. onShow: async function(e) {
  43. const that = this;
  44. await that.searchOther();
  45. await that.watchLogin();
  46. },
  47. onPullDownRefresh: async function() {
  48. const that = this;
  49. that.clearPage();
  50. await that.search();
  51. uni.stopPullDownRefresh();
  52. },
  53. methods: {
  54. // 监听用户是否登录
  55. watchLogin() {
  56. const that = this;
  57. uni.getStorage({
  58. key: 'token',
  59. success: function(res) {
  60. let user = that.$jwt(res.data);
  61. that.$set(that, `user`, user);
  62. that.search()
  63. },
  64. fail: function(err) {
  65. uni.navigateTo({
  66. url: `/pages/login/index`
  67. })
  68. }
  69. })
  70. },
  71. // 查询列表
  72. async search() {
  73. const that = this;
  74. let info = {
  75. skip: that.skip,
  76. limit: that.limit,
  77. customer: that.user._id
  78. }
  79. const res = await that.$api(`/notice`, `GET`, {
  80. ...info,
  81. })
  82. if (res.errcode == '0') {
  83. let list = [...that.list, ...res.data];
  84. for (let val of list) {
  85. if (val.status) val.zhStatus = that.searchStatus(val.status)
  86. if (val.source) val.zhSource = that.searchSource(val.source)
  87. if (val.status != '1') val.num = 1
  88. }
  89. that.$set(that, `list`, list)
  90. that.$set(that, `total`, res.total)
  91. }
  92. },
  93. // 查询状态
  94. searchStatus(e) {
  95. const that = this;
  96. let data = that.statusList.find((i) => i.value == e);
  97. if (data) return data.label
  98. else return '暂无'
  99. },
  100. // 查询来源
  101. searchSource(e) {
  102. const that = this;
  103. let data = that.sourceList.find((i) => i.value == e);
  104. if (data) return data.label
  105. else return '暂无'
  106. },
  107. // 全部已读
  108. async toNotice() {
  109. const that = this;
  110. let list = that.list.filter((i) => i.status != '1');
  111. for (let val of list) {
  112. const res = await that.$api(`/notice/${val._id}`, `POST`, {
  113. status: '1'
  114. })
  115. if (res.errcode == '0') {
  116. that.clearPage();
  117. that.search();
  118. }
  119. }
  120. },
  121. // 查询其他信息
  122. async searchOther() {
  123. const that = this;
  124. let res;
  125. res = await that.$api(`/dictData`, 'GET', {
  126. code: "notice_status"
  127. });
  128. if (res.errcode == '0') that.$set(that, `statusList`, res.data)
  129. res = await that.$api(`/dictData`, 'GET', {
  130. code: "notice_source"
  131. });
  132. if (res.errcode == '0') that.$set(that, `sourceList`, res.data)
  133. },
  134. // 分页
  135. toPage() {
  136. const that = this;
  137. let list = that.list;
  138. let limit = that.limit;
  139. if (that.total > list.length) {
  140. uni.showLoading({
  141. title: '加载中',
  142. mask: true
  143. })
  144. let page = that.page + 1;
  145. that.$set(that, `page`, page)
  146. let skip = page * limit;
  147. that.$set(that, `skip`, skip)
  148. that.search();
  149. uni.hideLoading();
  150. } else {}
  151. },
  152. // 清空列表
  153. clearPage() {
  154. const that = this;
  155. that.$set(that, `list`, [])
  156. that.$set(that, `skip`, 0)
  157. that.$set(that, `limit`, 10)
  158. that.$set(that, `page`, 0)
  159. }
  160. },
  161. }
  162. </script>
  163. <style lang="scss">
  164. .main {
  165. .one {
  166. .one_1 {
  167. padding: 2vw;
  168. text-align: center;
  169. .iconfont {
  170. color: #707070;
  171. }
  172. color:#707070;
  173. }
  174. .list {
  175. margin: 2vw 2vw 0 2vw;
  176. padding: 2vw;
  177. border-radius: 5px;
  178. border: 1px solid #f5f5f5;
  179. .list_1 {
  180. padding: 2vw 0 0 0;
  181. font-size: 14px;
  182. text {
  183. color: var(--f85Color);
  184. }
  185. }
  186. .list_2 {
  187. font-size: 12px;
  188. text {
  189. color: var(--f85Color);
  190. }
  191. }
  192. }
  193. }
  194. }
  195. .scroll-view {
  196. position: absolute;
  197. top: 0;
  198. left: 0;
  199. right: 0;
  200. bottom: 0;
  201. .list-scroll-view {
  202. display: flex;
  203. flex-direction: column;
  204. }
  205. }
  206. </style>