goods_cate.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view class='productSort' :style="'height:'+winHeight+'px'">
  3. <view class='header acea-row row-center-wrapper'>
  4. <navigator url="/pages/columnGoods/goods_search/index" class='acea-row row-between-wrapper input' hover-class="none">
  5. <text class='iconfont icon-sousuo'></text>
  6. <view class="input-box">点击搜索商品信息</view>
  7. </navigator>
  8. </view>
  9. <view class="con-box">
  10. <view class='aside'>
  11. <scroll-view scroll-y="true" style="height: 100%; overflow: hidden;" scroll-with-animation='true' :scroll-into-view="intoindex">
  12. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""' v-for="(item,index) in productList"
  13. :key="item.store_category_id" @click='tap(index,"b"+index)' :id='"sort"+index'><text class="item_text">{{item.cate_name}}</text></view>
  14. </scroll-view>
  15. </view>
  16. <view class='conter' v-if="productList.length>0">
  17. <scroll-view scroll-y="true" style="height: 100%; overflow: hidden;" @scroll="scroll" scroll-with-animation='true'>
  18. <block v-if="productList[navActive]">
  19. <view class='listw' :id="'b'+index" v-for="(item,index) in productList[navActive].children" :key="item.store_category_id">
  20. <view class='title acea-row'>
  21. <view class='name'>{{item.cate_name}}</view>
  22. </view>
  23. <view class='list acea-row'>
  24. <block v-for="(itemn,indexn) in item.children" :key="itemn.store_category_id">
  25. <!-- :url='"/pages/columnGoods/goods_list/index"+itemn.id+"&title="+itemn.cate_name' -->
  26. <navigator hover-class='none' :url="'/pages/columnGoods/goods_list/index?id='+itemn.store_category_id+'&title='+itemn.cate_name"
  27. class='item acea-row row-column row-middle'>
  28. <view class='picture'>
  29. <image :src='itemn.pic'></image>
  30. </view>
  31. <view class='name line1'>{{itemn.cate_name}}</view>
  32. </navigator>
  33. </block>
  34. </view>
  35. </view>
  36. </block>
  37. </scroll-view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. let app = getApp();
  44. import {
  45. getCategoryList
  46. } from '@/api/store.js';
  47. export default {
  48. data() {
  49. return {
  50. navlist: [],
  51. productList: [],
  52. navActive: 0,
  53. number: "",
  54. height: 0,
  55. hightArr: [],
  56. toView: "",
  57. winHeight: 0,
  58. pidIndex: 0,
  59. intoindex: ""
  60. }
  61. },
  62. onLoad(options) {
  63. let that = this
  64. uni.getSystemInfo({
  65. success: function(res) {
  66. that.winHeight = res.windowHeight
  67. },
  68. });
  69. // #ifdef H5
  70. console.log(this.$route)
  71. document.body.addEventListener('touchmove', function(event) {
  72. if (that.$route.path == '/pages/goods_cate/goods_cate') {
  73. event.preventDefault();
  74. }
  75. }, {
  76. passive: false
  77. });
  78. // #endif
  79. },
  80. onShow() {
  81. if (!this.productList.length) {
  82. this.getAllCategory();
  83. }
  84. },
  85. onHide() {},
  86. //点击底部tabbar调用
  87. onTabItemTap() {
  88. this.getAllCategory();
  89. },
  90. onReady() {
  91. // setTimeout(res=>{
  92. // this.intoindex = "sort13"
  93. // },2000)
  94. },
  95. methods: {
  96. infoScroll: function() {
  97. let that = this;
  98. let len = that.productList.length;
  99. //this.number = that.productList[len - 1].children.length;
  100. //设置商品列表高度
  101. uni.getSystemInfo({
  102. success: function(res) {
  103. that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
  104. },
  105. });
  106. // let height = 0;
  107. // let hightArr = [];
  108. // for (let i = 0; i < len; i++) {
  109. // //获取元素所在位置
  110. // let query = uni.createSelectorQuery().in(this);
  111. // let idView = "#b" + i;
  112. // query.select(idView).boundingClientRect();
  113. // query.exec(function(res) {
  114. // let top = res[0].top;
  115. // hightArr.push(top);
  116. // that.hightArr = hightArr
  117. // });
  118. // };
  119. },
  120. tap: function(index, id) {
  121. this.toView = id;
  122. this.navActive = index;
  123. },
  124. getAllCategory: function() {
  125. let that = this;
  126. let value = ""
  127. getCategoryList().then(res => {
  128. that.productList = res.data;
  129. that.getCateFrom(that.productList)
  130. that.tap(that.pidIndex, 'b' + that.pidIndex)
  131. that.infoScroll()
  132. that.intoindex = ""
  133. uni.removeStorageSync('storeIndex')
  134. })
  135. },
  136. //获取首页分类来源
  137. getCateFrom: function(arr) {
  138. let pid = uni.getStorageSync('storeIndex')
  139. let i = ""
  140. arr.map((item, index) => {
  141. if (item.store_category_id == pid) {
  142. this.pidIndex = index
  143. i = 'sort' + index
  144. // this.intoindex = 'sort'+index
  145. return;
  146. }
  147. })
  148. this.$nextTick(() => {
  149. this.intoindex = i
  150. })
  151. },
  152. scroll: function(e) {
  153. let scrollTop = e.detail.scrollTop;
  154. let scrollArr = this.hightArr;
  155. for (let i = 0; i < scrollArr.length; i++) {
  156. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  157. this.navActive = 0
  158. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[0]) {
  159. this.navActive = i
  160. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  161. this.navActive = scrollArr.length - 1
  162. }
  163. }
  164. },
  165. searchSubmitValue: function(e) {
  166. if (this.$util.trim(e.detail.value).length > 0)
  167. uni.navigateTo({
  168. url: '/pages/columnGoods/goods_list/index?searchValue=' + e.detail.value
  169. })
  170. else
  171. return this.$util.Tips({
  172. title: '请填写要搜索的产品信息'
  173. });
  174. },
  175. }
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. .productSort {
  180. display: flex;
  181. flex-direction: column;
  182. width: 100%;
  183. .con-box {
  184. flex: 1;
  185. display: flex;
  186. overflow: hidden;
  187. }
  188. }
  189. .productSort .header {
  190. width: 100%;
  191. height: 96rpx;
  192. background-color: #fff;
  193. border-bottom: 1rpx solid #f5f5f5;
  194. }
  195. .productSort .header .input {
  196. width: 700rpx;
  197. height: 60rpx;
  198. background-color: #f5f5f5;
  199. border-radius: 50rpx;
  200. box-sizing: border-box;
  201. padding: 0 25rpx;
  202. }
  203. .productSort .header .input .iconfont {
  204. font-size: 35rpx;
  205. color: #555;
  206. }
  207. .productSort .header .input .placeholder {
  208. color: #999;
  209. }
  210. .productSort .header .input .input-box {
  211. display: flex;
  212. align-items: center;
  213. font-size: 26rpx;
  214. height: 100%;
  215. width: 597rpx;
  216. color: #999999;
  217. }
  218. .productSort .aside {
  219. background-color: #fff;
  220. overflow-y: auto;
  221. overflow-x: hidden;
  222. width: 200rpx;
  223. height: 100%;
  224. overflow: hidden;
  225. }
  226. .productSort .aside .item {
  227. height: 100rpx;
  228. width: 100%;
  229. font-size: 26rpx;
  230. color: #424242;
  231. }
  232. .productSort .aside .item_text {
  233. padding-left: 20rpx;
  234. overflow: hidden;
  235. text-overflow: ellipsis;
  236. display: -webkit-box;
  237. -webkit-line-clamp: 2;
  238. -webkit-box-orient: vertical;
  239. }
  240. .productSort .aside .item_text .text {}
  241. .productSort .aside .item.on {
  242. background-color: #f7f7f7;
  243. border-left: 4rpx solid #fc4141;
  244. width: 100%;
  245. text-align: center;
  246. color: #fc4141;
  247. font-weight: bold;
  248. }
  249. .productSort .conter {
  250. flex: 1;
  251. height: 100%;
  252. padding: 0 14rpx;
  253. background-color: #f7f7f7;
  254. }
  255. .productSort .conter .listw {
  256. // padding-top: 20rpx;
  257. }
  258. .productSort .conter .listw .title {
  259. height: 100rpx;
  260. align-items: center;
  261. }
  262. .productSort .conter .listw .title .line {
  263. width: 100rpx;
  264. height: 2rpx;
  265. background-color: #f0f0f0;
  266. }
  267. .productSort .conter .listw .title .name {
  268. font-size: 28rpx;
  269. color: #333;
  270. margin: 0 30rpx;
  271. font-weight: bold;
  272. }
  273. .productSort .conter .list {
  274. flex-wrap: wrap;
  275. background: #fff;
  276. border-radius: 16rpx;
  277. padding-bottom: 26rpx;
  278. }
  279. .productSort .conter .list .item {
  280. width: 174rpx;
  281. margin-top: 26rpx;
  282. }
  283. .productSort .conter .list .item .picture {
  284. width: 110rpx;
  285. height: 110rpx;
  286. border-radius: 50%;
  287. }
  288. .productSort .conter .list .item .picture image {
  289. width: 100%;
  290. height: 100%;
  291. }
  292. .productSort .conter .list .item .name {
  293. font-size: 24rpx;
  294. color: #333;
  295. height: 56rpx;
  296. line-height: 56rpx;
  297. width: 120rpx;
  298. text-align: center;
  299. }
  300. </style>