goods_cate.vue 6.2 KB

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