goods_cate1.vue 8.4 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-middle'>
  35. <navigator class="name acea-row row-middle" :url="'/pages/goods/goods_list/index?cid='+item.id+'&title='+item.cate_name" hover-class="none">
  36. {{item.cate_name}}<text class="iconfont icon-xiangyou"></text>
  37. </navigator>
  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: 34rpx;
  217. color: #333;
  218. background-color: #fff;
  219. text-align: center;
  220. }
  221. .sys-head {
  222. background-color: #fff;
  223. }
  224. .productSort {
  225. display: flex;
  226. flex-direction: column;
  227. //#ifdef MP
  228. height: calc(100vh - var(--window-top)) !important;
  229. //#endif
  230. //#ifndef MP
  231. height: 100vh
  232. //#endif
  233. }
  234. .productSort .header {
  235. width: 100%;
  236. height: 96rpx;
  237. background-color: #fff;
  238. border-bottom: 1rpx solid #f5f5f5;
  239. }
  240. .productSort .header .input {
  241. width: 700rpx;
  242. height: 60rpx;
  243. background-color: #f5f5f5;
  244. border-radius: 50rpx;
  245. box-sizing: border-box;
  246. padding: 0 25rpx;
  247. }
  248. .productSort .header .input .iconfont {
  249. font-size: 35rpx;
  250. color: #555;
  251. }
  252. .productSort .header .input .placeholder {
  253. color: #999;
  254. }
  255. .productSort .header .input input {
  256. font-size: 26rpx;
  257. height: 100%;
  258. width: 597rpx;
  259. }
  260. .productSort .scroll-box {
  261. flex: 1;
  262. overflow: hidden;
  263. display: flex;
  264. }
  265. // #ifndef MP
  266. uni-scroll-view {
  267. padding-bottom: 100rpx;
  268. }
  269. // #endif
  270. .productSort .aside {
  271. width: 180rpx;
  272. height: 100%;
  273. overflow: hidden;
  274. background-color: #f7f7f7;
  275. }
  276. .productSort .aside .item {
  277. height: 100rpx;
  278. width: 100%;
  279. font-size: 26rpx;
  280. color: #424242;
  281. text-align: center;
  282. }
  283. .productSort .aside .item.on {
  284. background-color: #fff;
  285. border-left: 4rpx solid var(--view-theme);
  286. width: 100%;
  287. color: var(--view-theme);
  288. font-weight: bold;
  289. }
  290. .productSort .conter {
  291. flex: 1;
  292. height: 100%;
  293. overflow: hidden;
  294. padding: 0 14rpx;
  295. background-color: #fff;
  296. position: relative;
  297. }
  298. .productSort .conter .listw {
  299. padding-top: 20rpx;
  300. }
  301. .productSort .conter .listw .title {
  302. height: 90rpx;
  303. }
  304. .productSort .conter .listw .title .line {
  305. width: 100rpx;
  306. height: 2rpx;
  307. background-color: #f0f0f0;
  308. }
  309. .productSort .conter .listw .title .name {
  310. font-size: 28rpx;
  311. color: #333;
  312. margin: 0 30rpx;
  313. font-weight: bold;
  314. }
  315. .productSort .conter .listw .title .name .iconfont {
  316. margin-left: 10rpx;
  317. font-size: 22rpx;
  318. color: #999999;
  319. }
  320. .productSort .conter .list {
  321. flex-wrap: wrap;
  322. }
  323. .productSort .conter .list .item {
  324. width: 177rpx;
  325. margin-top: 26rpx;
  326. }
  327. .productSort .conter .list .item .picture {
  328. width: 120rpx;
  329. height: 120rpx;
  330. border-radius: 50%;
  331. }
  332. .productSort .conter .list .item .picture image {
  333. width: 100%;
  334. height: 100%;
  335. border-radius: 50%;
  336. }
  337. .productSort .conter .list .item .name {
  338. font-size: 24rpx;
  339. color: #333;
  340. height: 56rpx;
  341. line-height: 56rpx;
  342. width: 120rpx;
  343. text-align: center;
  344. }
  345. </style>