index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view>
  3. <view class="header">
  4. <image class="logo" src="https://ceres.zkthink.com//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="https://ceres.zkthink.com/static/images/classRight.png"></image>
  17. <text class="s-item">{{item.classifyName}}</text>
  18. <image class="emptyOrder-img" src="https://ceres.zkthink.com/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="https://ceres.zkthink.com/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. this.ifEmpty = false
  90. if(this.currentIndex == index){
  91. return;
  92. }
  93. this.currentId = item.classifyId;
  94. this.currentIndex = index
  95. this.getChildCategory()
  96. },
  97. //右侧栏滚动
  98. asideScroll(e){
  99. if(!this.sizeCalcState){
  100. this.calcSize();
  101. }
  102. let scrollTop = e.detail.scrollTop;
  103. let tabs = this.slist.filter(item=>item.top <= scrollTop).reverse();
  104. if(tabs.length > 0){
  105. this.currentId = tabs[0].pid;
  106. }
  107. },
  108. //计算右侧栏每个tab的高度等信息
  109. calcSize(){
  110. let h = 0;
  111. this.slist.forEach(item=>{
  112. let view = uni.createSelectorQuery().select("#main-" + item.id);
  113. view.fields({
  114. size: true
  115. }, data => {
  116. item.top = h;
  117. h += data.height;
  118. item.bottom = h;
  119. }).exec();
  120. })
  121. this.sizeCalcState = true;
  122. },
  123. navToList(sid, tid){
  124. uni.navigateTo({
  125. url: `../../../pages_category_page1/goodsModule/goodsList?category3Id=${tid}`
  126. })
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang='scss'>
  132. page,
  133. .content {
  134. height: 100%;
  135. /* background-color: #f8f8f8; */
  136. }
  137. .header{
  138. border-bottom: 1px solid #F3F4F5FF;
  139. }
  140. .logo {
  141. width: 280rpx;
  142. height: 42rpx;
  143. }
  144. .content {
  145. display: flex;
  146. }
  147. .left-aside {
  148. flex-shrink: 0;
  149. width: 200upx;
  150. height: 100vh;
  151. background-color: #F8F8F8;
  152. }
  153. .f-item {
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. width: 100%;
  158. height: 100upx;
  159. font-size: 28upx;
  160. color: $font-color-base;
  161. position: relative;
  162. &.active{
  163. color: $base-color;
  164. background: #FFFFFF;
  165. }
  166. }
  167. .right-aside{
  168. flex: 1;
  169. padding: 20upx 0 20upx 0;
  170. background: #fff;
  171. height: 100vh;
  172. }
  173. .s-item{
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. height: 70upx;
  178. padding-top: 8upx;
  179. font-size: 28upx;
  180. color: $font-color-dark;
  181. }
  182. .t-list{
  183. display: flex;
  184. flex-wrap: wrap;
  185. width: 100%;
  186. background: #fff;
  187. padding-top: 12upx;
  188. &:after{
  189. content: '';
  190. flex: 99;
  191. height: 0;
  192. }
  193. }
  194. .t-item{
  195. flex-shrink: 0;
  196. display: flex;
  197. justify-content: center;
  198. align-items: center;
  199. flex-direction: column;
  200. width: 176upx;
  201. font-size: 26upx;
  202. color: #666;
  203. padding-bottom: 20upx;
  204. image{
  205. width: 140upx;
  206. height: 140upx;
  207. }
  208. }
  209. .emptyOrder-box{
  210. margin-left: 180upx;
  211. .emptyOrder-img{
  212. margin-top: -130upx;
  213. width: 113upx;
  214. height: 98upx;
  215. }
  216. }
  217. .classBox {
  218. image {
  219. width: 66rpx;
  220. height: 4rpx;
  221. margin-top: 10rpx;
  222. }
  223. .s-item {
  224. margin: 0 10rpx;
  225. }
  226. }
  227. </style>