topTab.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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" v-if="item.Type!=1" :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 = '/trainingOpenApi/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. overflow: hidden;
  214. text-overflow: ellipsis;
  215. white-space: nowrap;
  216. width: 600rpx;
  217. text-align: center;
  218. line-height: 44rpx;
  219. }
  220. .leftView {
  221. /* width: 30%; */
  222. width: 80rpx;
  223. }
  224. .rightView {
  225. /* width: 30%; */
  226. width: 80rpx;
  227. display: flex;
  228. justify-content: flex-end;
  229. padding-right: 24rpx;
  230. }
  231. .rightImg {
  232. width: 40rpx;
  233. height: 40rpx;
  234. }
  235. .top {
  236. background-color: #FFFFFF;
  237. padding: 40rpx 74rpx;
  238. color: #999999;
  239. font-size: 24rpx;
  240. text-align: center;
  241. }
  242. .scrollBg {
  243. background-color: #FFFFFF;
  244. padding: 0 24rpx;
  245. }
  246. .guding {
  247. padding: 0 24rpx;
  248. background-color: #FFFFFF;
  249. position: fixed;
  250. left: 0;
  251. top: 88rpx;
  252. z-index: 999;
  253. padding-top: 30rpx;
  254. border-top: #eeeeee 2rpx solid;
  255. }
  256. .scroll-view {
  257. white-space: nowrap;
  258. }
  259. .tabBg {
  260. display: flex;
  261. margin-top: 0;
  262. margin-bottom: 20rpx;
  263. }
  264. .tabTitle {
  265. margin-right: 40rpx;
  266. font-size: 30rpx;
  267. color: #3c3c3c;
  268. text-overflow: ellipsis;
  269. white-space: nowrap;
  270. height: 60rpx;
  271. line-height: 60rpx;
  272. }
  273. .tabActive {
  274. color: #FF4F00;
  275. }
  276. .itemBg {
  277. background-color: #FFFFFF;
  278. padding: 0 24rpx 30rpx;
  279. }
  280. .twoItem {
  281. display: flex;
  282. background-color: #FFFFFF;
  283. padding: 30rpx 0;
  284. }
  285. .line {
  286. border-top: #eeeeee 2rpx solid;
  287. }
  288. .title {
  289. font-size: 28rpx;
  290. font-weight: bold;
  291. color: #3c3c3c;
  292. /* 隐藏文字显示 ...不换行 */
  293. overflow: hidden;
  294. text-overflow: ellipsis;
  295. white-space: nowrap;
  296. }
  297. .title2 {
  298. font-size: 24rpx;
  299. color: #999999;
  300. //超过固定行数 隐藏
  301. display: -webkit-box;
  302. overflow: hidden;
  303. text-overflow: ellipsis;
  304. word-wrap: break-word;
  305. white-space: normal !important;
  306. -webkit-line-clamp: 3;
  307. -webkit-box-orient: vertical;
  308. margin: 14rpx 0;
  309. }
  310. .img2 {
  311. width: 240rpx;
  312. height: 135rpx;
  313. border-radius: 10rpx;
  314. }
  315. .rightItem {
  316. margin-left: 30rpx;
  317. width: calc(100vw - 300rpx);
  318. }
  319. .noMore {
  320. text-align: center;
  321. line-height: 50rpx;
  322. color: #999999;
  323. font-size: 28rpx;
  324. }
  325. .gotopImg {
  326. width: 100rpx;
  327. height: 100rpx;
  328. }
  329. .gotop {
  330. position: fixed;
  331. right: 15rpx;
  332. bottom: 100rpx;
  333. cursor: pointer;
  334. z-index: 99999;
  335. }
  336. </style>