goods_cate1.vue 8.3 KB

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