discovery.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="">
  3. <navbar :config="config" backColor="#999999"></navbar>
  4. <view class="tabs-box" :style="{'top':navHeight + 'px' , 'height':tabsHeight+'rpx','paddingBottom':'30rpx'}">
  5. <!-- <view class="tab-item" v-for="item in tabs" @click.stop="onChange(item)">
  6. {{ item}}
  7. </view> -->
  8. <u-tabs style="width: 100%;" :list="tabs" active-color="#3CBACF" bg-color="transparent" height="80"
  9. is-scroll :current="tabIndex" @change="onChange"></u-tabs>
  10. </view>
  11. <view class="" :style="{'width':'100%', 'height': tabsHeight + 'rpx' }" />
  12. <view class="fx-kong-kim" v-if="tabIndex === 0 && KongKim && KongKim.length > 0">
  13. <block v-for="(item , index) in KongKim">
  14. <view class="kong-kim" :style="{backgroundImage: `url(${item.icon})` }" :key="`fx_KongKim_${index}`"
  15. @click.stop=" $openPage(item)">
  16. {{item.name}}
  17. </view>
  18. </block>
  19. </view>
  20. <view class="card-box">
  21. <!-- <zw-waterfall :list="tabs[0].list || []"></zw-waterfall> -->
  22. <template v-if="tabs && tabs.length > 0">
  23. <block v-for="(t , i ) in tabs">
  24. <u-waterfall v-show="tabIndex === i" v-model="tabs[i].list">
  25. <template v-slot:left="{leftList}">
  26. <view class="card-left-item" v-for="(item, index) in leftList" :key="`left_${index}`">
  27. <discovery :data-val="item" />
  28. </view>
  29. </template>
  30. <template v-slot:right="{rightList}">
  31. <view class="card-right-item" v-for="(item, index) in rightList" :key="`right_${index}`">
  32. <discovery :data-val="item" />
  33. </view>
  34. </template>
  35. </u-waterfall>
  36. </block>
  37. </template>
  38. </view>
  39. <loadMore v-if="tabs[tabIndex].list.length > 0 || tabs[tabIndex].loadingStatus === 'loading' "
  40. :status="tabs[tabIndex].loadingStatus">
  41. </loadMore>
  42. <view class="empty-data"
  43. v-if="(!tabs[tabIndex].list || tabs[tabIndex].list.length===0) && tabs[tabIndex].loadingStatus=== 'noMore' ">
  44. <EmptyDate />
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. getAPPList,
  51. getDiscover,
  52. newsClassify,
  53. getInformationFindPage
  54. } from "@/api/government.js";
  55. let app = getApp();
  56. export default {
  57. data() {
  58. return {
  59. tabsHeight: 100,
  60. config: {
  61. back: false,
  62. title: '发现',
  63. color: 'black',
  64. backgroundColor: [1, '#fff'],
  65. statusBarFontColor: 'black'
  66. },
  67. tabs: [{
  68. list: []
  69. }],
  70. KongKim: [],
  71. allLoading: false,
  72. tabIndex: 0,
  73. dataList: [],
  74. pageSize: 10,
  75. waterfallKey: 1
  76. }
  77. },
  78. onLoad() {
  79. const {
  80. statusBarHeight,
  81. navHeight
  82. } = app.globalData;
  83. this.navHeight = statusBarHeight + navHeight + 'px';
  84. // let data = uni.getStorageSync('discoveryPage');
  85. // if (data) {
  86. // this.tabs[0].list = data.rows
  87. // }
  88. this.init()
  89. },
  90. onShow() {
  91. },
  92. onReachBottom() {
  93. if (this.tabs[this.tabIndex].loadingStatus === "more") {
  94. this.getPage(this.tabIndex);
  95. }
  96. },
  97. onPullDownRefresh() {
  98. this.init();
  99. },
  100. methods: {
  101. setKeys() {
  102. return new Date().getTime() + Math.random();
  103. },
  104. init(tag) {
  105. this.pageNum = 0;
  106. this.tabs = [{
  107. name: '推荐',
  108. list: this.tabs[0].list,
  109. pageNum: 0,
  110. key: this.setKeys(),
  111. loadingStatus: '', //more|loading|noMore
  112. }];
  113. this.tabIndex = 0;
  114. this.getKongKim();
  115. this.getLabel(tag)
  116. },
  117. getKongKim() {
  118. getAPPList(this.$keys.FX_KONGKIM).then(res => {
  119. this.KongKim = res.data || []
  120. }).catch(() => {})
  121. },
  122. getLabel(tag) {
  123. newsClassify({
  124. informationChannel: this.$keys.information_discover
  125. }).then(res => {
  126. const data = res.data || [];
  127. const tabs = data.map((el, index) => {
  128. el.name = el.informationTypeName;
  129. el.list = index == 0 ? this.tabs[0].list : [];
  130. el.pageNum = 0;
  131. el.loadingStatus = '';
  132. el.key = this.setKeys()
  133. return el;
  134. });
  135. this.tabs = this.tabs.concat(tabs);
  136. this.tabs.forEach((el, index) => {
  137. this.getPage(index)
  138. })
  139. })
  140. },
  141. getPage(tabIndex) {
  142. if (this.tabs[tabIndex].pageNum <= 0) {
  143. this.tabs[tabIndex].pageNum = 0;
  144. // this.tabs[tabIndex].list = [];
  145. this.tabs[tabIndex].loadingStatus = '';
  146. }
  147. if (this.tabs[tabIndex].loadingStatus === 'noMore' || this.tabs[tabIndex].loadingStatus === 'loading') {
  148. return
  149. };
  150. this.allLoading = true;
  151. this.$nextTick(() => {
  152. this.tabs[tabIndex].loadingStatus = 'loading';
  153. this.tabs[tabIndex].pageNum++;
  154. const parms = {
  155. pageNum: this.tabs[tabIndex].pageNum,
  156. pageSize: this.pageSize
  157. }
  158. if (this.tabs[tabIndex].hasOwnProperty('informationTypeId')) {
  159. parms.informationTypeId = this.tabs[tabIndex].informationTypeId
  160. }
  161. setTimeout(() => {
  162. getInformationFindPage(parms).then(res => {
  163. try {
  164. if (res.code === 200) {
  165. if (this.tabs[tabIndex].pageNum <= 0) {
  166. this.tabs[tabIndex].list = [];
  167. }
  168. const arr = this.tabs[tabIndex].list.concat(res.rows || []);
  169. this.$set(this.tabs[tabIndex], 'list', arr)
  170. };
  171. } catch (e) {}
  172. this.$forceUpdate()
  173. this.tabs[tabIndex].loadingStatus = this.$mUtil.pagination(res.total,
  174. this.tabs[tabIndex].pageNum, this.pageSize)
  175. }).catch(err => {
  176. this.tabs[tabIndex].pageNum--;
  177. this.tabs[tabIndex].loadingStatus = 'noMore';
  178. }).finally(() => {
  179. // this.status = 'noMore'
  180. this.allLoading = false;
  181. uni.stopPullDownRefresh();
  182. })
  183. }, 500)
  184. })
  185. },
  186. onChange(e) {
  187. this.tabIndex = e;
  188. if (this.tabs[e].pageNum >= 1) return;
  189. this.getPage(this.tabIndex);
  190. }
  191. }
  192. }
  193. </script>
  194. <style>
  195. page {
  196. background-color: #F9F9F9;
  197. padding-bottom: 30rpx;
  198. }
  199. </style>
  200. <style lang="scss" scoped>
  201. .tabs-box {
  202. width: 100%;
  203. position: fixed;
  204. left: 0;
  205. right: 0;
  206. z-index: 1;
  207. display: flex;
  208. flex-direction: row;
  209. // padding: 0 30rpx;
  210. background-color: #F9F9F9;
  211. .tab-item {
  212. // width: 104rpx;
  213. padding: 0 22rpx;
  214. height: 100%;
  215. display: flex;
  216. align-items: center;
  217. font-size: 36rpx;
  218. margin-left: 40rpx;
  219. font-size: 30rpx;
  220. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  221. font-weight: 400;
  222. color: #999999;
  223. &:first-child {
  224. margin-left: 0;
  225. position: relative;
  226. color: #3CBACF;
  227. font-family: Microsoft YaHei, Microsoft YaHei-Bold;
  228. font-weight: 700;
  229. &::before {
  230. content: '';
  231. position: absolute;
  232. left: 50%;
  233. transform: translateX(-50%);
  234. bottom: 0;
  235. right: 0;
  236. width: 50%;
  237. height: 6rpx;
  238. border-radius: 3rpx;
  239. background-color: #3CBACF;
  240. }
  241. }
  242. }
  243. }
  244. .card-box {
  245. padding: 0 20rpx;
  246. /deep/ .u-column {
  247. width: 50%;
  248. }
  249. // display: flex;
  250. // flex-direction: row;
  251. // justify-content: space-between;
  252. // align-items: stretch;
  253. // flex-wrap: wrap;
  254. .card-left-item {
  255. padding-right: 10rpx;
  256. }
  257. .card-right-item {
  258. padding-left: 10rpx;
  259. }
  260. }
  261. .fx-kong-kim {
  262. width: 100%;
  263. display: flex;
  264. align-items: stretch;
  265. flex-wrap: wrap;
  266. padding: 20rpx;
  267. .kong-kim {
  268. flex-shrink: 0;
  269. width: calc((100% - 40rpx) / 3);
  270. height: 106rpx;
  271. background-repeat: no-repeat;
  272. background-size: 100% 100%;
  273. margin: 0 20rpx 10rpx 0;
  274. display: flex;
  275. justify-content: center;
  276. align-items: center;
  277. &:nth-child(3n) {
  278. margin-right: 0;
  279. }
  280. }
  281. }
  282. </style>