index.vue 4.9 KB

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