index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <view :data-theme="theme">
  3. <tui-skeleton v-if="showSkeleton"></tui-skeleton>
  4. <view class='productSort' :style="{visibility: showSkeleton ? 'hidden' : 'visible', height: winHeight+ 'px' }">
  5. <!-- #ifdef APP -->
  6. <view class='header acea-row row-center-wrapper' :style="{ 'marginTop': sysHeight*2 + 'rpx'}">
  7. <!-- #endif -->
  8. <!-- #ifndef APP -->
  9. <view class='header acea-row row-center-wrapper header-box'>
  10. <!-- #endif -->
  11. <!-- #ifndef MP -->
  12. <view class='acea-row row-between-wrapper input'>
  13. <text class='iconfont icon-sousuo'></text>
  14. <input type='text' placeholder='点击搜索商品信息' @confirm="searchSubmitValue" confirm-type='search' name="search"
  15. placeholder-class='placeholder' maxlength="20"></input>
  16. </view>
  17. <!-- #endif -->
  18. <!-- #ifdef MP -->
  19. <searchBox class="searchBox" :toBackShow="false" @searchChange="searchSubmitValue"></searchBox>
  20. <!-- #endif -->
  21. </view>
  22. <!-- #ifdef APP -->
  23. <view class="con-box">
  24. <!-- #endif -->
  25. <!-- #ifndef APP -->
  26. <view class="con-box" :style="{ 'marginTop': sysHeight*2 + 90 + 'rpx'}">
  27. <!-- #endif -->
  28. <view class='aside'>
  29. <scroll-view scroll-y="true" style="height: 100%; overflow: hidden;" scroll-with-animation='true' :scroll-into-view="intoindex">
  30. <view v-for="(item,index) in productList" :key="item.id">
  31. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""' v-if='item.childList && item.childList.length > 0'
  32. :key="item.id" @click='tap(index,"b"+item.id)' :id='"sort"+index'><text class="item_text skeleton-rect">{{item.name}}</text>
  33. </view>
  34. </view>
  35. </scroll-view>
  36. </view>
  37. <view class='conter'>
  38. <scroll-view scroll-y="true" :scroll-into-view="toView" style="height: 100%; overflow: hidden;" @scroll="scroll" scroll-with-animation='true'>
  39. <view v-for="(p,i) in productList" :key="p.id">
  40. <view class='listw' :id="'b'+p.id+index" v-for="(item,index) in p.childList" :key="item.id">
  41. <view class='title acea-row'>
  42. <view class='name skeleton-rect'>{{item.name}}</view>
  43. </view>
  44. <view class='list acea-row'>
  45. <block v-for="(itemn,indexn) in item.childList" :key="itemn.id">
  46. <navigator hover-class='none' :url='"/pages/goods/goods_list/index?cid="+itemn.id+"&title="+itemn.name'
  47. class='item acea-row row-column row-middle'>
  48. <view class='picture skeleton-rect'>
  49. <easy-loadimage mode="widthFix" :image-src="itemn.icon"></easy-loadimage>
  50. </view>
  51. <view class='name line1'>{{itemn.name}}</view>
  52. </navigator>
  53. </block>
  54. </view>
  55. </view>
  56. </view>
  57. <view :style='"height:"+(bottomheight-300)+"rpx;"'></view>
  58. </scroll-view>
  59. </view>
  60. </view>
  61. </view>
  62. <view v-if="bottomNavigationIsCustom" class="footerBottom"></view>
  63. <pageFooter></pageFooter>
  64. </view>
  65. </template>
  66. <script>
  67. // +----------------------------------------------------------------------
  68. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  69. // +----------------------------------------------------------------------
  70. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  71. // +----------------------------------------------------------------------
  72. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  73. // +----------------------------------------------------------------------
  74. // | Author: CRMEB Team <admin@crmeb.com>
  75. // +----------------------------------------------------------------------
  76. let app = getApp();
  77. import { getCategoryList } from '@/api/product.js';
  78. import easyLoadimage from '@/components/base/easy-loadimage.vue';
  79. import { mapGetters } from "vuex";
  80. import tuiSkeleton from '@/components/base/tui-skeleton.vue';
  81. import pageFooter from "@/components/pageFooter/index.vue";
  82. import animationType from '@/utils/animationType.js'
  83. // #ifdef MP
  84. import searchBox from "@/components/searchBox.vue";
  85. // #endif
  86. let sysHeight = uni.getSystemInfoSync().statusBarHeight;
  87. export default {
  88. components: {
  89. easyLoadimage,
  90. tuiSkeleton,
  91. pageFooter,
  92. // #ifdef MP
  93. searchBox
  94. // #endif
  95. },
  96. computed: mapGetters(['bottomNavigationIsCustom']),
  97. data() {
  98. let active = 0;
  99. // #ifdef H5
  100. active = location.hash.substr(1);
  101. // #endif
  102. return {
  103. theme:app.globalData.theme,
  104. showSkeleton: true, //骨架屏显示隐藏
  105. navlist: [],
  106. hotList: [], //推荐分类
  107. sysHeight:sysHeight,
  108. productList: [
  109. {name: 'skeleton',id: 0,
  110. childList:[
  111. {name: 'skeleton',id: 10,childList:[
  112. {name: '',id: 101,},
  113. {name: '',id: 102,},
  114. {name: '',id: 103,},
  115. {name: '',id: 104,},
  116. {name: '',id: 105,},
  117. {name: '',id: 106,}
  118. ]},
  119. {name: 'skeleton',id: 1,
  120. childList:[
  121. {name: '',id: 101,},
  122. {name: '',id: 102,},
  123. {name: '',id: 103,},
  124. {name: '',id: 104,},
  125. {name: '',id: 105,},
  126. {name: '',id: 106,}
  127. ]},
  128. {name: '',id: 20}
  129. ]
  130. },
  131. {name: 'skeleton',id: 2,
  132. childList:[{name:'skeleton',id: 30}]},
  133. {name: 'skeleton',id: 3,
  134. childList:[{name:'skeleton',id: 31}]},
  135. {name: 'skeleton',id: 4,
  136. childList:[{name:'skeleton',id: 32}]},
  137. {name: 'skeleton',id: 5,
  138. childList:[{name:'skeleton',id: 33}]},
  139. {name: 'skeleton',id: 6,
  140. childList:[{name:'skeleton',id: 34}]},
  141. {name: 'skeleton',id: 7,
  142. childList:[{name:'skeleton',id: 35}]},
  143. {name: 'skeleton',id: 8,
  144. childList:[{name:'skeleton',id: 36}]},
  145. {name: 'skeleton',id: 9,
  146. children:[{name:'skeleton',id: 37}]},
  147. {name: 'skeleton',id: 10,
  148. childList:[{name:'skeleton',id: 38}]},
  149. {name: 'skeleton',id: 11,
  150. childList:[{name:'skeleton',id: 39}]},
  151. ],
  152. navActive: 0,
  153. activceCate: active,
  154. number: "",
  155. bottomheight: 0,
  156. hightArr: [],
  157. toView: "",
  158. winHeight: 0,
  159. pidIndex: 0,
  160. intoindex: "",
  161. pid: '',
  162. newData: {},
  163. activeRouter: '',
  164. }
  165. },
  166. onLoad(options) {
  167. let that = this
  168. uni.getSystemInfo({
  169. success: function(res) {
  170. that.winHeight = res.windowHeight
  171. },
  172. });
  173. // #ifdef H5
  174. document.body.addEventListener('touchmove', function(event) {
  175. if (that.$route.path == '/pages/goods_cate/goods_cate') {
  176. event.preventDefault();
  177. }
  178. }, {
  179. passive: false
  180. });
  181. // #endif
  182. this.getAllCategory();
  183. },
  184. onShow() {
  185. let that = this
  186. let routes = getCurrentPages();
  187. let curRoute = routes[routes.length - 1].route;
  188. this.activeRouter = '/' + curRoute;
  189. if(uni.getStorageSync('cateNavActive')){
  190. this.navActive = uni.getStorageSync('cateNavActive')-1;
  191. uni.removeStorageSync('cateNavActive');
  192. }
  193. if(uni.getStorageSync('categoryId')){
  194. this.pid= uni.getStorageSync('categoryId');
  195. uni.removeStorageSync('categoryId');
  196. }
  197. this.pid && this.navActive && setTimeout(()=>this.tap(this.navActive, 'b' + this.pid), 200);
  198. setTimeout(() => {
  199. uni.removeStorageSync('categoryId');
  200. uni.removeStorageSync('cateNavActive');
  201. }, 300);
  202. },
  203. methods: {
  204. infoScroll: function() {
  205. let that = this;
  206. //设置商品列表高度
  207. uni.getSystemInfo({
  208. success: function(res) {
  209. that.bottomheight = (res.windowHeight) * (750 / res.windowWidth) - 98;
  210. },
  211. });
  212. let hightArr = [];
  213. for (let i = 0; i < that.productList.length; i++) {
  214. let item = that.productList[i]
  215. if(!that.productList[i].childList){
  216. continue;
  217. }
  218. for (let j = 0; j < that.productList[i].childList.length; j++) {
  219. //获取元素所在位置
  220. let query = uni.createSelectorQuery().in(this);
  221. let idView = "#b" + item.id + j;
  222. query.select(idView).boundingClientRect();
  223. query.exec(function(res) {
  224. if(res[0]){
  225. let top = res[0].top;
  226. hightArr.push({top,i});
  227. }
  228. });
  229. };
  230. };
  231. that.hightArr = hightArr;
  232. },
  233. tap: function(index, id) {
  234. this.toView = ''+id+0;
  235. this.navActive = index;
  236. setTimeout(()=>{
  237. uni.$emit('scroll');
  238. }, 300);
  239. },
  240. getAllCategory: function() {
  241. let that = this;
  242. let value = ""
  243. that.pidIndex = 0;
  244. getCategoryList().then(res => {
  245. that.productList = res.data;
  246. console.log(this.productList)
  247. that.$nextTick(function(){
  248. that.infoScroll();
  249. })
  250. that.showSkeleton = false
  251. })
  252. },
  253. scroll: function(e) {
  254. uni.$emit('scroll');
  255. let scrollTop = e.detail.scrollTop + 10;
  256. let scrollArr = this.hightArr;
  257. for (let i = 0; i < scrollArr.length; i++) {
  258. if (scrollTop >= 0 && scrollTop < scrollArr[1].top - scrollArr[0].top) {
  259. this.navActive = 0
  260. } else if (scrollTop >= scrollArr[i].top - scrollArr[0].top && scrollTop < (scrollArr[i + 1] ? scrollArr[i + 1].top : 0) - scrollArr[0].top) {
  261. this.navActive = scrollArr[i].i
  262. } else if (scrollTop >= scrollArr[scrollArr.length - 1].top - scrollArr[0].top) {
  263. this.navActive = scrollArr[scrollArr.length - 1].i
  264. }
  265. }
  266. },
  267. searchSubmitValue: function(e) {
  268. if (this.$util.trim(e.detail.value).length > 0)
  269. uni.navigateTo({
  270. animationType: animationType.type,
  271. animationDuration: animationType.duration,
  272. url: '/pages/goods/goods_list/index?searchValue=' + e.detail.value
  273. })
  274. else
  275. return this.$util.Tips({
  276. title: '请填写要搜索的产品信息'
  277. });
  278. },
  279. }
  280. }
  281. </script>
  282. <style scoped lang="scss">
  283. /deep/.origin-img{
  284. border-radius: 50%;
  285. }
  286. .productSort {
  287. display: flex;
  288. flex-direction: column;
  289. width: 100%;
  290. .con-box {
  291. flex: 1;
  292. display: flex;
  293. overflow: hidden;
  294. }
  295. }
  296. .productSort .header {
  297. width: 100%;
  298. /* #ifndef MP */
  299. height: 96rpx;
  300. /* #endif */
  301. background-color: #fff;
  302. border-bottom: 1rpx solid #f5f5f5;
  303. }
  304. .productSort .header .input {
  305. width: 700rpx;
  306. height: 60rpx;
  307. background-color: #f5f5f5;
  308. border-radius: 50rpx;
  309. box-sizing: border-box;
  310. padding: 0 25rpx;
  311. }
  312. .productSort .header .input .iconfont {
  313. font-size: 28rpx;
  314. color: #555;
  315. }
  316. .productSort .header .input .placeholder {
  317. color: #999;
  318. }
  319. .productSort .header .input input {
  320. font-size: 28rpx;
  321. height: 100%;
  322. width: 597rpx;
  323. }
  324. .productSort .header .input .input-box {
  325. display: flex;
  326. align-items: center;
  327. font-size: 28rpx;
  328. height: 100%;
  329. width: 597rpx;
  330. color: #999999;
  331. }
  332. .productSort .aside {
  333. background-color: #fff;
  334. overflow-y: auto;
  335. overflow-x: hidden;
  336. width: 200rpx;
  337. height: 100%;
  338. overflow: hidden;
  339. }
  340. .productSort .aside .item {
  341. height: 100rpx;
  342. width: 100%;
  343. font-size: 26rpx;
  344. color: #424242;
  345. }
  346. .productSort .aside .item_text {
  347. padding-left: 20rpx;
  348. overflow: hidden;
  349. text-overflow: ellipsis;
  350. display: -webkit-box;
  351. -webkit-line-clamp: 2;
  352. -webkit-box-orient: vertical;
  353. }
  354. .productSort .aside .item.on {
  355. background-color: #f7f7f7;
  356. border-left: 4rpx solid var(--view-theme);
  357. width: 100%;
  358. text-align: center;
  359. @include main_color(theme);
  360. font-weight: bold;
  361. }
  362. .productSort .conter {
  363. flex: 1;
  364. height: 100%;
  365. padding: 0 14rpx;
  366. background-color: #f7f7f7;
  367. }
  368. .productSort .conter .listw .title {
  369. height: 100rpx;
  370. align-items: center;
  371. }
  372. .productSort .conter .listw .title .line {
  373. width: 100rpx;
  374. height: 2rpx;
  375. background-color: #f0f0f0;
  376. }
  377. .productSort .conter .listw .title .name {
  378. font-size: 28rpx;
  379. color: #333;
  380. margin: 0 30rpx;
  381. font-weight: bold;
  382. }
  383. .productSort .conter .listw .title .list_title,
  384. .productSort .conter .listw .title uni-image,
  385. .productSort .conter .listw .title image{
  386. width: 110rpx;
  387. height: 26rpx;
  388. border-radius: 0;
  389. }
  390. .productSort .conter .list {
  391. flex-wrap: wrap;
  392. background: #fff;
  393. border-radius: 16rpx;
  394. padding-bottom: 26rpx;
  395. }
  396. .productSort .conter .list .item {
  397. width: 174rpx;
  398. margin-top: 26rpx;
  399. }
  400. .productSort .conter .list .item .picture,
  401. .productSort .conter uni-image,
  402. .productSort .conter .list .item image,
  403. /deep/.easy-loadimage{
  404. width: 110rpx;
  405. height: 110rpx;
  406. border-radius: 50%;
  407. }
  408. .productSort .conter .list .item .name {
  409. font-size: 24rpx;
  410. color: #333;
  411. height: 56rpx;
  412. line-height: 56rpx;
  413. width: 120rpx;
  414. text-align: center;
  415. }
  416. .searchBox{
  417. width: 100%;
  418. }
  419. .header-box{
  420. position: fixed;
  421. z-index: 9999;
  422. }
  423. </style>