goods_cate1.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <!-- 商品分类第一种布局样式 -->
  3. <view class='productSort copy-data' :style="{height:pageHeight}">
  4. <!-- #ifdef APP-PLUS || MP -->
  5. <view class="sys-head" :style="{height:sysHeight}"></view>
  6. <!-- #endif -->
  7. <!-- #ifdef MP || APP-PLUS -->
  8. <view class="sys-title">商品分类</view>
  9. <!-- #endif -->
  10. <view class='header acea-row row-center-wrapper'>
  11. <view class='acea-row row-between-wrapper input'>
  12. <text class='iconfont icon-sousuo'></text>
  13. <input type='text' placeholder='点击搜索商品信息' @confirm="searchSubmitValue" confirm-type='search'
  14. name="search" placeholder-class='placeholder'></input>
  15. </view>
  16. </view>
  17. <view class="scroll-box">
  18. <view class='aside'>
  19. <scroll-view scroll-y="true" scroll-with-animation='true' class="height-add">
  20. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""'
  21. v-for="(item,index) in productList" :key="index" @click='tap(index,"b"+index)'>
  22. <text>{{item.cate_name}}</text>
  23. </view>
  24. <!-- #ifdef APP-PLUS -->
  25. <view class="item" v-if="isFooter"></view>
  26. <!-- #endif -->
  27. </scroll-view>
  28. </view>
  29. <view class='conter'>
  30. <scroll-view scroll-y="true" :scroll-into-view="toView" @scroll="scroll" scroll-with-animation='true'
  31. class="conterScroll height-add">
  32. <block v-for="(item,index) in productList" :key="index">
  33. <view class='listw' :id="'b'+index">
  34. <view class='title acea-row row-center-wrapper'>
  35. <view class='line'></view>
  36. <view class='name'>{{item.cate_name}}</view>
  37. <view class='line'></view>
  38. </view>
  39. <view class='list acea-row'>
  40. <block v-for="(itemn,indexn) in item.children" :key="indexn">
  41. <navigator hover-class='none'
  42. :url='"/pages/goods/goods_list/index?sid="+itemn.id+"&title="+itemn.cate_name'
  43. class='item acea-row row-column row-middle'>
  44. <view class='picture'>
  45. <!-- <image :src='itemn.pic' v-if="itemn.pic"></image> -->
  46. <lazyLoad :src="itemn.pic" width="100%" height="100%" v-if="itemn.pic"></lazyLoad>
  47. <image src="/static/images/sort-img.png" v-else></image>
  48. </view>
  49. <view class='name line1'>{{itemn.cate_name}}</view>
  50. </navigator>
  51. </block>
  52. </view>
  53. </view>
  54. </block>
  55. <view :style='"height:"+(height-heightDiv)+"rpx;"'></view>
  56. </scroll-view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  63. import {
  64. getCategoryList
  65. } from '@/api/store.js';
  66. import {
  67. mapState,
  68. mapGetters
  69. } from "vuex"
  70. import lazyLoad from '@/components/muqian-lazyLoad/muqian-lazyLoad.vue'
  71. const app = getApp();
  72. export default {
  73. components: {
  74. lazyLoad
  75. },
  76. props: {
  77. isFooter:{
  78. type:Boolean,
  79. default:false
  80. }
  81. },
  82. data() {
  83. return {
  84. navlist: [],
  85. productList: [],
  86. navActive: 0,
  87. number: "",
  88. height: 0,
  89. heightDiv: 0,
  90. hightArr: [],
  91. toView: "",
  92. tabbarH: 0,
  93. footH: 0,
  94. windowHeight: 0,
  95. pageHeight: '100%',
  96. sysHeight: sysHeight,
  97. // #ifdef APP-PLUS
  98. pageHeight: app.globalData.windowHeight,
  99. // #endif
  100. footerStatus: false,
  101. lock: false
  102. }
  103. },
  104. computed: {
  105. ...mapState({
  106. cartNum: state => state.indexData.cartNum
  107. })
  108. },
  109. mounted() {
  110. let that = this
  111. // this.getAllCategory();
  112. // #ifdef H5
  113. uni.getSystemInfo({
  114. success: function(res) {
  115. that.pageHeight = res.windowHeight + 'px'
  116. }
  117. });
  118. // #endif
  119. },
  120. methods: {
  121. footHeight(data) {
  122. this.footH = data
  123. },
  124. infoScroll: function() {
  125. let that = this;
  126. let len = that.productList.length;
  127. this.number = that.productList[len - 1].children.length;
  128. let height = 0;
  129. let hightArr = [];
  130. //设置商品列表高度
  131. let query = uni.createSelectorQuery().in(this);
  132. query.select(".conter").boundingClientRect();
  133. query.exec(function(res){
  134. height = res[0].height;
  135. })
  136. for (let i = 0; i < len; i++) {
  137. //获取元素所在位置
  138. let query = uni.createSelectorQuery().in(this);
  139. let idView = "#b" + i;
  140. query.select(idView).boundingClientRect();
  141. query.exec(function(res) {
  142. let top = res[0].top;
  143. that.hightArr.push(top);
  144. if(len == that.hightArr.length){
  145. //设置转化比例
  146. uni.getSystemInfo({
  147. success: function(res) {
  148. let per = (750 / res.windowWidth);
  149. that.height = height * per;
  150. that.heightDiv = (that.hightArr[that.hightArr.length-1] - that.hightArr[that.hightArr.length-2])*per;
  151. },
  152. });
  153. }
  154. });
  155. };
  156. },
  157. tap: function(index, id) {
  158. this.toView = id;
  159. this.navActive = index;
  160. this.$set(this, 'lock', true);
  161. },
  162. getAllCategory: function() {
  163. let that = this;
  164. getCategoryList().then(res => {
  165. that.productList = res.data;
  166. that.$nextTick(res => {
  167. setTimeout(function(){
  168. that.infoScroll();
  169. })
  170. })
  171. })
  172. },
  173. scroll: function(e) {
  174. let scrollTop = e.detail.scrollTop;
  175. let scrollArr = this.hightArr;
  176. if (this.lock) {
  177. this.$set(this, 'lock', false);
  178. return;
  179. }
  180. for (let i = 0; i < scrollArr.length; i++) {
  181. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  182. this.navActive = 0
  183. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[
  184. 0]) {
  185. this.navActive = i
  186. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  187. this.navActive = scrollArr.length - 1
  188. }
  189. }
  190. },
  191. searchSubmitValue: function(e) {
  192. if (this.$util.trim(e.detail.value).length > 0)
  193. uni.navigateTo({
  194. url: '/pages/goods/goods_list/index?searchValue=' + e.detail.value
  195. })
  196. else
  197. return this.$util.Tips({
  198. title: '请填写要搜索的产品信息'
  199. });
  200. },
  201. }
  202. }
  203. </script>
  204. <style>
  205. .height-add {
  206. height: 100%;
  207. }
  208. page {
  209. height: 100%;
  210. }
  211. </style>
  212. <style scoped lang="scss">
  213. /deep/uni-scroll-view{
  214. padding-bottom: 0!important;
  215. }
  216. .sys-title {
  217. z-index: 10;
  218. position: relative;
  219. height: 40px;
  220. line-height: 40px;
  221. font-size: 30rpx;
  222. color: #333;
  223. background-color: #fff;
  224. // #ifdef APP-PLUS
  225. text-align: center;
  226. // #endif
  227. // #ifdef MP
  228. text-align: left;
  229. padding-left: 30rpx;
  230. // #endif
  231. }
  232. .sys-head {
  233. background-color: #fff;
  234. }
  235. .productSort {
  236. display: flex;
  237. flex-direction: column;
  238. //#ifdef MP
  239. height: calc(100vh - var(--window-top)) !important;
  240. //#endif
  241. //#ifndef MP
  242. height: 100vh
  243. //#endif
  244. }
  245. .productSort .header {
  246. width: 100%;
  247. height: 96rpx;
  248. background-color: #fff;
  249. border-bottom: 1rpx solid #f5f5f5;
  250. }
  251. .productSort .header .input {
  252. width: 700rpx;
  253. height: 60rpx;
  254. background-color: #f5f5f5;
  255. border-radius: 50rpx;
  256. box-sizing: border-box;
  257. padding: 0 25rpx;
  258. }
  259. .productSort .header .input .iconfont {
  260. font-size: 35rpx;
  261. color: #555;
  262. }
  263. .productSort .header .input .placeholder {
  264. color: #999;
  265. }
  266. .productSort .header .input input {
  267. font-size: 26rpx;
  268. height: 100%;
  269. width: 597rpx;
  270. }
  271. .productSort .scroll-box {
  272. flex: 1;
  273. overflow: hidden;
  274. display: flex;
  275. }
  276. // #ifndef MP
  277. uni-scroll-view {
  278. padding-bottom: 100rpx;
  279. }
  280. // #endif
  281. .productSort .aside {
  282. width: 180rpx;
  283. height: 100%;
  284. overflow: hidden;
  285. background-color: #f7f7f7;
  286. }
  287. .productSort .aside .item {
  288. height: 100rpx;
  289. width: 100%;
  290. font-size: 26rpx;
  291. color: #424242;
  292. text-align: center;
  293. }
  294. .productSort .aside .item.on {
  295. background-color: #fff;
  296. border-left: 4rpx solid var(--view-theme);
  297. width: 100%;
  298. color: var(--view-theme);
  299. font-weight: bold;
  300. }
  301. .productSort .conter {
  302. flex: 1;
  303. height: 100%;
  304. overflow: hidden;
  305. padding: 0 14rpx;
  306. background-color: #fff;
  307. position: relative;
  308. }
  309. .productSort .conter .listw {
  310. padding-top: 20rpx;
  311. }
  312. .productSort .conter .listw .title {
  313. height: 90rpx;
  314. }
  315. .productSort .conter .listw .title .line {
  316. width: 100rpx;
  317. height: 2rpx;
  318. background-color: #f0f0f0;
  319. }
  320. .productSort .conter .listw .title .name {
  321. font-size: 28rpx;
  322. color: #333;
  323. margin: 0 30rpx;
  324. font-weight: bold;
  325. }
  326. .productSort .conter .list {
  327. flex-wrap: wrap;
  328. }
  329. .productSort .conter .list .item {
  330. width: 177rpx;
  331. margin-top: 26rpx;
  332. }
  333. .productSort .conter .list .item .picture {
  334. width: 120rpx;
  335. height: 120rpx;
  336. border-radius: 50%;
  337. }
  338. .productSort .conter .list .item .picture image {
  339. width: 100%;
  340. height: 100%;
  341. border-radius: 50%;
  342. }
  343. .productSort .conter .list .item .name {
  344. font-size: 24rpx;
  345. color: #333;
  346. height: 56rpx;
  347. line-height: 56rpx;
  348. width: 120rpx;
  349. text-align: center;
  350. }
  351. </style>