discovery - 副本.vue 8.5 KB

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