notice.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <view class="content">
  3. <view class="navbar">
  4. <view v-for="(item, index) in navList" :key="index" class="nav-item"
  5. :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">
  6. <text>{{ item.text }}</text>
  7. <text class="margin-l-10" v-if="item.count>0">({{item.count}})</text>
  8. </view>
  9. </view>
  10. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  11. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  12. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  13. <!-- 空白页 -->
  14. <!-- #ifdef H5 -->
  15. <empty src="../../static/error/emptyNotice.png"
  16. v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  17. <!-- #endif -->
  18. <!-- #ifndef H5 -->
  19. <empty src="../static/error/emptyNotice.png"
  20. v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  21. <!-- #endif -->
  22. <!-- 订单列表 -->
  23. <view class="itemBox" v-for="(item,index) in tabItem.orderList">
  24. <view class="time">
  25. {{item.add_time}}
  26. </view>
  27. <view @click="
  28. tabItem.state==1
  29. ?
  30. navTo('/pages/index/noticeDetail?id='+item.id+'&type=1',item)
  31. :
  32. navTo('/pages/index/noticeDetail?id='+item.id+'&type=2',item)
  33. " class="itemDetail" :class="{wargin:tabItem.state==2,base:tabItem.state==1}">
  34. <view class="typeName" :class="{gray:item.is_read==1}">
  35. {{item.title}}
  36. </view>
  37. <view class="detail" :class="{gray:item.is_read==1}">
  38. {{item.synopsis}}
  39. </view>
  40. </view>
  41. </view>
  42. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  43. </scroll-view>
  44. </swiper-item>
  45. </swiper>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. articleList,
  51. notify,
  52. notify_read
  53. } from '@/api/index.js';
  54. export default {
  55. data() {
  56. return {
  57. tabCurrentIndex: 0,
  58. navList: [{
  59. state: 1,
  60. text: '通知',
  61. loadingType: 'more',
  62. orderList: [],
  63. page: 1, //当前页数
  64. limit: 10, //每次信息条数
  65. count: 0, //总消息条数
  66. },
  67. {
  68. state: 2,
  69. text: '警报',
  70. loadingType: 'more',
  71. orderList: [],
  72. page: 1, //当前页数
  73. limit: 10, //每次信息条数
  74. count: 0, //总消息条数
  75. }
  76. ]
  77. };
  78. },
  79. onLoad(options) {
  80. this.initNum();
  81. this.loadData();
  82. },
  83. methods: {
  84. // 初始化查询数量
  85. initNum() {
  86. notify().then((e) => {
  87. this.navList[1].count = e.data.not_read_count;
  88. })
  89. },
  90. navTo(url, item) {
  91. let data = {
  92. url: url,
  93. }
  94. // 判断是否为报警信息
  95. if (item.type==2) {
  96. // 判断是否已读
  97. notify_read({
  98. id: item.id
  99. })
  100. data.success = function(res) {
  101. // 通过eventChannel向被打开页面传送数据
  102. res.eventChannel.emit('addPushData', item)
  103. }
  104. }
  105. if (item.is_read != 1) {
  106. this.navList[item.type-1].count--
  107. }
  108. console.log(this.navList[item.type-1]);
  109. // 设置为已读
  110. item.is_read = 1
  111. uni.navigateTo(data)
  112. },
  113. // 转换金额为数字
  114. moneyNum(value) {
  115. return +value;
  116. },
  117. // 确认收货
  118. //获取订单列表
  119. loadData(source) {
  120. const that = this;
  121. //这里是将订单挂载到tab列表下
  122. let index = this.tabCurrentIndex;
  123. let navItem = this.navList[index];
  124. let state = navItem.state;
  125. console.log(navItem, '数据');
  126. if (source === 'tabChange' && navItem.loaded === true) {
  127. //tab切换只有第一次需要加载数据
  128. return;
  129. }
  130. if (navItem.loadingType === 'loading') {
  131. //防止重复加载
  132. return;
  133. }
  134. if (navItem.loadingType === 'noMore') {
  135. //防止重复加载
  136. return;
  137. }
  138. // 修改当前对象状态为加载中
  139. navItem.loadingType = 'loading';
  140. // 判断是否为消息通知
  141. if (state == 1) {
  142. articleList({
  143. page: navItem.page,
  144. limit: navItem.limit
  145. }, 1)
  146. .then(({
  147. data
  148. }) => {
  149. data.data = data.data.map((e) => {
  150. e.is_read = +e.is_read;
  151. e.type=1
  152. return e
  153. })
  154. that.callback(data, navItem)
  155. })
  156. .catch(e => {
  157. console.log(e);
  158. });
  159. }
  160. // 判断是否为警报
  161. if (state == 2) {
  162. notify({
  163. page: navItem.page,
  164. limit: navItem.limit
  165. })
  166. .then(({
  167. data
  168. }) => {
  169. data.data = data.data.map((e) => {
  170. const detail = {
  171. title: e.content,
  172. synopsis: e.address,
  173. longitude: e.longitude,
  174. latitude: e.latitude,
  175. address: e.address,
  176. is_read: +e.is_read,
  177. id: e.id,
  178. add_time: e.add_time,
  179. type:2
  180. }
  181. return detail
  182. })
  183. that.callback(data, navItem)
  184. })
  185. .catch(e => {
  186. console.log(e);
  187. });
  188. }
  189. },
  190. // 回调数据处理
  191. callback(data, navItem) {
  192. navItem.count = data.not_read_count;
  193. let arr = data.data
  194. navItem.orderList = navItem.orderList.concat(arr);
  195. // console.log(navItem.orderList);
  196. navItem.page++;
  197. if (navItem.limit == arr.length) {
  198. //判断是否还有数据, 有改为 more, 没有改为noMore
  199. navItem.loadingType = 'more';
  200. return;
  201. } else {
  202. //判断是否还有数据, 有改为 more, 没有改为noMore
  203. navItem.loadingType = 'noMore';
  204. }
  205. uni.hideLoading();
  206. this.$set(navItem, 'loaded', true);
  207. },
  208. //swiper 切换
  209. changeTab(e) {
  210. this.tabCurrentIndex = e.target.current;
  211. this.loadData('tabChange');
  212. },
  213. //顶部tab点击
  214. tabClick(index) {
  215. this.tabCurrentIndex = index;
  216. },
  217. }
  218. };
  219. </script>
  220. <style lang="scss">
  221. page,
  222. .content {
  223. background: $page-color-base;
  224. height: 100%;
  225. }
  226. .swiper-box {
  227. height: calc(100% - 40px);
  228. }
  229. .tab-content {
  230. height: 100%;
  231. }
  232. .list-scroll-content {
  233. height: 100%;
  234. }
  235. .itemBox {
  236. padding: 50rpx 30rpx 0;
  237. .time {
  238. margin: 0 auto;
  239. width: 360rpx;
  240. background-color: $font-color-disabled;
  241. height: 48rpx;
  242. color: #FFFFFF;
  243. text-align: center;
  244. line-height: 48rpx;
  245. margin-bottom: 30rpx;
  246. border-radius: 10rpx;
  247. font-size: 24rpx;
  248. }
  249. .itemDetail {
  250. padding: 50rpx;
  251. background-color: #FFFFFF;
  252. border-radius: 20rpx;
  253. &.base {
  254. color: $font-color-base;
  255. }
  256. &.wargin {
  257. color: $color-red;
  258. }
  259. .typeName {
  260. font-size: 28rpx;
  261. &.gray {
  262. color: $color-gray !important;
  263. }
  264. }
  265. .detail {
  266. font-size: 24rpx;
  267. &.gray {
  268. color: $color-gray !important;
  269. }
  270. }
  271. }
  272. }
  273. .navbar {
  274. display: flex;
  275. height: 40px;
  276. padding: 0 5px;
  277. background: #fff;
  278. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  279. position: relative;
  280. z-index: 10;
  281. .nav-item {
  282. flex: 1;
  283. display: flex;
  284. justify-content: center;
  285. align-items: center;
  286. height: 100%;
  287. font-size: 15px;
  288. color: $font-color-dark;
  289. position: relative;
  290. &.current {
  291. color: $base-color;
  292. &:after {
  293. content: '';
  294. position: absolute;
  295. left: 50%;
  296. bottom: 0;
  297. transform: translateX(-50%);
  298. width: 44px;
  299. height: 0;
  300. border-bottom: 2px solid $base-color;
  301. }
  302. }
  303. }
  304. }
  305. </style>