goods_cate.vue 6.3 KB

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