index.vue 4.7 KB

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