goods_cate.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <template>
  2. <view>
  3. <skeleton :show="showSkeleton" :isNodes="isNodes" ref="skeleton" loading="chiaroscuro" selector="skeleton"
  4. bgcolor="#FFF"></skeleton>
  5. <view class='productSort' :style="{visibility: showSkeleton ? 'hidden' : 'visible', height: winHeight+ 'px' }">
  6. <view class='header acea-row row-center-wrapper'>
  7. <navigator url="/pages/columnGoods/goods_search/index" class='acea-row row-between-wrapper input skeleton-rect' hover-class="none">
  8. <text class='iconfont icon-sousuo'></text>
  9. <view class="input-box">点击搜索商品信息</view>
  10. </navigator>
  11. </view>
  12. <view class="con-box" :style="viewColor">
  13. <view class='aside'>
  14. <scroll-view scroll-y="true" style="height: 100%; overflow: hidden;" scroll-with-animation='true' :scroll-into-view="intoindex">
  15. <view v-for="(item,index) in productList">
  16. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""' v-if='item.children && item.children.length > 0'
  17. :key="item.store_category_id" @click='tap(index,"b"+item.store_category_id)' :id='"sort"+index'><text class="item_text skeleton-rect">{{item.cate_name}}{{pid}}</text>
  18. </view>
  19. </view>
  20. </scroll-view>
  21. </view>
  22. <view class='conter'>
  23. <scroll-view scroll-y="true" :scroll-into-view="toView" style="height: 100%; overflow: hidden;" @scroll="scroll" scroll-with-animation='true'>
  24. <view v-for="(p,i) in productList">
  25. <view class='listw' :id="'b'+p.store_category_id+index" v-for="(item,index) in p.children" :key="item.store_category_id">
  26. <view class='title acea-row'>
  27. <view v-if="hotList.length > 0 && i === 0" class='name skeleton-rect'>
  28. <image class="list_title" :src="domain+'/static/diy/recommend_cate'+keyColor+'.png'"></image>
  29. </view>
  30. <view v-else class='name skeleton-rect'>{{item.cate_name}}</view>
  31. </view>
  32. <view class='list acea-row'>
  33. <block v-for="(itemn,indexn) in item.children" :key="itemn.store_category_id">
  34. <navigator hover-class='none' :url="'/pages/columnGoods/goods_list/index?id='+itemn.store_category_id+'&title='+itemn.cate_name"
  35. class='item acea-row row-column row-middle'>
  36. <view class='picture skeleton-rect'>
  37. <easy-loadimage mode="widthFix" :image-src="itemn.pic"></easy-loadimage>
  38. </view>
  39. <view class='name line1'>{{itemn.cate_name}}</view>
  40. </navigator>
  41. </block>
  42. </view>
  43. </view>
  44. </view>
  45. <view :style='"height:"+(height-300)+"rpx;"'></view>
  46. </scroll-view>
  47. </view>
  48. </view>
  49. <!-- #ifndef H5 -->
  50. <passwordPopup></passwordPopup>
  51. <!-- #endif -->
  52. </view>
  53. <view class="foot" v-if="newData.status && newData.status.status">
  54. <view class="page-footer" id="target" :style="{'background-color':newData.bgColor.color[0].item}">
  55. <view class="foot-item" v-for="(item,index) in newData.menuList" :key="index"
  56. @click="goRouter(item)">
  57. <block v-if="item.link == activeRouter">
  58. <image :src="item.imgList[0]"></image>
  59. <view class="txt" :style="{color:newData.activeTxtColor.color[0].item}">{{item.name}}
  60. </view>
  61. </block>
  62. <block v-else>
  63. <image :src="item.imgList[1]"></image>
  64. <view class="txt" :style="{color:newData.txtColor.color[0].item}">{{item.name}}</view>
  65. </block>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. // +----------------------------------------------------------------------
  73. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  74. // +----------------------------------------------------------------------
  75. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  76. // +----------------------------------------------------------------------
  77. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  78. // +----------------------------------------------------------------------
  79. // | Author: CRMEB Team <admin@crmeb.com>
  80. // +----------------------------------------------------------------------
  81. let app = getApp();
  82. import { getCategoryList } from '@/api/store.js';
  83. import { getNavigation } from '@/api/public.js'
  84. import { configMap } from '@/utils/index';
  85. // #ifndef H5
  86. import passwordPopup from '@/components/passwordPopup';
  87. // #endif
  88. import easyLoadimage from '@/components/easy-loadimage/easy-loadimage.vue';
  89. import { mapGetters } from "vuex";
  90. import { HTTP_REQUEST_URL } from '@/config/app';
  91. export default {
  92. components: {
  93. easyLoadimage,
  94. // #ifndef H5
  95. passwordPopup,
  96. // #endif
  97. },
  98. computed: configMap({navigation: {}},mapGetters(['viewColor','keyColor'])),
  99. data() {
  100. let active = 0;
  101. // #ifdef H5
  102. active = location.hash.substr(1);
  103. // #endif
  104. return {
  105. domain: HTTP_REQUEST_URL,
  106. showSkeleton: true, //骨架屏显示隐藏
  107. isNodes: 0, //控制什么时候开始抓取元素节点,只要数值改变就重新抓取
  108. navlist: [],
  109. hotList: [], //推荐分类
  110. productList: [
  111. {cate_name: 'skeleton',store_category_id: 0,
  112. children:[
  113. {cate_name: 'skeleton',store_category_id: 10,children:[
  114. {cate_name: '',store_category_id: 101,},
  115. {cate_name: '',store_category_id: 102,},
  116. {cate_name: '',store_category_id: 103,},
  117. {cate_name: '',store_category_id: 104,},
  118. {cate_name: '',store_category_id: 105,},
  119. {cate_name: '',store_category_id: 106,}
  120. ]},
  121. {cate_name: 'skeleton',store_category_id: 1,
  122. children:[
  123. {cate_name: '',store_category_id: 101,},
  124. {cate_name: '',store_category_id: 102,},
  125. {cate_name: '',store_category_id: 103,},
  126. {cate_name: '',store_category_id: 104,},
  127. {cate_name: '',store_category_id: 105,},
  128. {cate_name: '',store_category_id: 106,}
  129. ]},
  130. {cate_name: '',store_category_id: 20}
  131. ]
  132. },
  133. {cate_name: 'skeleton',store_category_id: 2,
  134. children:[{cate_name:'skeleton',store_category_id: 30}]},
  135. {cate_name: 'skeleton',store_category_id: 3,
  136. children:[{cate_name:'skeleton',store_category_id: 31}]},
  137. {cate_name: 'skeleton',store_category_id: 4,
  138. children:[{cate_name:'skeleton',store_category_id: 32}]},
  139. {cate_name: 'skeleton',store_category_id: 5,
  140. children:[{cate_name:'skeleton',store_category_id: 33}]},
  141. {cate_name: 'skeleton',store_category_id: 6,
  142. children:[{cate_name:'skeleton',store_category_id: 34}]},
  143. {cate_name: 'skeleton',store_category_id: 7,
  144. children:[{cate_name:'skeleton',store_category_id: 35}]},
  145. {cate_name: 'skeleton',store_category_id: 8,
  146. children:[{cate_name:'skeleton',store_category_id: 36}]},
  147. {cate_name: 'skeleton',store_category_id: 9,
  148. children:[{cate_name:'skeleton',store_category_id: 37}]},
  149. {cate_name: 'skeleton',store_category_id: 10,
  150. children:[{cate_name:'skeleton',store_category_id: 38}]},
  151. {cate_name: 'skeleton',store_category_id: 11,
  152. children:[{cate_name:'skeleton',store_category_id: 39}]},
  153. ],
  154. navActive: 0,
  155. activceCate: active,
  156. number: "",
  157. height: 0,
  158. hightArr: [],
  159. toView: "",
  160. winHeight: 0,
  161. pidIndex: 0,
  162. intoindex: "",
  163. pid: '',
  164. newData: {},
  165. activeRouter: '',
  166. }
  167. },
  168. onLoad(options) {
  169. let that = this
  170. const index = uni.getStorageSync('storeIndex');
  171. if(options.activceCate){
  172. this.activceCate = options.activceCate;
  173. }else if(index){
  174. this.activceCate = index;
  175. uni.removeStorageSync('storeIndex');
  176. }
  177. uni.getSystemInfo({
  178. success: function(res) {
  179. that.winHeight = res.windowHeight
  180. },
  181. });
  182. // #ifdef H5
  183. document.body.addEventListener('touchmove', function(event) {
  184. if (that.$route.path == '/pages/goods_cate/goods_cate') {
  185. event.preventDefault();
  186. }
  187. }, {
  188. passive: false
  189. });
  190. // #endif
  191. this.getAllCategory();
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. // #ifdef MP
  197. onShareAppMessage: function() {
  198. wx.showShareMenu({
  199. withShareTicket: true,
  200. menus: ['shareAppMessage', 'shareTimeline']
  201. })
  202. return {
  203. path: '/pages/goods_cate/goods_cate?activceCate=' + this.productList[this.navActive] ? this.productList[this.navActive].store_category_id : 0
  204. }
  205. },
  206. onShareTimeline: function() {
  207. return {
  208. query: {
  209. activceCate: this.productList[this.navActive] ? this.productList[this.navActive].store_category_id : 0,
  210. }
  211. }
  212. },
  213. // #endif
  214. onShow() {
  215. let that = this
  216. let routes = getCurrentPages();
  217. let curRoute = routes[routes.length - 1].route
  218. this.activeRouter = '/' + curRoute
  219. let pid = uni.getStorageSync('storeIndex')
  220. if(pid) {
  221. this.activceCate = pid
  222. uni.removeStorageSync('storeIndex');
  223. }
  224. if(this.activceCate){
  225. this.getCateFrom(this.productList)
  226. pid && setTimeout(()=>this.tap(this.pidIndex, 'b' + this.activceCate), 200);
  227. }
  228. that.getNav()
  229. },
  230. onHide() {},
  231. // //点击底部tabbar调用
  232. // onTabItemTap() {
  233. // this.getAllCategory();
  234. // },
  235. onReady() {
  236. this.isNodes++;
  237. },
  238. methods: {
  239. goRouter(item) {
  240. var pages = getCurrentPages();
  241. var page = (pages[pages.length - 1]).$page.fullPath;
  242. if (item.link == page) return
  243. uni.switchTab({
  244. url: item.link,
  245. fail(err) {
  246. uni.redirectTo({
  247. url: item.link
  248. })
  249. }
  250. })
  251. },
  252. getNav() {
  253. this.newData = this.navigation
  254. if (this.newData.status && this.newData.status.status) {
  255. uni.hideTabBar()
  256. } else {
  257. uni.showTabBar()
  258. }
  259. },
  260. infoScroll: function() {
  261. let that = this;
  262. //this.number = that.productList[len - 1].children.length;
  263. //设置商品列表高度
  264. uni.getSystemInfo({
  265. success: function(res) {
  266. that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
  267. },
  268. });
  269. let hightArr = [];
  270. for (let i = 0; i < that.productList.length; i++) {
  271. let item = that.productList[i]
  272. if(!that.productList[i].children){
  273. continue;
  274. }
  275. for (let j = 0; j < that.productList[i].children.length; j++) {
  276. //获取元素所在位置
  277. let query = uni.createSelectorQuery().in(this);
  278. let idView = "#b" + item.store_category_id + j;
  279. query.select(idView).boundingClientRect();
  280. query.exec(function(res) {
  281. if(res[0]){
  282. let top = res[0].top;
  283. hightArr.push({top,i});
  284. }
  285. });
  286. };
  287. };
  288. that.hightArr = hightArr;
  289. },
  290. tap: function(index, id) {
  291. this.toView = ''+id+0;
  292. this.navActive = index;
  293. setTimeout(()=>{
  294. uni.$emit('scroll');
  295. }, 300);
  296. },
  297. getAllCategory: function() {
  298. let that = this;
  299. let value = ""
  300. that.pidIndex = 0;
  301. getCategoryList().then(res => {
  302. that.productList = res.data.list;
  303. that.hotList = res.data.hot;
  304. if(that.hotList.length>0){
  305. let hot = {
  306. cate_name: '推荐分类',store_category_id: 0,
  307. children: [
  308. {
  309. cate_name:'推荐分类',
  310. store_category_id: 1,
  311. children:that.hotList
  312. }
  313. ]
  314. }
  315. that.productList.unshift(hot)
  316. }
  317. that.getCateFrom(that.productList)
  318. that.$nextTick(function(){
  319. setTimeout(() => {
  320. that.infoScroll();
  321. setTimeout(()=>that.tap(that.pidIndex, 'b' + that.activceCate),200);
  322. }, 300);
  323. })
  324. setTimeout(() => {
  325. that.showSkeleton = false
  326. }, 500)
  327. })
  328. },
  329. //获取首页分类来源
  330. getCateFrom: function(arr) {
  331. let i = ""
  332. arr.map((item, index) => {
  333. if ((this.activceCate && item.store_category_id == this.activceCate)) {
  334. this.pidIndex = index
  335. i = 'sort' + index
  336. return;
  337. }
  338. })
  339. this.$nextTick(() => {
  340. this.intoindex = i
  341. })
  342. },
  343. scroll: function(e) {
  344. uni.$emit('scroll');
  345. let scrollTop = e.detail.scrollTop + 10;
  346. let scrollArr = this.hightArr;
  347. for (let i = 0; i < scrollArr.length; i++) {
  348. if (scrollTop >= scrollArr[i].top - scrollArr[0].top && scrollTop < (scrollArr[i + 1] ? scrollArr[i + 1].top : 0) - scrollArr[0].top) {
  349. this.navActive = scrollArr[i].i
  350. } else if (scrollTop >= scrollArr[scrollArr.length - 1].top - scrollArr[0].top) {
  351. this.navActive = scrollArr[scrollArr.length - 1].i
  352. }else if (scrollTop >= 0 && scrollTop < scrollArr[1].top - scrollArr[0].top) {
  353. this.navActive = 0
  354. }
  355. }
  356. },
  357. searchSubmitValue: function(e) {
  358. if (this.$util.trim(e.detail.value).length > 0)
  359. uni.navigateTo({
  360. url: '/pages/columnGoods/goods_list/index?searchValue=' + e.detail.value
  361. })
  362. else
  363. return this.$util.Tips({
  364. title: '请填写要搜索的产品信息'
  365. });
  366. },
  367. }
  368. }
  369. </script>
  370. <style scoped lang="scss">
  371. .productSort {
  372. display: flex;
  373. flex-direction: column;
  374. width: 100%;
  375. .con-box {
  376. flex: 1;
  377. display: flex;
  378. overflow: hidden;
  379. }
  380. }
  381. .productSort .header {
  382. width: 100%;
  383. height: 96rpx;
  384. background-color: #fff;
  385. border-bottom: 1px solid #f5f5f5;
  386. }
  387. .productSort .header .input {
  388. width: 700rpx;
  389. height: 60rpx;
  390. background-color: #f5f5f5;
  391. border-radius: 50rpx;
  392. box-sizing: border-box;
  393. padding: 0 25rpx;
  394. }
  395. .productSort .header .input .iconfont {
  396. font-size: 35rpx;
  397. color: #555;
  398. }
  399. .productSort .header .input .placeholder {
  400. color: #999;
  401. }
  402. .productSort .header .input .input-box {
  403. display: flex;
  404. align-items: center;
  405. font-size: 26rpx;
  406. height: 100%;
  407. width: 597rpx;
  408. color: #999999;
  409. }
  410. .productSort .aside {
  411. background-color: #fff;
  412. overflow-y: auto;
  413. overflow-x: hidden;
  414. width: 200rpx;
  415. height: 100%;
  416. overflow: hidden;
  417. }
  418. .productSort .aside .item {
  419. height: 100rpx;
  420. width: 100%;
  421. font-size: 26rpx;
  422. color: #424242;
  423. }
  424. .productSort .aside .item_text {
  425. padding-left: 20rpx;
  426. overflow: hidden;
  427. text-overflow: ellipsis;
  428. display: -webkit-box;
  429. -webkit-line-clamp: 2;
  430. -webkit-box-orient: vertical;
  431. }
  432. .productSort .aside .item.on {
  433. background-color: #f7f7f7;
  434. border-left: 4rpx solid var(--view-theme);
  435. width: 100%;
  436. text-align: center;
  437. color: var(--view-theme);
  438. font-weight: bold;
  439. }
  440. .productSort .conter {
  441. flex: 1;
  442. height: 100%;
  443. padding: 0 14rpx;
  444. background-color: #f7f7f7;
  445. }
  446. .productSort .conter .listw .title {
  447. height: 100rpx;
  448. align-items: center;
  449. }
  450. .productSort .conter .listw .title .line {
  451. width: 100rpx;
  452. height: 2rpx;
  453. background-color: #f0f0f0;
  454. }
  455. .productSort .conter .listw .title .name {
  456. font-size: 28rpx;
  457. color: #333;
  458. margin: 0 30rpx;
  459. font-weight: bold;
  460. }
  461. .productSort .conter .listw .title .list_title,
  462. .productSort .conter .listw .title uni-image,
  463. .productSort .conter .listw .title image{
  464. width: 110rpx;
  465. height: 26rpx;
  466. border-radius: 0;
  467. }
  468. .productSort .conter .list {
  469. flex-wrap: wrap;
  470. background: #fff;
  471. border-radius: 16rpx;
  472. padding-bottom: 26rpx;
  473. }
  474. .productSort .conter .list .item {
  475. width: 174rpx;
  476. margin-top: 26rpx;
  477. }
  478. .productSort .conter .list .item .picture,
  479. .productSort .conter uni-image,
  480. .productSort .conter .list .item image,
  481. /deep/.easy-loadimage{
  482. width: 110rpx;
  483. height: 110rpx;
  484. border-radius: 50%;
  485. }
  486. .productSort .conter .list .item .name {
  487. font-size: 24rpx;
  488. color: #333;
  489. height: 56rpx;
  490. line-height: 56rpx;
  491. width: 120rpx;
  492. text-align: center;
  493. }
  494. .page-footer {
  495. position: fixed;
  496. bottom: 0;
  497. z-index: 30;
  498. display: flex;
  499. align-items: center;
  500. justify-content: space-around;
  501. width: 100%;
  502. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  503. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  504. box-sizing: border-box;
  505. border-top: 1px solid #F3F3F3;
  506. background-color: #fff;
  507. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  508. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  509. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  510. .foot-item {
  511. display: flex;
  512. width: max-content;
  513. align-items: center;
  514. justify-content: center;
  515. flex-direction: column;
  516. position: relative;
  517. .count-num {
  518. position: absolute;
  519. display: flex;
  520. justify-content: center;
  521. align-items: center;
  522. width: 40rpx;
  523. height: 40rpx;
  524. top: 0rpx;
  525. right: -15rpx;
  526. color: #fff;
  527. font-size: 20rpx;
  528. background-color: #FD502F;
  529. border-radius: 50%;
  530. padding: 4rpx;
  531. }
  532. }
  533. .foot-item image {
  534. height: 50rpx;
  535. width: 50rpx;
  536. text-align: center;
  537. margin: 0 auto;
  538. }
  539. .foot-item .txt {
  540. font-size: 24rpx;
  541. }
  542. }
  543. </style>