index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="clear">
  3. <view class="cleartop mb24">
  4. <view class="search flexc">
  5. <image :src="search"></image>
  6. <!-- confirm-type="search" @confirm="getConfirm" -->
  7. <input placeholder="深度清洁" v-model="text"/>
  8. <view class="btn" @click="getConfirm">搜索</view>
  9. </view>
  10. </view>
  11. <view class="talbbox">
  12. <!-- 左侧 -->
  13. <view class="tableft">
  14. <view class="flexcc">
  15. <view class="catetit">热门服务</view>
  16. </view>
  17. <scroll-view :scroll-top="scrollTop" class="cate-left" scroll-y="true" show-scrollbar="false">
  18. <view class="cate-item" :class="{act:current==index}" v-for="(item,index) in cateList"
  19. @click="menuTab(index)" :key="item.id">
  20. {{item.label}}
  21. </view>
  22. </scroll-view>
  23. </view>
  24. <!-- 右侧 -->
  25. <view class="cate-right" >
  26. <scroll-view :scroll-top="riscrollTop" :scroll-into-view="'cate'+tempCurrent" class="cate-right-scroll" scroll-y="true"
  27. show-scrollbar="false" @scroll="getCurrentHeight">
  28. <view :id="'cate'+index" v-for="(item,index) in cateList" :key="item.id" class="cate-right-item">
  29. <view class="cate-title">{{item.label}}</view>
  30. <view class="cate-list flexcw">
  31. <view class="list flexccc" v-for="(el,index) in item.children" @click="getTabFn(el)" :class="{act:ricurrent==el.id}" :key="el.id">
  32. <image :src="cbga"></image>
  33. <view class="over">保洁初体验</view>
  34. </view>
  35. </view>
  36. <!-- <view class="cate-right-txt">
  37. <text v-for="(el,index) in item.children" @click="getTabFn(el)" :class="{act:ricurrent==el.id}" :key="el.id">{{el.label}}</text>
  38. </view> -->
  39. </view>
  40. <view style="height: 30rpx;"></view>
  41. </scroll-view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. // import {getCategoryTree} from "@/api/common.js"
  48. export default {
  49. data() {
  50. return {
  51. search:require('@/work/static/clear/search.png'),
  52. cbga:require('@/static/images/home/adrbg.png'),
  53. text:'',
  54. cateList: [
  55. {label:'农、林、牧、渔业',id:0,children:[{label:'农业',id:10},{label:'林业',id:11},{label:'畜牧业',id:12},{label:'渔业',id:13},{label:'农、林、牧、渔专业及辅助 性活动',id:14},]},
  56. {label:'1工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  57. {label:'2工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  58. {label:'3工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  59. {label:'4工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  60. {label:'5工业',id:1,children:[{label:'采矿业',id:20},{label:'煤炭开采和洗选业',id:21},{label:'石油和天然气开采业',id:22},{label:'黑色金属矿采选业',id:23},{label:'有色金属矿采选业',id:24},]},
  61. ],
  62. current: 0, //当前点击项
  63. rectInfoList: [],
  64. tempCurrent: 0,
  65. ricurrent:'',
  66. categoryName:'',//选择的名字
  67. scrollTop: 0, //左侧导航栏距离顶部的位置
  68. riscrollTop:0,//右侧导航栏距离顶部的位置
  69. tabflag:false,
  70. }
  71. },
  72. onLoad(e) {
  73. // if(e.data){
  74. // var newobj=JSON.parse(decodeURIComponent(e.data));
  75. // this.ricurrent=newobj.id;
  76. // this.categoryName=newobj.name
  77. // }
  78. // this.getCasetalbFn()
  79. },
  80. mounted() {
  81. setTimeout(() => {
  82. this.getRectInfo();
  83. }, 200)
  84. },
  85. methods: {
  86. getConfirm(){
  87. },
  88. getCasetalbFn(){
  89. getCategoryTree().then(res=>{
  90. if(res.code==200){
  91. this.cateList=res.data;
  92. }
  93. })
  94. },
  95. menuTab(index){
  96. var that=this;
  97. var idx=Number(index)
  98. var top=this.rectInfoList[idx].top;
  99. this.current = idx;
  100. this.riscrollTop = top;
  101. this.tabflag=true;
  102. setTimeout(function(){
  103. that.tabflag=false;
  104. },500)
  105. },
  106. getTabFn(ite){
  107. this.$tab.navigateTo("/work/pages/clean/detail")
  108. // this.ricurrent=ite.id;
  109. // this.categoryName=ite.label
  110. },
  111. getSure(){
  112. // 带数据返回
  113. var obj={
  114. categoryName:this.categoryName,
  115. categoryId:this.ricurrent,
  116. }
  117. uni.$emit("refreshtalb",obj)
  118. uni.navigateBack({
  119. delta: 1 //返回层数,2则上上页
  120. });
  121. },
  122. // 获取与顶部之间的距离
  123. getRectInfo() {
  124. var that=this;
  125. var top = 0;
  126. var bottom = 0;
  127. var temp = 0;
  128. for (var i = 0; i < this.cateList.length; i++) {
  129. var obj={}
  130. let view = uni.createSelectorQuery().in(this).select("#cate" + i);
  131. view.fields({
  132. size: true,
  133. rect: true
  134. }, data => {
  135. top = temp;
  136. bottom = top + data.height;
  137. temp = bottom;
  138. var obj={
  139. 'top': Number(top),
  140. 'bottom': Number(bottom)
  141. }
  142. that.rectInfoList.push(obj)
  143. // console.log(top, bottom);
  144. }).exec();
  145. }
  146. },
  147. getCurrentHeight(e) {
  148. var currentHeight = e.detail.scrollTop;
  149. this.rectInfoList.forEach((item, index) => {
  150. if (currentHeight >= item.top && currentHeight <= item.bottom&&!this.tabflag) {
  151. // 当前获取的盒子高度大于top小于bottom,判定将索引传至左侧菜单导航
  152. this.current = Number(index);
  153. this.scrollTop = Number(index) * uni.upx2px(100);
  154. }
  155. })
  156. }
  157. }
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. /deep/::-webkit-scrollbar {
  162. display: none;
  163. width: 0;
  164. height: 0;
  165. }
  166. .talbbox{flex: 1;display: flex;overflow: hidden;
  167. .tableft{width: 236rpx;box-shadow: 0px 8rpx 10rpx 0px #8E8E8E;display: flex;flex-direction: column;
  168. }
  169. .catetit{font-weight: bold;font-size: 32rpx;color: #272727;position: relative;flex: 0 0 auto;
  170. &::before{content: '';position: absolute;left: 0;right: 0;bottom: 0;z-index: -1;height: 20rpx;background: linear-gradient(263deg, #5CCCFF, #5CEEB8);}
  171. }
  172. .cate-left{width: 236rpx;flex:1;overflow: auto;
  173. .cate-item{min-height: 110rpx;font-weight: 500;display: flex;align-items: center;justify-content: center;
  174. font-size: 28rpx;color: #666666;padding: 20rpx 46rpx;
  175. &.act{font-weight: bold;color: #272727;}
  176. }
  177. }
  178. .cate-right{flex: 1;height: 100%;
  179. .cate-right-scroll{height: 100%;padding-left:18rpx;padding-right: 2rpx;
  180. .cate-right-item{padding-bottom: 32rpx;
  181. .cate-title{font-weight: bold;font-size: 30rpx;color: #222327;display: flex;align-items: center;padding:4rpx 0 4rpx 30rpx;margin-bottom: 20rpx;}
  182. .cate-right-txt{display: flex;flex-wrap: wrap;
  183. // text{font-weight: 500;font-size: 26rpx;color: #666666;margin-bottom: 16rpx;padding: 8rpx 0;width: 100%;box-sizing: border-box;display: block;
  184. // &.act{color: $com-cd3;}
  185. // }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. .clear{height: 100vh;display: flex;flex-direction: column;
  192. .cleartop{padding: 16rpx 30rpx;flex: 0 0 auto;background: #ffffff;
  193. .search{flex: 1;margin-left: 16rpx;height: 64rpx;background: #EEEEEE;border-radius: 32rpx;border: 2rpx solid #E6E6E6;padding-left: 24rpx;box-sizing: border-box;
  194. image{width: 32rpx;height: 34rpx;margin-right: 22rpx;flex: 0 0 auto;}
  195. input{flex: 1;font-size: 26rpx;color: #272727;}
  196. .btn{width: 100rpx;height: 64rpx;background: #3565ED;border-radius: 32rpx;flex: 0 0 auto;font-weight: bold;text-align: center;line-height: 64rpx;font-size: 26rpx;color: #FFFFFF;}
  197. }
  198. }
  199. .cate-list{
  200. .list{margin: 0 15rpx;padding: 16rpx 0;
  201. image{width: 210rpx;height: 148rpx;margin-bottom: 16rpx;}
  202. view{font-weight: 500;font-size: 24rpx;color: #666666;}
  203. }
  204. }
  205. }
  206. </style>