index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. that.$nextTick(function(){
  247. that.infoScroll();
  248. })
  249. that.showSkeleton = false
  250. })
  251. },
  252. scroll: function(e) {
  253. uni.$emit('scroll');
  254. let scrollTop = e.detail.scrollTop + 10;
  255. let scrollArr = this.hightArr;
  256. for (let i = 0; i < scrollArr.length; i++) {
  257. if (scrollTop >= 0 && scrollTop < scrollArr[1].top - scrollArr[0].top) {
  258. this.navActive = 0
  259. } else if (scrollTop >= scrollArr[i].top - scrollArr[0].top && scrollTop < (scrollArr[i + 1] ? scrollArr[i + 1].top : 0) - scrollArr[0].top) {
  260. this.navActive = scrollArr[i].i
  261. } else if (scrollTop >= scrollArr[scrollArr.length - 1].top - scrollArr[0].top) {
  262. this.navActive = scrollArr[scrollArr.length - 1].i
  263. }
  264. }
  265. },
  266. searchSubmitValue: function(e) {
  267. if (this.$util.trim(e.detail.value).length > 0)
  268. uni.navigateTo({
  269. animationType: animationType.type,
  270. animationDuration: animationType.duration,
  271. url: '/pages/goods/goods_list/index?searchValue=' + e.detail.value
  272. })
  273. else
  274. return this.$util.Tips({
  275. title: '请填写要搜索的产品信息'
  276. });
  277. },
  278. }
  279. }
  280. </script>
  281. <style scoped lang="scss">
  282. /deep/.origin-img{
  283. border-radius: 50%;
  284. }
  285. .productSort {
  286. display: flex;
  287. flex-direction: column;
  288. width: 100%;
  289. .con-box {
  290. flex: 1;
  291. display: flex;
  292. overflow: hidden;
  293. }
  294. }
  295. .productSort .header {
  296. width: 100%;
  297. /* #ifndef MP */
  298. height: 96rpx;
  299. /* #endif */
  300. background-color: #fff;
  301. border-bottom: 1rpx solid #f5f5f5;
  302. }
  303. .productSort .header .input {
  304. width: 700rpx;
  305. height: 60rpx;
  306. background-color: #f5f5f5;
  307. border-radius: 50rpx;
  308. box-sizing: border-box;
  309. padding: 0 25rpx;
  310. }
  311. .productSort .header .input .iconfont {
  312. font-size: 28rpx;
  313. color: #555;
  314. }
  315. .productSort .header .input .placeholder {
  316. color: #999;
  317. }
  318. .productSort .header .input input {
  319. font-size: 28rpx;
  320. height: 100%;
  321. width: 597rpx;
  322. }
  323. .productSort .header .input .input-box {
  324. display: flex;
  325. align-items: center;
  326. font-size: 28rpx;
  327. height: 100%;
  328. width: 597rpx;
  329. color: #999999;
  330. }
  331. .productSort .aside {
  332. background-color: #fff;
  333. overflow-y: auto;
  334. overflow-x: hidden;
  335. width: 200rpx;
  336. height: 100%;
  337. overflow: hidden;
  338. }
  339. .productSort .aside .item {
  340. height: 100rpx;
  341. width: 100%;
  342. font-size: 26rpx;
  343. color: #424242;
  344. }
  345. .productSort .aside .item_text {
  346. padding-left: 20rpx;
  347. overflow: hidden;
  348. text-overflow: ellipsis;
  349. display: -webkit-box;
  350. -webkit-line-clamp: 2;
  351. -webkit-box-orient: vertical;
  352. }
  353. .productSort .aside .item.on {
  354. background-color: #f7f7f7;
  355. border-left: 4rpx solid var(--view-theme);
  356. width: 100%;
  357. text-align: center;
  358. @include main_color(theme);
  359. font-weight: bold;
  360. }
  361. .productSort .conter {
  362. flex: 1;
  363. height: 100%;
  364. padding: 0 14rpx;
  365. background-color: #f7f7f7;
  366. }
  367. .productSort .conter .listw .title {
  368. height: 100rpx;
  369. align-items: center;
  370. }
  371. .productSort .conter .listw .title .line {
  372. width: 100rpx;
  373. height: 2rpx;
  374. background-color: #f0f0f0;
  375. }
  376. .productSort .conter .listw .title .name {
  377. font-size: 28rpx;
  378. color: #333;
  379. margin: 0 30rpx;
  380. font-weight: bold;
  381. }
  382. .productSort .conter .listw .title .list_title,
  383. .productSort .conter .listw .title uni-image,
  384. .productSort .conter .listw .title image{
  385. width: 110rpx;
  386. height: 26rpx;
  387. border-radius: 0;
  388. }
  389. .productSort .conter .list {
  390. flex-wrap: wrap;
  391. background: #fff;
  392. border-radius: 16rpx;
  393. padding-bottom: 26rpx;
  394. }
  395. .productSort .conter .list .item {
  396. width: 174rpx;
  397. margin-top: 26rpx;
  398. }
  399. .productSort .conter .list .item .picture,
  400. .productSort .conter uni-image,
  401. .productSort .conter .list .item image,
  402. /deep/.easy-loadimage{
  403. width: 110rpx;
  404. height: 110rpx;
  405. border-radius: 50%;
  406. }
  407. .productSort .conter .list .item .name {
  408. font-size: 24rpx;
  409. color: #333;
  410. height: 56rpx;
  411. line-height: 56rpx;
  412. width: 120rpx;
  413. text-align: center;
  414. }
  415. .searchBox{
  416. width: 100%;
  417. }
  418. .header-box{
  419. position: fixed;
  420. z-index: 9999;
  421. }
  422. </style>