topTab.vue 7.2 KB

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