talbclass.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 {getCategoryTree} from "@/api/common.js"
  30. export default {
  31. data() {
  32. return {
  33. cateList: [
  34. {label:'农、林、牧、渔业',id:0,children:[{label:'农业',id:10},{label:'林业',id:11},{label:'畜牧业',id:12},{label:'渔业',id:13},{label:'农、林、牧、渔专业及辅助 性活动',id:14},]},
  35. {label:'1工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  36. {label:'2工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  37. {label:'3工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  38. {label:'4工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  39. {label:'5工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  40. ],
  41. current: 0, //当前点击项
  42. rectInfoList: [],
  43. tempCurrent: 0,
  44. ricurrent:'',
  45. categoryName:'',//选择的名字
  46. scrollTop: 0, //左侧导航栏距离顶部的位置
  47. riscrollTop:0,//右侧导航栏距离顶部的位置
  48. }
  49. },
  50. onLoad(e) {
  51. if(e.data){
  52. var newobj=JSON.parse(decodeURIComponent(e.data));
  53. this.ricurrent=newobj.id;
  54. this.categoryName=newobj.name
  55. }
  56. this.getCasetalbFn()
  57. },
  58. mounted() {
  59. setTimeout(() => {
  60. this.getRectInfo();
  61. }, 200)
  62. },
  63. methods: {
  64. getCasetalbFn(){
  65. getCategoryTree().then(res=>{
  66. if(res.code==200){
  67. this.cateList=res.data;
  68. }
  69. })
  70. },
  71. menuTab(index){
  72. var top=this.rectInfoList[index].top;
  73. this.current = index;
  74. this.riscrollTop = top;
  75. },
  76. getTabFn(ite){
  77. this.ricurrent=ite.id;
  78. this.categoryName=ite.label
  79. },
  80. getSure(){
  81. // 带数据返回
  82. var obj={
  83. categoryName:this.categoryName,
  84. categoryId:this.ricurrent,
  85. }
  86. uni.$emit("refreshtalb",obj)
  87. uni.navigateBack({
  88. delta: 1 //返回层数,2则上上页
  89. });
  90. },
  91. // 获取与顶部之间的距离
  92. getRectInfo() {
  93. var top = 0;
  94. var bottom = 0;
  95. var temp = 0;
  96. for (var i = 0; i < this.cateList.length; i++) {
  97. let view = uni.createSelectorQuery().in(this).select("#cate" + i);
  98. view.fields({
  99. size: true,
  100. rect: true
  101. }, data => {
  102. top = temp;
  103. bottom = top + data.height;
  104. temp = bottom;
  105. this.rectInfoList[i] = {
  106. 'top': top,
  107. 'bottom': bottom
  108. }
  109. // console.log(top, bottom);
  110. }).exec();
  111. }
  112. },
  113. getCurrentHeight(e) {
  114. var currentHeight = e.detail.scrollTop;
  115. this.rectInfoList.forEach((item, index) => {
  116. if (currentHeight >= item.top && currentHeight <= item.bottom) {
  117. // 当前获取的盒子高度大于top小于bottom,判定将索引传至左侧菜单导航
  118. this.current = index;
  119. this.scrollTop = index * uni.upx2px(100);
  120. }
  121. })
  122. }
  123. }
  124. }
  125. </script>
  126. <style scoped lang="scss">
  127. /deep/::-webkit-scrollbar {
  128. display: none;
  129. width: 0;
  130. height: 0;
  131. }
  132. .talbbox{
  133. display: flex;height: 100vh;padding-bottom: 98rpx;
  134. .cate-left{width: 330rpx;flex: 0 0 auto;height: 100%;background-color: #f5f5f5;
  135. .cate-item{min-height: 110rpx;font-weight: 500;display: flex;align-items: center;justify-content: center;
  136. font-size: 28rpx;color: #666666;padding: 20rpx 46rpx;
  137. &.act{background-color: #ffffff;font-weight: bold;color: $com-cd3;}
  138. }
  139. }
  140. .cate-right{flex: 1;height: 100%;background: #ffffff;
  141. .cate-right-scroll{height: 100%;padding-left:58rpx;padding-right: 52rpx;
  142. .cate-right-item{
  143. .cate-title{font-weight: bold;font-size: 30rpx;color: #222327;min-height: 110rpx;display: flex;align-items: center;padding: 20rpx 0;}
  144. .cate-right-txt{display: flex;flex-wrap: wrap;
  145. text{font-weight: 500;font-size: 26rpx;color: #666666;margin-bottom: 16rpx;padding: 8rpx 0;width: 100%;box-sizing: border-box;display: block;
  146. &.act{color: $com-cd3;}
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. </style>