talbclass.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="talbbox">
  3. <!-- 左侧 -->
  4. <view>
  5. <scroll-view :scroll-top="scrollTop" class="cate-left" scroll-y="true" show-scrollbar="false">
  6. <view class="cate-item" :class="{act:current==index}" v-for="(item,index) in cateList"
  7. @click="menuTab(index)" :key="item.id">
  8. {{item.label}}
  9. </view>
  10. </scroll-view>
  11. </view>
  12. <!-- 右侧 -->
  13. <view class="cate-right">
  14. <scroll-view :scroll-top="riscrollTop" :scroll-into-view="'cate'+tempCurrent" class="cate-right-scroll" scroll-y="true"
  15. show-scrollbar="false" @scroll="getCurrentHeight">
  16. <view :id="'cate'+index" v-for="(item,index) in cateList" :key="item.id" class="cate-right-item">
  17. <view class="cate-title">{{item.label}}</view>
  18. <view class="cate-right-txt">
  19. <text v-for="(el,index) in item.children" @click="getTabFn(el)" :class="{act:ricurrent==el.id}" :key="el.id">{{el.label}}</text>
  20. </view>
  21. </view>
  22. <view style="height: 30rpx;"></view>
  23. </scroll-view>
  24. </view>
  25. <view class="fwbtns" @click="getSure">确定</view>
  26. </view>
  27. </template>
  28. <script>
  29. import {getCasetalbFn} from "@/api/mine/case.js"
  30. export default {
  31. data() {
  32. return {
  33. cateList: [],
  34. current: 0, //当前点击项
  35. rectInfoList: [],
  36. tempCurrent: 0,
  37. ricurrent:'',
  38. categoryName:'',//选择的名字
  39. scrollTop: 0, //左侧导航栏距离顶部的位置
  40. riscrollTop:0,//右侧导航栏距离顶部的位置
  41. }
  42. },
  43. onLoad(e) {
  44. if(e.data){
  45. var newobj=JSON.parse(decodeURIComponent(e.data));
  46. this.ricurrent=newobj.id;
  47. this.categoryName=newobj.name
  48. }
  49. this.getCasetalbFn()
  50. },
  51. mounted() {
  52. setTimeout(() => {
  53. this.getRectInfo();
  54. }, 200)
  55. },
  56. methods: {
  57. getCasetalbFn(){
  58. getCasetalbFn().then(res=>{
  59. if(res.code==200){
  60. this.cateList=res.data;
  61. }
  62. })
  63. },
  64. menuTab(index){
  65. var top=this.rectInfoList[index].top;
  66. this.current = index;
  67. this.riscrollTop = top;
  68. },
  69. getTabFn(ite){
  70. this.ricurrent=ite.id;
  71. this.categoryName=ite.label
  72. },
  73. getSure(){
  74. // 带数据返回
  75. var obj={
  76. categoryName:this.categoryName,
  77. categoryId:this.ricurrent,
  78. }
  79. uni.$emit("refreshtalb",obj)
  80. uni.navigateBack({
  81. delta: 1 //返回层数,2则上上页
  82. });
  83. },
  84. // 获取与顶部之间的距离
  85. getRectInfo() {
  86. var top = 0;
  87. var bottom = 0;
  88. var temp = 0;
  89. for (var i = 0; i < this.cateList.length; i++) {
  90. let view = uni.createSelectorQuery().in(this).select("#cate" + i);
  91. view.fields({
  92. size: true,
  93. rect: true
  94. }, data => {
  95. top = temp;
  96. bottom = top + data.height;
  97. temp = bottom;
  98. this.rectInfoList[i] = {
  99. 'top': top,
  100. 'bottom': bottom
  101. }
  102. // console.log(top, bottom);
  103. }).exec();
  104. }
  105. },
  106. getCurrentHeight(e) {
  107. var currentHeight = e.detail.scrollTop;
  108. this.rectInfoList.forEach((item, index) => {
  109. if (currentHeight >= item.top && currentHeight <= item.bottom) {
  110. // 当前获取的盒子高度大于top小于bottom,判定将索引传至左侧菜单导航
  111. this.current = index;
  112. this.scrollTop = index * uni.upx2px(100);
  113. }
  114. })
  115. }
  116. }
  117. }
  118. </script>
  119. <style scoped lang="scss">
  120. /deep/::-webkit-scrollbar {
  121. display: none;
  122. width: 0;
  123. height: 0;
  124. }
  125. .talbbox{
  126. display: flex;height: 100vh;padding-bottom: 98rpx;
  127. .cate-left{width: 252rpx;flex: 0 0 auto;height: 100%;background-color: #f5f5f5;
  128. .cate-item{height: 110rpx;line-height: 110rpx;text-align: center;font-weight: 500;
  129. font-size: 28rpx;color: #666666;
  130. &.act{background-color: #ffffff;font-weight: bold;color: #1D64E2;}
  131. }
  132. }
  133. .cate-right{flex: 1;height: 100%;background: #ffffff;
  134. .cate-right-scroll{height: 100%;padding-left:34rpx;
  135. .cate-right-item{
  136. .cate-title{font-weight: bold;font-size: 30rpx;color: #222327;height: 110rpx;line-height: 110rpx;}
  137. .cate-right-txt{display: flex;flex-wrap: wrap;
  138. text{font-weight: 500;font-size: 26rpx;color: #666666;min-width: 130rpx;margin-right:24rpx ;margin-bottom: 16rpx;padding: 8rpx 0;
  139. &.act{color: #1D64E2;}
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. </style>