topTab.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <view class="content">
  3. <!-- 导航 -->
  4. <view class="nav">
  5. <view class="leftView" @click="back">
  6. <image src="../../static/mobile/backBtn.png" mode=""
  7. style="width: 22rpx; height: 40rpx; padding-left: 24rpx;"></image>
  8. </view>
  9. <view class="navTitle">{{topName}}</view>
  10. <view class="rightView">
  11. <image src="../../static/mobile/icon_search@2x.png" mode="" class="rightImg" style="margin-left: 40rpx;"
  12. @click="goSearch"></image>
  13. </view>
  14. </view>
  15. <!-- content -->
  16. <view class="top" v-if="comment.length != 0">{{comment}}</view>
  17. <!-- tab -->
  18. <view class="scrollBg" v-if="bannerArr.length != 0">
  19. <scroll-view scroll-x="true" @scroll="scroll" :class="{guding:scrollY>0}">
  20. <view class="tabBg">
  21. <view v-for="(item,index) in bannerArr" :key="index" @click="tabClick(index)">
  22. <view class="tabTitle" :class="{tabActive:tabIndex==index}">{{item.name}}</view>
  23. </view>
  24. </view>
  25. </scroll-view>
  26. </view>
  27. <!-- item -->
  28. <view class="itemBg">
  29. <view v-for="(item,index) in itemArr" :key="index" class="twoItem" :class="{line:index>0}" @click="goList(item)">
  30. <image :src="item.LogoImg" mode="" class="img2"></image>
  31. <view class="rightItem">
  32. <view class="title">{{item.Title}}</view>
  33. <view class="title2">{{item.Comment}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 上拉 加载更多 -->
  38. <view class="noMore" v-if="noMoreShow">没有更多数据</view>
  39. <!-- 无数据空白页 -->
  40. <nodata v-if="itemArr.length==0"></nodata>
  41. <view class="gotop" @click="gotoTop">
  42. <image src="../../static/pcimg/btn_top@2x.png" mode="" class="gotopImg"></image>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import nodata from '../../components/nodata/nodata.vue'
  48. export default {
  49. components: {
  50. nodata,
  51. },
  52. data() {
  53. return {
  54. topName: '',
  55. topCode: '',
  56. comment: '',
  57. page: 1,
  58. bannerArr: [],
  59. scrollTop: 0,
  60. old: {
  61. scrollTop: 0
  62. },
  63. itemArr: [],
  64. tabIndex: 0,
  65. noMoreShow: false,
  66. scrollY: '',
  67. }
  68. },
  69. onLoad(opt) {
  70. this.topName = opt.topName
  71. this.topCode = opt.topCode
  72. this.comment = opt.comment
  73. this.page = 1
  74. this.getItemData()
  75. // uni.setNavigationBarTitle({
  76. // title: this.topName
  77. // })
  78. },
  79. methods: {
  80. gotoTop() {
  81. uni.pageScrollTo({
  82. scrollTop: 0,
  83. duration: 300
  84. });
  85. },
  86. onPageScroll(e) {
  87. let that = this;
  88. if (that.scrollY > e.scrollTop) {
  89. console.log("向上滚动", e);
  90. } else {
  91. console.log("向下滚动", e);
  92. }
  93. that.scrollY = e.scrollTop;
  94. },
  95. goList(item) {
  96. // 1分类2文章
  97. if (item.Type == 1) {
  98. uni.navigateTo({
  99. url: 'list?topCode=' + item.Code + '&comment=' + item.Comment + '&topName=' + item.Name
  100. })
  101. }
  102. if (item.Type == 2) {
  103. uni.navigateTo({
  104. url: 'detail?id=' + item.ID
  105. })
  106. }
  107. },
  108. getItemData() {
  109. uni.showLoading({
  110. title: '加载中'
  111. })
  112. let parentCode;
  113. if (this.tabIndex == 0) {
  114. parentCode = this.topCode
  115. } else {
  116. parentCode = this.bannerArr[this.tabIndex].code
  117. }
  118. let url = '/trainingOpenApiV2/categoryPageData',
  119. params = {
  120. page: this.page,
  121. limit: 10,
  122. parentCode: parentCode,
  123. topCode: this.topCode
  124. }
  125. this.$http(url, params, 'GET').then(res => {
  126. uni.hideLoading();
  127. var data = res.data
  128. // 处理 undefined和null转为空白字符串
  129. for (const key in data) {
  130. data[key] = this.$praseStrEmpty(data[key])
  131. }
  132. if (this.page == 1) {
  133. this.itemArr = data.Items
  134. } else {
  135. this.itemArr = this.itemArr.concat(data.Items)
  136. }
  137. if (data.Items.length < 10) {
  138. this.noMoreShow = true
  139. } else {
  140. this.noMoreShow = false
  141. }
  142. if (this.itemArr.length == 0) {
  143. this.noMoreShow = false
  144. }
  145. this.bannerArr = data.dynamicCol
  146. let dic = {
  147. code: this.topCode,
  148. name: '全部',
  149. }
  150. if (this.bannerArr.length != 0) {
  151. this.bannerArr.splice(0, 0, dic)
  152. }
  153. })
  154. },
  155. goSearch() {
  156. uni.navigateTo({
  157. url: 'search'
  158. })
  159. },
  160. back() {
  161. uni.navigateBack({
  162. })
  163. },
  164. scroll: function(e) {
  165. console.log(e)
  166. this.old.scrollTop = e.detail.scrollTop
  167. },
  168. tabClick(num) {
  169. this.tabIndex = num;
  170. this.page = 1;
  171. this.getItemData()
  172. },
  173. // 下拉刷新 上拉加载更多
  174. onPullDownRefresh() {
  175. this.page = 1;
  176. this.getItemData()
  177. // this.getDetailData()
  178. setTimeout(function() {
  179. uni.stopPullDownRefresh();
  180. }, 1000);
  181. },
  182. onReachBottom() {
  183. this.page++;
  184. this.getItemData()
  185. }
  186. }
  187. }
  188. </script>
  189. <style scoped>
  190. .content {
  191. min-height: 100vh;
  192. background-color: #FFFFFF;
  193. padding-top: 88rpx;
  194. padding-bottom: 20rpx;
  195. }
  196. .nav {
  197. position: fixed;
  198. left: 0;
  199. top: 0;
  200. width: 100vw;
  201. height: 88rpx;
  202. background-color: #FFFFFF;
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. z-index: 999;
  207. border-bottom: #eeeeee 2rpx solid;
  208. }
  209. .navTitle {
  210. font-size: 36rpx;
  211. font-weight: bold;
  212. color: #3c3c3c;
  213. }
  214. .leftView {
  215. width: 30%;
  216. }
  217. .rightView {
  218. width: 30%;
  219. display: flex;
  220. justify-content: flex-end;
  221. padding-right: 24rpx;
  222. }
  223. .rightImg {
  224. width: 40rpx;
  225. height: 40rpx;
  226. }
  227. .top {
  228. background-color: #FFFFFF;
  229. padding: 40rpx 74rpx;
  230. color: #999999;
  231. font-size: 24rpx;
  232. text-align: center;
  233. }
  234. .scrollBg {
  235. background-color: #FFFFFF;
  236. padding: 0 24rpx;
  237. }
  238. .guding {
  239. padding: 0 24rpx;
  240. background-color: #FFFFFF;
  241. position: fixed;
  242. left: 0;
  243. top: 88rpx;
  244. z-index: 999;
  245. padding-top: 30rpx;
  246. border-top: #eeeeee 2rpx solid;
  247. }
  248. .scroll-view {
  249. white-space: nowrap;
  250. }
  251. .tabBg {
  252. display: flex;
  253. margin-top: 0;
  254. margin-bottom: 20rpx;
  255. }
  256. .tabTitle {
  257. margin-right: 40rpx;
  258. font-size: 30rpx;
  259. color: #3c3c3c;
  260. text-overflow: ellipsis;
  261. white-space: nowrap;
  262. height: 60rpx;
  263. line-height: 60rpx;
  264. }
  265. .tabActive {
  266. color: #FF4F00;
  267. }
  268. .itemBg {
  269. background-color: #FFFFFF;
  270. padding: 0 24rpx 30rpx;
  271. }
  272. .twoItem {
  273. display: flex;
  274. background-color: #FFFFFF;
  275. padding: 30rpx 0;
  276. }
  277. .line {
  278. border-top: #eeeeee 2rpx solid;
  279. }
  280. .title {
  281. font-size: 28rpx;
  282. font-weight: bold;
  283. color: #3c3c3c;
  284. /* 隐藏文字显示 ...不换行 */
  285. overflow: hidden;
  286. text-overflow: ellipsis;
  287. white-space: nowrap;
  288. }
  289. .title2 {
  290. font-size: 24rpx;
  291. color: #999999;
  292. //超过固定行数 隐藏
  293. display: -webkit-box;
  294. overflow: hidden;
  295. text-overflow: ellipsis;
  296. word-wrap: break-word;
  297. white-space: normal !important;
  298. -webkit-line-clamp: 3;
  299. -webkit-box-orient: vertical;
  300. margin: 14rpx 0;
  301. }
  302. .img2 {
  303. width: 240rpx;
  304. height: 135rpx;
  305. border-radius: 10rpx;
  306. }
  307. .rightItem {
  308. margin-left: 30rpx;
  309. width: calc(100vw - 300rpx);
  310. }
  311. .noMore {
  312. text-align: center;
  313. line-height: 50rpx;
  314. color: #999999;
  315. font-size: 28rpx;
  316. }
  317. .gotopImg {
  318. width: 100rpx;
  319. height: 100rpx;
  320. }
  321. .gotop {
  322. position: fixed;
  323. right: 15rpx;
  324. bottom: 100rpx;
  325. cursor: pointer;
  326. z-index: 99999;
  327. }
  328. </style>