goods_cate.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class='productSort'>
  3. <view class='header acea-row row-center-wrapper'>
  4. <view class='acea-row row-between-wrapper input'>
  5. <text class='iconfont icon-sousuo'></text>
  6. <input type='text' placeholder='点击搜索商品信息' @confirm="searchSubmitValue" confirm-type='search' name="search"
  7. placeholder-class='placeholder'></input>
  8. </view>
  9. </view>
  10. <view class='aside'>
  11. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""' v-for="(item,index) in productList"
  12. :key="index" @click='tap(index,"b"+index)'><text>{{item.cate_name}}</text></view>
  13. </view>
  14. <view class='conter'>
  15. <scroll-view scroll-y="true" :scroll-into-view="toView" :style='"height:"+height+"rpx;"' @scroll="scroll"
  16. scroll-with-animation='true'>
  17. <block v-for="(item,index) in productList" :key="index">
  18. <view class='listw' :id="'b'+index">
  19. <view class='title acea-row row-center-wrapper'>
  20. <view class='line'></view>
  21. <view class='name'>{{item.cate_name}}</view>
  22. <view class='line'></view>
  23. </view>
  24. <view class='list acea-row'>
  25. <block v-for="(itemn,indexn) in item.children" :key="indexn">
  26. <navigator hover-class='none' :url='"/pages/goods_list/index?sid="+itemn.id+"&title="+itemn.cate_name' class='item acea-row row-column row-middle'>
  27. <view class='picture'>
  28. <image :src='itemn.pic'></image>
  29. </view>
  30. <view class='name line1'>{{itemn.cate_name}}</view>
  31. </navigator>
  32. </block>
  33. </view>
  34. </view>
  35. </block>
  36. <view :style='"height:"+(height-300)+"rpx;"' v-if="number<15"></view>
  37. </scroll-view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. getCategoryList
  44. } from '@/api/store.js';
  45. export default {
  46. data() {
  47. return {
  48. navlist: [],
  49. productList: [],
  50. navActive: 0,
  51. number: "",
  52. height: 0,
  53. hightArr: [],
  54. toView: ""
  55. }
  56. },
  57. onLoad(options) {
  58. this.getAllCategory();
  59. },
  60. methods: {
  61. infoScroll: function() {
  62. let that = this;
  63. let len = that.productList.length;
  64. this.number = that.productList[len - 1].children.length;
  65. //设置商品列表高度
  66. uni.getSystemInfo({
  67. success: function(res) {
  68. that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
  69. },
  70. });
  71. let height = 0;
  72. let hightArr = [];
  73. for (let i = 0; i < len; i++) {
  74. //获取元素所在位置
  75. let query = uni.createSelectorQuery().in(this);
  76. let idView = "#b" + i;
  77. query.select(idView).boundingClientRect();
  78. query.exec(function(res) {
  79. let top = res[0].top;
  80. hightArr.push(top);
  81. that.hightArr = hightArr
  82. });
  83. };
  84. },
  85. tap: function(index, id) {
  86. this.toView = id;
  87. this.navActive = index;
  88. },
  89. getAllCategory: function() {
  90. let that = this;
  91. getCategoryList().then(res => {
  92. that.productList = res.data;
  93. setTimeout(function(){
  94. that.infoScroll();
  95. },500)
  96. })
  97. },
  98. scroll: function(e) {
  99. let scrollTop = e.detail.scrollTop;
  100. let scrollArr = this.hightArr;
  101. for (let i = 0; i < scrollArr.length; i++) {
  102. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  103. this.navActive = 0
  104. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[0]) {
  105. this.navActive = i
  106. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  107. this.navActive = scrollArr.length - 1
  108. }
  109. }
  110. },
  111. searchSubmitValue: function(e) {
  112. if (this.$util.trim(e.detail.value).length > 0)
  113. uni.navigateTo({
  114. url: '/pages/goods_list/index?searchValue=' + e.detail.value
  115. })
  116. else
  117. return this.$util.Tips({
  118. title: '请填写要搜索的产品信息'
  119. });
  120. },
  121. }
  122. }
  123. </script>
  124. <style scoped lang="scss">
  125. .productSort .header {
  126. width: 100%;
  127. height: 96rpx;
  128. background-color: #fff;
  129. position: fixed;
  130. left: 0;
  131. right: 0;
  132. top: 0;
  133. z-index: 9;
  134. border-bottom: 1rpx solid #f5f5f5;
  135. }
  136. .productSort .header .input {
  137. width: 700rpx;
  138. height: 60rpx;
  139. background-color: #f5f5f5;
  140. border-radius: 50rpx;
  141. box-sizing: border-box;
  142. padding: 0 25rpx;
  143. }
  144. .productSort .header .input .iconfont {
  145. font-size: 35rpx;
  146. color: #555;
  147. }
  148. .productSort .header .input .placeholder {
  149. color: #999;
  150. }
  151. .productSort .header .input input {
  152. font-size: 26rpx;
  153. height: 100%;
  154. width: 597rpx;
  155. }
  156. .productSort .aside {
  157. position: fixed;
  158. width: 180rpx;
  159. left: 0;
  160. bottom: 0;
  161. top:0;
  162. background-color: #f7f7f7;
  163. overflow-y: auto;
  164. overflow-x: hidden;
  165. margin-top: 96rpx;
  166. }
  167. .productSort .aside .item {
  168. height: 100rpx;
  169. width: 100%;
  170. font-size: 26rpx;
  171. color: #424242;
  172. }
  173. .productSort .aside .item.on {
  174. background-color: #fff;
  175. border-left: 4rpx solid #fc4141;
  176. width: 100%;
  177. text-align: center;
  178. color: #fc4141;
  179. font-weight: bold;
  180. }
  181. .productSort .conter {
  182. margin: 96rpx 0 0 180rpx;
  183. padding: 0 14rpx;
  184. background-color: #fff;
  185. }
  186. .productSort .conter .listw {
  187. padding-top: 20rpx;
  188. }
  189. .productSort .conter .listw .title {
  190. height: 90rpx;
  191. }
  192. .productSort .conter .listw .title .line {
  193. width: 100rpx;
  194. height: 2rpx;
  195. background-color: #f0f0f0;
  196. }
  197. .productSort .conter .listw .title .name {
  198. font-size: 28rpx;
  199. color: #333;
  200. margin: 0 30rpx;
  201. font-weight: bold;
  202. }
  203. .productSort .conter .list {
  204. flex-wrap: wrap;
  205. }
  206. .productSort .conter .list .item {
  207. width: 177rpx;
  208. margin-top: 26rpx;
  209. }
  210. .productSort .conter .list .item .picture {
  211. width: 120rpx;
  212. height: 120rpx;
  213. border-radius: 50%;
  214. }
  215. .productSort .conter .list .item .picture image {
  216. width: 100%;
  217. height: 100%;
  218. border-radius: 50%;
  219. }
  220. .productSort .conter .list .item .name {
  221. font-size: 24rpx;
  222. color: #333;
  223. height: 56rpx;
  224. line-height: 56rpx;
  225. width: 120rpx;
  226. text-align: center;
  227. }
  228. </style>