index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 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-if="ifEmpty" 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. ifEmpty: false
  48. }
  49. },
  50. onLoad() {
  51. this.loadData();
  52. },
  53. methods: {
  54. loadData(){
  55. uni.showLoading({
  56. mask: true,
  57. title:'加载中...'
  58. })
  59. NET.request(API.FindCategoryListByDepth, {
  60. classifyId: "",
  61. }, 'GET').then(res => {
  62. this.flist = res.data
  63. this.currentId = this.flist[0].classifyId
  64. uni.hideLoading()
  65. this.getChildCategory()
  66. }).catch(res => {
  67. uni.hideLoading()
  68. })
  69. },
  70. getChildCategory(){
  71. uni.showLoading({
  72. mask: true,
  73. title:'加载中...'
  74. })
  75. NET.request(API.FindCategoryListByDepth,{
  76. classifyId:this.currentId
  77. },'GET').then(res => {
  78. uni.hideLoading()
  79. this.slist = res.data
  80. if (this.slist.length === 0) {
  81. this.ifEmpty = true
  82. }
  83. }).catch(res => {
  84. uni.hideLoading()
  85. })
  86. },
  87. //一级分类点击
  88. tabtap(item,index){
  89. if(this.currentIndex == index){
  90. return;
  91. }
  92. this.currentId = item.classifyId;
  93. this.currentIndex = index
  94. this.getChildCategory()
  95. },
  96. //右侧栏滚动
  97. asideScroll(e){
  98. if(!this.sizeCalcState){
  99. this.calcSize();
  100. }
  101. let scrollTop = e.detail.scrollTop;
  102. let tabs = this.slist.filter(item=>item.top <= scrollTop).reverse();
  103. if(tabs.length > 0){
  104. this.currentId = tabs[0].pid;
  105. }
  106. },
  107. //计算右侧栏每个tab的高度等信息
  108. calcSize(){
  109. let h = 0;
  110. this.slist.forEach(item=>{
  111. let view = uni.createSelectorQuery().select("#main-" + item.id);
  112. view.fields({
  113. size: true
  114. }, data => {
  115. item.top = h;
  116. h += data.height;
  117. item.bottom = h;
  118. }).exec();
  119. })
  120. this.sizeCalcState = true;
  121. },
  122. navToList(sid, tid){
  123. uni.navigateTo({
  124. url: `../../../pages_category_page1/goodsModule/goodsList?category3Id=${tid}`
  125. })
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang='scss'>
  131. page,
  132. .content {
  133. height: 100%;
  134. /* background-color: #f8f8f8; */
  135. }
  136. .header{
  137. border-bottom: 1px solid #F3F4F5FF;
  138. }
  139. .logo {
  140. width: 280rpx;
  141. height: 42rpx;
  142. }
  143. .content {
  144. display: flex;
  145. }
  146. .left-aside {
  147. flex-shrink: 0;
  148. width: 200upx;
  149. height: 100vh;
  150. background-color: #F8F8F8;
  151. }
  152. .f-item {
  153. display: flex;
  154. align-items: center;
  155. justify-content: center;
  156. width: 100%;
  157. height: 100upx;
  158. font-size: 28upx;
  159. color: $font-color-base;
  160. position: relative;
  161. &.active{
  162. color: $base-color;
  163. background: #FFFFFF;
  164. }
  165. }
  166. .right-aside{
  167. flex: 1;
  168. padding: 20upx 0 20upx 0;
  169. background: #fff;
  170. height: 100vh;
  171. }
  172. .s-item{
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. height: 70upx;
  177. padding-top: 8upx;
  178. font-size: 28upx;
  179. color: $font-color-dark;
  180. }
  181. .t-list{
  182. display: flex;
  183. flex-wrap: wrap;
  184. width: 100%;
  185. background: #fff;
  186. padding-top: 12upx;
  187. &:after{
  188. content: '';
  189. flex: 99;
  190. height: 0;
  191. }
  192. }
  193. .t-item{
  194. flex-shrink: 0;
  195. display: flex;
  196. justify-content: center;
  197. align-items: center;
  198. flex-direction: column;
  199. width: 176upx;
  200. font-size: 26upx;
  201. color: #666;
  202. padding-bottom: 20upx;
  203. image{
  204. width: 140upx;
  205. height: 140upx;
  206. }
  207. }
  208. .emptyOrder-box{
  209. margin-left: 180upx;
  210. .emptyOrder-img{
  211. margin-top: -130upx;
  212. width: 113upx;
  213. height: 98upx;
  214. }
  215. }
  216. .classBox {
  217. image {
  218. width: 66rpx;
  219. height: 4rpx;
  220. margin-top: 10rpx;
  221. }
  222. .s-item {
  223. margin: 0 10rpx;
  224. }
  225. }
  226. </style>