index.vue 4.9 KB

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