topTab.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. if(item.linkType==1){
  104. window.location.href =item.linkUrl
  105. }else{
  106. uni.navigateTo({
  107. url: 'detail?id=' + item.ID
  108. })
  109. }
  110. /* uni.navigateTo({
  111. url: 'detail?id=' + item.ID
  112. }) */
  113. }
  114. },
  115. getItemData() {
  116. uni.showLoading({
  117. title: '加载中'
  118. })
  119. let parentCode;
  120. if (this.tabIndex == 0) {
  121. parentCode = this.topCode
  122. } else {
  123. parentCode = this.bannerArr[this.tabIndex].code
  124. }
  125. let url = '/trainingOpenApi/categoryPageData',
  126. params = {
  127. page: this.page,
  128. limit: 10,
  129. parentCode: parentCode,
  130. topCode: this.topCode
  131. }
  132. this.$http(url, params, 'GET').then(res => {
  133. uni.hideLoading();
  134. var data = res.data
  135. // 处理 undefined和null转为空白字符串
  136. for (const key in data) {
  137. data[key] = this.$praseStrEmpty(data[key])
  138. }
  139. if (this.page == 1) {
  140. this.itemArr = data.Items
  141. } else {
  142. this.itemArr = this.itemArr.concat(data.Items)
  143. }
  144. if (data.Items.length < 10) {
  145. this.noMoreShow = true
  146. } else {
  147. this.noMoreShow = false
  148. }
  149. if (this.itemArr.length == 0) {
  150. this.noMoreShow = false
  151. }
  152. this.bannerArr = data.dynamicCol
  153. let dic = {
  154. code: this.topCode,
  155. name: '全部',
  156. }
  157. if (this.bannerArr.length != 0) {
  158. this.bannerArr.splice(0, 0, dic)
  159. }
  160. })
  161. },
  162. goSearch() {
  163. uni.navigateTo({
  164. url: 'search'
  165. })
  166. },
  167. back() {
  168. uni.navigateBack({
  169. })
  170. },
  171. scroll: function(e) {
  172. console.log(e)
  173. this.old.scrollTop = e.detail.scrollTop
  174. },
  175. tabClick(num) {
  176. this.tabIndex = num;
  177. this.page = 1;
  178. this.getItemData()
  179. },
  180. // 下拉刷新 上拉加载更多
  181. onPullDownRefresh() {
  182. this.page = 1;
  183. this.getItemData()
  184. // this.getDetailData()
  185. setTimeout(function() {
  186. uni.stopPullDownRefresh();
  187. }, 1000);
  188. },
  189. onReachBottom() {
  190. this.page++;
  191. this.getItemData()
  192. }
  193. }
  194. }
  195. </script>
  196. <style scoped>
  197. .content {
  198. min-height: 100vh;
  199. background-color: #FFFFFF;
  200. padding-top: 88rpx;
  201. padding-bottom: 20rpx;
  202. }
  203. .nav {
  204. position: fixed;
  205. left: 0;
  206. top: 0;
  207. width: 100vw;
  208. height: 88rpx;
  209. background-color: #FFFFFF;
  210. display: flex;
  211. justify-content: space-between;
  212. align-items: center;
  213. z-index: 999;
  214. border-bottom: #eeeeee 2rpx solid;
  215. }
  216. .navTitle {
  217. font-size: 36rpx;
  218. font-weight: bold;
  219. color: #3c3c3c;
  220. overflow: hidden;
  221. text-overflow: ellipsis;
  222. white-space: nowrap;
  223. width: 600rpx;
  224. text-align: center;
  225. line-height: 44rpx;
  226. }
  227. .leftView {
  228. /* width: 30%; */
  229. width: 80rpx;
  230. }
  231. .rightView {
  232. /* width: 30%; */
  233. width: 80rpx;
  234. display: flex;
  235. justify-content: flex-end;
  236. padding-right: 24rpx;
  237. }
  238. .rightImg {
  239. width: 40rpx;
  240. height: 40rpx;
  241. }
  242. .top {
  243. background-color: #FFFFFF;
  244. padding: 40rpx 74rpx;
  245. color: #999999;
  246. font-size: 24rpx;
  247. text-align: center;
  248. }
  249. .scrollBg {
  250. background-color: #FFFFFF;
  251. padding: 0 24rpx;
  252. }
  253. .guding {
  254. padding: 0 24rpx;
  255. background-color: #FFFFFF;
  256. position: fixed;
  257. left: 0;
  258. top: 88rpx;
  259. z-index: 999;
  260. padding-top: 30rpx;
  261. border-top: #eeeeee 2rpx solid;
  262. }
  263. .scroll-view {
  264. white-space: nowrap;
  265. }
  266. .tabBg {
  267. display: flex;
  268. margin-top: 0;
  269. margin-bottom: 20rpx;
  270. }
  271. .tabTitle {
  272. margin-right: 40rpx;
  273. font-size: 30rpx;
  274. color: #3c3c3c;
  275. text-overflow: ellipsis;
  276. white-space: nowrap;
  277. height: 60rpx;
  278. line-height: 60rpx;
  279. }
  280. .tabActive {
  281. color: #FF4F00;
  282. }
  283. .itemBg {
  284. background-color: #FFFFFF;
  285. padding: 0 24rpx 30rpx;
  286. }
  287. .twoItem {
  288. display: flex;
  289. background-color: #FFFFFF;
  290. padding: 30rpx 0;
  291. }
  292. .line {
  293. border-top: #eeeeee 2rpx solid;
  294. }
  295. .title {
  296. font-size: 28rpx;
  297. font-weight: bold;
  298. color: #3c3c3c;
  299. /* 隐藏文字显示 ...不换行 */
  300. overflow: hidden;
  301. text-overflow: ellipsis;
  302. white-space: nowrap;
  303. }
  304. .title2 {
  305. font-size: 24rpx;
  306. color: #999999;
  307. //超过固定行数 隐藏
  308. display: -webkit-box;
  309. overflow: hidden;
  310. text-overflow: ellipsis;
  311. word-wrap: break-word;
  312. white-space: normal !important;
  313. -webkit-line-clamp: 3;
  314. -webkit-box-orient: vertical;
  315. margin: 14rpx 0;
  316. }
  317. .img2 {
  318. width: 240rpx;
  319. height: 135rpx;
  320. border-radius: 10rpx;
  321. }
  322. .rightItem {
  323. margin-left: 30rpx;
  324. width: calc(100vw - 300rpx);
  325. }
  326. .noMore {
  327. text-align: center;
  328. line-height: 50rpx;
  329. color: #999999;
  330. font-size: 28rpx;
  331. }
  332. .gotopImg {
  333. width: 100rpx;
  334. height: 100rpx;
  335. }
  336. .gotop {
  337. position: fixed;
  338. right: 15rpx;
  339. bottom: 100rpx;
  340. cursor: pointer;
  341. z-index: 99999;
  342. }
  343. </style>