discovery - 副本 (2).vue 6.9 KB

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