index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view>
  3. <global-loading />
  4. <view class="header">
  5. <image class="logo" src="../../../static/images/origin/logoTop.png" mode="widthFix"></image>
  6. </view>
  7. <view class="content">
  8. <!-- 分类中心 -->
  9. <scroll-view scroll-y class="left-aside">
  10. <view
  11. v-for="(item, index) in flist" :key="item.classifyId" class="f-item b-b"
  12. :class="{ active: index === currentIndex }" @click="tabtap(item, index)"
  13. >
  14. {{ item.classifyName }}
  15. </view>
  16. </scroll-view>
  17. <scroll-view scroll-with-animation scroll-y class="right-aside">
  18. <view v-for="item in slist" :key="item.classifyId" class="s-list">
  19. <view v-if="item.childs.length > 0" class="classBox flex-items-plus">
  20. <image class="emptyOrder-img" src="logoTop.pngclassRight.png"></image>
  21. <text class="s-item">{{ item.classifyName }}</text>
  22. <image class="emptyOrder-img" src="logoTop.pngclassLeft.png"></image>
  23. </view>
  24. <view class="t-list">
  25. <view
  26. v-for="titem in item.childs" :key="titem.classifyId" class="t-item"
  27. @click="navToList(item.classifyId, titem.classifyId)"
  28. >
  29. <image :src="titem.classifyImage" class="pic-img default-img"></image>
  30. <text>{{ titem.classifyName }}</text>
  31. </view>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. <view v-if="ifEmpty" class="emptyOrder-box flex-items-plus flex-column">
  36. <image class="emptyOrder-img" src="../../../static/images/origin/bgnull.png"></image>
  37. <label class="font-color-999 fs26 mar-top-30">该分类没有商品~</label>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. const NET = require('../../../utils/request')
  44. const API = require('../../../config/api')
  45. export default {
  46. data() {
  47. return {
  48. sizeCalcState: false,
  49. tabScrollTop: 0,
  50. currentIndex: 0,
  51. currentId: '',
  52. flist: [],
  53. slist: [],
  54. ifEmpty: false
  55. }
  56. },
  57. onLoad() {
  58. this.loadData()
  59. },
  60. methods: {
  61. loadData() {
  62. // uni.showLoading({
  63. // mask: true,
  64. // title:'加载中...'
  65. // })
  66. NET.request(API.FindCategoryListByDepth, {
  67. classifyId: ''
  68. }, 'GET').then((res) => {
  69. this.flist = res.data
  70. this.currentId = this.flist[0].classifyId
  71. uni.hideLoading()
  72. this.getChildCategory()
  73. })
  74. .catch((res) => {
  75. uni.hideLoading()
  76. })
  77. },
  78. getChildCategory() {
  79. // uni.showLoading({
  80. // mask: true,
  81. // title:'加载中...'
  82. // })
  83. NET.request(API.FindCategoryListByDepth, {
  84. classifyId: this.currentId
  85. }, 'GET').then((res) => {
  86. uni.hideLoading()
  87. this.slist = res.data
  88. if (this.slist.length === 0) {
  89. this.ifEmpty = true
  90. }
  91. })
  92. .catch((res) => {
  93. uni.hideLoading()
  94. })
  95. },
  96. // 一级分类点击
  97. tabtap(item, index) {
  98. this.ifEmpty = false
  99. if (this.currentIndex == index) {
  100. return
  101. }
  102. this.currentId = item.classifyId
  103. this.currentIndex = index
  104. this.getChildCategory()
  105. },
  106. // 右侧栏滚动
  107. asideScroll(e) {
  108. if (!this.sizeCalcState) {
  109. this.calcSize()
  110. }
  111. const scrollTop = e.detail.scrollTop
  112. const tabs = this.slist.filter((item) => item.top <= scrollTop).reverse()
  113. if (tabs.length > 0) {
  114. this.currentId = tabs[0].pid
  115. }
  116. },
  117. // 计算右侧栏每个tab的高度等信息
  118. calcSize() {
  119. let h = 0
  120. this.slist.forEach((item) => {
  121. const view = uni.createSelectorQuery().select('#main-' + item.id)
  122. view.fields({
  123. size: true
  124. }, (data) => {
  125. item.top = h
  126. h += data.height
  127. item.bottom = h
  128. }).exec()
  129. })
  130. this.sizeCalcState = true
  131. },
  132. navToList(sid, tid) {
  133. uni.navigateTo({
  134. url: `../../../pages_category_page1/goodsModule/goodsList?category3Id=${tid}`
  135. })
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang='scss'>
  141. page,
  142. .content {
  143. height: 100%;
  144. /* background-color: #f8f8f8; */
  145. }
  146. .header {
  147. border-bottom: 1px solid #F3F4F5FF;
  148. }
  149. .logo {
  150. width: 280rpx;
  151. height: 42rpx;
  152. }
  153. .content {
  154. display: flex;
  155. }
  156. .left-aside {
  157. flex-shrink: 0;
  158. width: 200upx;
  159. height: 100vh;
  160. background-color: #F8F8F8;
  161. }
  162. .f-item {
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. width: 100%;
  167. height: 100upx;
  168. font-size: 28upx;
  169. color: $font-color-base;
  170. position: relative;
  171. &.active {
  172. color: $base-color;
  173. background: #FFFFFF;
  174. }
  175. }
  176. .right-aside {
  177. flex: 1;
  178. padding: 20upx 0 20upx 0;
  179. background: #fff;
  180. height: 100vh;
  181. }
  182. .s-item {
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. height: 70upx;
  187. padding-top: 8upx;
  188. font-size: 28upx;
  189. color: $font-color-dark;
  190. }
  191. .t-list {
  192. display: flex;
  193. flex-wrap: wrap;
  194. width: 100%;
  195. background: #fff;
  196. padding-top: 12upx;
  197. &:after {
  198. content: '';
  199. flex: 99;
  200. height: 0;
  201. }
  202. image {
  203. width: 140rpx;
  204. height: 140rpx;
  205. }
  206. }
  207. .t-item {
  208. flex-shrink: 0;
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. flex-direction: column;
  213. width: 176upx;
  214. font-size: 26upx;
  215. color: #666;
  216. padding-bottom: 20upx;
  217. image {
  218. width: 140upx;
  219. height: 140upx;
  220. }
  221. }
  222. .emptyOrder-box {
  223. margin-left: 180upx;
  224. .emptyOrder-img {
  225. margin-top: -130upx;
  226. width: 113upx;
  227. height: 98upx;
  228. }
  229. }
  230. .classBox {
  231. image {
  232. width: 66rpx;
  233. height: 4rpx;
  234. margin-top: 10rpx;
  235. }
  236. .s-item {
  237. margin: 0 10rpx;
  238. }
  239. }
  240. </style>