test4.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view class="content">
  3. <scroll-view scroll-y="true" class="nave-left" :scroll-into-view="scrollToLeft">
  4. <view class="scroll">
  5. <view class="goods-type" :class="{ isSelect: scrollToLeft === 'idx' + index }" v-for="(val, index) in items" :key="index"
  6. @click="scrollRight(index)" :id="'idx' + index">
  7. {{ val.name }}
  8. </view>
  9. </view>
  10. </scroll-view>
  11. <scroll-view scroll-y="true" class="nav-right" :scroll-into-view="scrollToRight" scroll-with-animation="" @scroll="scrolling">
  12. <view class="scroll">
  13. <view class="goods-list" v-for="(val, index) in items" :key="index" :id="'id' + index">
  14. <view class="goods-head">{{ val.name }}</view>
  15. <view class="goods-body" v-for="(item, idx) in val.children" :key="idx">{{ item.name }}</view>
  16. </view>
  17. </view>
  18. </scroll-view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'goodsSecond',
  24. data() {
  25. return {
  26. scrollToRight: '',
  27. nodeHeight: [],
  28. scrollToLeft: 'idx0',
  29. items: [{
  30. name: 'A',
  31. children: [{
  32. name: 'A1'
  33. },
  34. {
  35. name: 'A2'
  36. },
  37. {
  38. name: 'A3'
  39. },
  40. {
  41. name: 'A1'
  42. },
  43. {
  44. name: 'A2'
  45. },
  46. {
  47. name: 'A3'
  48. }
  49. ]
  50. },
  51. {
  52. name: 'B',
  53. children: [{
  54. name: 'B1'
  55. },
  56. {
  57. name: 'B2'
  58. },
  59. {
  60. name: 'B3'
  61. },
  62. {
  63. name: 'B1'
  64. },
  65. {
  66. name: 'B2'
  67. },
  68. {
  69. name: 'B3'
  70. }
  71. ]
  72. },
  73. {
  74. name: 'C',
  75. children: [{
  76. name: 'C1'
  77. },
  78. {
  79. name: 'C2'
  80. },
  81. {
  82. name: 'C3'
  83. },
  84. {
  85. name: 'C1'
  86. },
  87. {
  88. name: 'C2'
  89. },
  90. {
  91. name: 'C3'
  92. }
  93. ]
  94. }
  95. ]
  96. };
  97. },
  98. mounted() {
  99. this.getGoodsLsit();
  100. },
  101. methods: {
  102. getGoodsLsit() {
  103. let view = uni
  104. .createSelectorQuery()
  105. .in(this)
  106. .selectAll('.goods-list');
  107. view.boundingClientRect(data => {
  108. console.log('得到布局位置信息');
  109. this.nodeHeight = data;
  110. console.log(data);
  111. }).exec();
  112. },
  113. scrollRight(index) {
  114. this.scrollToRight = 'id' + index;
  115. this.scrollToLeft = 'idx' + index;
  116. },
  117. scrolling(e) {
  118. this.scrollLeft(Math.ceil(e.detail.scrollTop));
  119. console.log(e.detail);
  120. },
  121. scrollLeft(e) {
  122. for (let i = 2; i < this.nodeHeight.length; i++) {
  123. if (e > this.nodeHeight[i - 1].top && e < this.nodeHeight[i].top) {
  124. this.scrollToLeft = 'idx' + (i - 1);
  125. } else if (e > this.nodeHeight[this.nodeHeight.length - 1].top) {
  126. this.scrollToLeft = 'idx' + (this.nodeHeight.length - 1);
  127. } else if (e < this.nodeHeight[1].top) {
  128. this.scrollToLeft = 'idx0';
  129. this.scrollToRight = 'id0';
  130. }
  131. this.scrollToRight = '';
  132. }
  133. }
  134. }
  135. };
  136. </script>
  137. <style>
  138. .content {
  139. width: 100%;
  140. height: 100%;
  141. display: flex;
  142. }
  143. .nave-left {
  144. width: 187rpx;
  145. height: 100%;
  146. }
  147. .nav-right {
  148. width: 562rpx;
  149. height: 100%;
  150. }
  151. .scroll {
  152. width: 100%;
  153. height: 100%;
  154. display: flex;
  155. flex-direction: column;
  156. align-items: center;
  157. }
  158. .goods-type {
  159. width: 150rpx;
  160. height: 80rpx;
  161. box-shadow: 0px 4px 7px 1px rgba(206, 148, 5, 0.24);
  162. border-radius: 20px;
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. font-size: 24rpx;
  167. font-family: Microsoft YaHei UI;
  168. font-weight: 400;
  169. color: #a1a1a1;
  170. }
  171. .isSelect {
  172. border: 2rpx solid rgb(206, 148, 5);
  173. }
  174. .goods-list {
  175. width: 500rpx;
  176. }
  177. .goods-head {
  178. width: 500rpx;
  179. height: 80rpx;
  180. display: flex;
  181. align-items: center;
  182. }
  183. .goods-body {
  184. width: 500rpx;
  185. height: 150rpx;
  186. display: flex;
  187. align-items: center;
  188. box-shadow: 0px 4px 7px 1px rgba(206, 148, 5, 0.24);
  189. border-radius: 20px;
  190. }
  191. </style>