index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <view class="content">
  3. <!-- 导航 -->
  4. <view class="nav">
  5. <view class="leftView"></view>
  6. <view class="navTitle">门店学院</view>
  7. <view class="rightView">
  8. <image src="../../static/mobile/icona_fenlei@2x.png" mode="" class="rightImg" @click="goSift"></image>
  9. <image src="../../static/mobile/icon_search@2x.png" mode="" class="rightImg"
  10. style="margin-left: 40rpx;" @click="goSearch"></image>
  11. </view>
  12. </view>
  13. <!-- 推荐 -->
  14. <view class="commend" v-if="bannerArr.length != 0">
  15. <view class="top">
  16. <image src="../../static/mobile/icon_tuijian@2x.png" mode="" style="width: 28rpx; height: 28rpx;">
  17. <text class="tuijian">推荐文章</text>
  18. </image>
  19. </view>
  20. <!-- item -->
  21. <view class="scrollBg">
  22. <scroll-view scroll-x="true" @scroll="scroll">
  23. <view class="itemBg">
  24. <view v-for="(item,index) in bannerArr" :key="index" class="item" @click="goDetail(item)">
  25. <image :src="item.logoImg" mode="" class="swpImg"></image>
  26. <view class="title">{{item.title}}</view>
  27. <view class="title2" @click.stop="goTuijianTab(item)">{{item.categoryName}}</view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. </view>
  32. </view>
  33. <!-- 分类 -->
  34. <view v-for="(item,index) in itemArr" :key="index">
  35. <view class="fenleiBg">
  36. <!-- 头 -->
  37. <view class="fenTop">
  38. <view class="leftTop">
  39. <view class="tuijian">{{item.name}}</view>
  40. <view class="sum">共{{item.count}}篇文章</view>
  41. </view>
  42. <view class="rightTop">
  43. <view class="" @click="goTopTab(item)">查看全部
  44. <image src="../../static/mobile/icon_arrow@2x.png" mode=""
  45. style="width: 11rpx; height: 18rpx; margin-left: 10rpx;"></image>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- item -->
  50. <view class="itemBg">
  51. <view v-for="(item2,index2) in item.children" :key="index2" v-if="index2<2" class="twoItem" @click="goList(item2)">
  52. <image :src="item2.logoImg" mode="" class="img2"></image>
  53. <view class="title">{{item2.title}}</view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 下拉菜单 -->
  59. <view class="sift" v-show="showSift" @click="goHide()">
  60. <view class="siftItemBg">
  61. <view v-for="(item,index) in siftData" :key="index" class="siftItem">
  62. <view @click="goTopTab(item)">{{item.name}}</view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. export default {
  70. data() {
  71. return {
  72. bannerArr: [],
  73. scrollTop: 0,
  74. old: {
  75. scrollTop: 0
  76. },
  77. itemArr: [],
  78. showSift:false,
  79. siftData:[],
  80. }
  81. },
  82. onLoad() {
  83. this.getDetailData()
  84. this.getSiftData()
  85. },
  86. methods: {
  87. goHide(){
  88. this.showSift = false
  89. },
  90. goDetail(item){
  91. uni.navigateTo({
  92. url:'detail?id=' + item.id
  93. })
  94. },
  95. goTuijianTab(item){
  96. uni.navigateTo({
  97. url:'topTab?topCode=' + item.categoryCode + '&comment=' + item.comment + '&topName=' + item.categoryName
  98. })
  99. },
  100. goList(item){
  101. // 1分类2文章
  102. if (item.type == 1) {
  103. uni.navigateTo({
  104. url:'list?topCode=' + item.code + '&comment=' + item.comment + '&topName=' + item.name
  105. })
  106. }
  107. if (item.type == 2) {
  108. uni.navigateTo({
  109. url:'detail?id=' + item.id
  110. })
  111. }
  112. },
  113. goTopTab(item){
  114. this.showSift = false
  115. uni.navigateTo({
  116. url:'topTab?topCode=' + item.code + '&comment=' + item.comment + '&topName=' + item.name
  117. })
  118. },
  119. goSift(){
  120. this.showSift = !this.showSift
  121. },
  122. goSearch(){
  123. uni.navigateTo({
  124. url:'search'
  125. })
  126. },
  127. scroll: function(e) {
  128. console.log(e)
  129. this.old.scrollTop = e.detail.scrollTop
  130. },
  131. goNav(urlStr){
  132. uni.navigateTo({
  133. url:urlStr
  134. })
  135. },
  136. getDetailData() {
  137. uni.showLoading({
  138. title: '加载中'
  139. })
  140. let url = '/trainingOpenApi/indexData',
  141. params = {
  142. }
  143. this.$http(url, params, 'GET').then(res => {
  144. uni.hideLoading();
  145. var data = res.data
  146. // 处理 undefined和null转为空白字符串
  147. for (const key in data) {
  148. data[key] = this.$praseStrEmpty(data[key])
  149. }
  150. this.detailData = data
  151. this.bannerArr = this.detailData.recommendList
  152. this.itemArr = this.detailData.categoryList
  153. })
  154. },
  155. getSiftData() {
  156. uni.showLoading({
  157. title: '加载中'
  158. })
  159. let url = '/trainingOpenApi/allCategory',
  160. params = {
  161. }
  162. this.$http(url, params, 'GET').then(res => {
  163. uni.hideLoading();
  164. var data = res.data
  165. // 处理 undefined和null转为空白字符串
  166. for (const key in data) {
  167. data[key] = this.$praseStrEmpty(data[key])
  168. }
  169. this.siftData = data
  170. })
  171. },
  172. // 下拉刷新 上拉加载更多
  173. onPullDownRefresh() {
  174. // this.page = 1;
  175. // this.getItemData()
  176. this.getDetailData()
  177. setTimeout(function() {
  178. uni.stopPullDownRefresh();
  179. }, 1000);
  180. },
  181. // onReachBottom() {
  182. // this.page++;
  183. // this.getItemData()
  184. // },
  185. }
  186. }
  187. </script>
  188. <style scoped>
  189. .content {
  190. min-height: 100vh;
  191. background-color: #f4f5f7;
  192. padding-top: 88rpx;
  193. padding-bottom: 20rpx;
  194. }
  195. .nav {
  196. position: fixed;
  197. left: 0;
  198. top: 0;
  199. width: 100vw;
  200. height: 88rpx;
  201. background-color: #FFFFFF;
  202. display: flex;
  203. justify-content: space-between;
  204. align-items: center;
  205. z-index: 999;
  206. border-bottom: #eeeeee 2rpx solid;
  207. }
  208. .navTitle {
  209. font-size: 36rpx;
  210. font-weight: bold;
  211. color: #3c3c3c;
  212. }
  213. .leftView {
  214. width: 30%;
  215. }
  216. .rightView {
  217. width: 30%;
  218. display: flex;
  219. justify-content: flex-end;
  220. padding-right: 24rpx;
  221. }
  222. .rightImg {
  223. width: 40rpx;
  224. height: 40rpx;
  225. }
  226. .commend {
  227. background-color: #FFFFFF;
  228. margin: 20rpx 0;
  229. padding: 30rpx 25rpx;
  230. }
  231. .top {
  232. padding-bottom: 24rpx;
  233. }
  234. .tuijian {
  235. font-size: 32rpx;
  236. font-weight: bold;
  237. color: #3c3c3c;
  238. margin-left: 10rpx;
  239. }
  240. .scrollBg {
  241. background-color: #FFFFFF;
  242. }
  243. .scroll-view {
  244. white-space: nowrap;
  245. }
  246. .itemBg {
  247. display: flex;
  248. }
  249. .item {
  250. width: calc((100vw - 75rpx) / 2);
  251. margin-right: 25rpx;
  252. }
  253. .swpImg {
  254. border-radius: 10rpx;
  255. width: calc((100vw - 75rpx) / 2);
  256. height: 226rpx;
  257. }
  258. .title {
  259. font-size: 28rpx;
  260. font-weight: bold;
  261. color: #3c3c3c;
  262. /* 隐藏文字显示 ...不换行 */
  263. overflow: hidden;
  264. text-overflow: ellipsis;
  265. white-space: nowrap;
  266. margin: 14rpx 0;
  267. }
  268. .title2 {
  269. background: rgba(63, 144, 247, 0.1);
  270. font-size: 22rpx;
  271. color: #3F90F7;
  272. height: 36rpx;
  273. line-height: 36rpx;
  274. border-radius: 18rpx;
  275. padding: 3rpx 14rpx;
  276. width: 138rpx;
  277. margin-bottom: 10rpx;
  278. text-align: center;
  279. /* 隐藏文字显示 ...不换行 */
  280. overflow: hidden;
  281. text-overflow: ellipsis;
  282. white-space: nowrap;
  283. }
  284. .fenleiBg {
  285. background-color: #FFFFFF;
  286. margin: 20rpx 0;
  287. padding: 30rpx 25rpx;
  288. }
  289. .fenTop {
  290. padding-bottom: 24rpx;
  291. display: flex;
  292. justify-content: space-between;
  293. align-items: center;
  294. }
  295. .leftTop {
  296. display: flex;
  297. align-items: center;
  298. }
  299. .sum {
  300. font-size: 24rpx;
  301. color: #999999;
  302. margin-left: 16rpx;
  303. }
  304. .twoItem {
  305. width: calc((100vw - 75rpx) / 2);
  306. margin-right: 25rpx;
  307. }
  308. .img2 {
  309. width: calc((100vw - 75rpx) / 2);
  310. height: 226rpx;
  311. border-radius: 10rpx;
  312. }
  313. .sift{
  314. position: fixed;
  315. left: 0;
  316. top: 88rpx;
  317. width: 100vw;
  318. min-height: 100vh;
  319. background-color: rgba(0, 0, 0, 0.4);
  320. }
  321. .siftItemBg{
  322. background-color: #FFFFFF;
  323. width: 100%;
  324. height: 500rpx;
  325. overflow-y: scroll;
  326. }
  327. .siftItem{
  328. background-color: #FFFFFF;
  329. color: #333333;
  330. font-size: 30rpx;
  331. text-align: center;
  332. padding: 30rpx 0;
  333. }
  334. </style>