topTab.vue 6.7 KB

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