topTab.vue 7.7 KB

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