goods_cate1.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <template>
  2. <view class='productSort copy-data' :style="{height:pageHeight}">
  3. <!-- #ifdef APP-PLUS || MP -->
  4. <!-- <view class="sys-head" :style="{height:sysHeight}"></view> -->
  5. <!-- #endif -->
  6. <view class='header acea-row row-center-wrapper'>
  7. <view class='acea-row row-between-wrapper input'>
  8. <text class='iconfont icon-sousuo'></text>
  9. <input type='text' :placeholder="$t('搜索商品名称')" @confirm="searchSubmitValue" confirm-type='search'
  10. name="search" placeholder-class='placeholder'></input>
  11. </view>
  12. </view>
  13. <view class="scroll-box">
  14. <view class='aside'>
  15. <scroll-view scroll-y="true" scroll-with-animation='true' style="height: calc(100% - 100rpx)">
  16. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""'
  17. v-for="(item,index) in productList" :key="index" @click='tap(index,"b"+index)'>
  18. <text>{{$t(item.cate_name)}}</text>
  19. </view>
  20. <!-- #ifdef APP-PLUS -->
  21. <view class="item" v-if="newData.status && newData.status.status"></view>
  22. <!-- #endif -->
  23. </scroll-view>
  24. </view>
  25. <view class='conter'>
  26. <scroll-view scroll-y="true" :scroll-into-view="toView" @scroll="scroll" scroll-with-animation='true'
  27. style="height: 100%;" class="conterScroll">
  28. <block v-for="(item,index) in productList" :key="index">
  29. <view class='listw' :id="'b'+index">
  30. <view class='title acea-row row-center-wrapper'>
  31. <view class='line'></view>
  32. <view class='name'>{{$t(item.cate_name)}}</view>
  33. <view class='line'></view>
  34. </view>
  35. <view class='list acea-row'>
  36. <block v-for="(itemn,indexn) in item.children" :key="indexn">
  37. <navigator hover-class='none'
  38. :url='"/pages/goods/goods_list/index?sid="+itemn.id+"&title="+itemn.cate_name'
  39. class='item acea-row row-column row-middle'>
  40. <view class='picture'>
  41. <image :src='itemn.pic' v-if="itemn.pic"></image>
  42. <image src="/static/images/sort-img.png" v-else></image>
  43. </view>
  44. <view class='name line1'>{{$t(itemn.cate_name)}}</view>
  45. </navigator>
  46. </block>
  47. </view>
  48. </view>
  49. </block>
  50. <view :style='"height:"+(height-300)+"rpx;"' v-if="number<15"></view>
  51. </scroll-view>
  52. </view>
  53. </view>
  54. <view class="foot" v-if="is_diy && newData.status && newData.status.status">
  55. <view class="page-footer" id="target" :style="{'background-color':newData.bgColor.color[0].item}">
  56. <view class="foot-item" v-for="(item,index) in newData.menuList" :key="index" @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}">{{$t(item.name)}}</view>
  60. </block>
  61. <block v-else>
  62. <image :src="item.imgList[1]"></image>
  63. <view class="txt" :style="{color:newData.txtColor.color[0].item}">{{$t(item.name)}}</view>
  64. </block>
  65. <div class="count-num" v-if="item.link === '/pages/order_addcart/order_addcart' && cartNum > 0">
  66. {{cartNum}}
  67. </div>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  75. import {
  76. getCategoryList
  77. } from '@/api/store.js';
  78. import {
  79. mapState,
  80. mapGetters
  81. } from "vuex"
  82. import pageFooter from '@/components/pageFooter/index.vue'
  83. import {
  84. getNavigation
  85. } from '@/api/public.js'
  86. const app = getApp();
  87. export default {
  88. components: {
  89. pageFooter
  90. },
  91. data() {
  92. return {
  93. navlist: [],
  94. productList: [],
  95. navActive: 0,
  96. number: "",
  97. is_diy: uni.getStorageSync('is_diy'),
  98. height: 0,
  99. hightArr: [],
  100. toView: "",
  101. tabbarH: 0,
  102. footH: 0,
  103. windowHeight: 0,
  104. newData: {},
  105. activeRouter: '',
  106. pageHeight: '100%',
  107. sysHeight: sysHeight,
  108. // #ifdef APP-PLUS
  109. pageHeight: app.globalData.windowHeight,
  110. // #endif
  111. footerStatus: false,
  112. lock: false
  113. }
  114. },
  115. computed: {
  116. ...mapState({
  117. cartNum: state => state.indexData.cartNum
  118. })
  119. },
  120. mounted() {
  121. let that = this
  122. let routes = getCurrentPages();
  123. let curRoute = routes[routes.length - 1].route
  124. this.activeRouter = '/' + curRoute
  125. this.getAllCategory();
  126. // #ifdef H5
  127. uni.getSystemInfo({
  128. success: function(res) {
  129. that.pageHeight = res.windowHeight + 'px'
  130. }
  131. });
  132. // #endif
  133. },
  134. methods: {
  135. getNav() {
  136. let res = {
  137. "name": "pageFoot",
  138. "setUp": {
  139. "tabVal": 0
  140. },
  141. "status": {
  142. "title": "是否自定义",
  143. "name": "status",
  144. "status": true
  145. },
  146. "txtColor": {
  147. "title": "文字颜色",
  148. "name": "txtColor",
  149. "default": [
  150. {
  151. "item": "#282828"
  152. }
  153. ],
  154. "color": [
  155. {
  156. "item": "rgba(51,51,51,1)"
  157. }
  158. ]
  159. },
  160. "activeTxtColor": {
  161. "title": "选中文字颜色",
  162. "name": "txtColor",
  163. "default": [
  164. {
  165. "item": "#F62C2C"
  166. }
  167. ],
  168. "color": [
  169. {
  170. "item": "rgba(29,176,252,1)"
  171. }
  172. ]
  173. },
  174. "bgColor": {
  175. "title": "背景颜色",
  176. "name": "bgColor",
  177. "default": [
  178. {
  179. "item": "#fff"
  180. }
  181. ],
  182. "color": [
  183. {
  184. "item": "#fff"
  185. }
  186. ]
  187. },
  188. "menuList": [
  189. {
  190. "imgList": [
  191. "https://qiniu.crmeb.net/attach/2021/11/bdf25202111181452426458.png",
  192. "https://qiniu.crmeb.net/attach/2021/11/aaf1b202111181452576658.png"
  193. ],
  194. "name": "首页",
  195. "link": "/pages/index/index"
  196. },
  197. {
  198. "imgList": [
  199. "https://demo26.crmeb.net/uploads/attach/2022/09/20220923/14367a2fecd502f51978ed6ea09afe19.png",
  200. "https://qiniu.crmeb.net/attach/2021/11/59d4a202111181453208678.png"
  201. ],
  202. "name": "分类",
  203. "link": "/pages/goods_cate/goods_cate"
  204. },
  205. {
  206. "imgList": [
  207. "https://qiniu.crmeb.net/attach/2021/11/076ac202111181453294517.png",
  208. "https://qiniu.crmeb.net/attach/2021/11/201c9202111181453378599.png"
  209. ],
  210. "name": "购物车",
  211. "link": "/pages/order_addcart/order_addcart"
  212. },
  213. {
  214. "imgList": [
  215. "https://qiniu.crmeb.net/attach/2021/11/f04cf20211118145343755.png",
  216. "https://qiniu.crmeb.net/attach/2021/11/3a141202111181453495771.png"
  217. ],
  218. "name": "我的",
  219. "link": "/pages/user/index"
  220. }
  221. ],
  222. "id": "idundefined"
  223. }
  224. // getNavigation().then(res => {
  225. this.newData = res
  226. if (this.newData.status && this.newData.status.status) {
  227. uni.hideTabBar()
  228. } else {
  229. uni.showTabBar()
  230. }
  231. // })
  232. },
  233. goRouter(item) {
  234. var pages = getCurrentPages();
  235. var page = (pages[pages.length - 1]).$page.fullPath;
  236. if (item.link == page) return
  237. uni.switchTab({
  238. url: item.link,
  239. fail(err) {
  240. uni.redirectTo({
  241. url: item.link
  242. })
  243. }
  244. })
  245. },
  246. footHeight(data) {
  247. this.footH = data
  248. },
  249. infoScroll: function() {
  250. let that = this;
  251. let len = that.productList.length;
  252. this.number = that.productList[len - 1].children.length;
  253. //设置商品列表高度
  254. uni.getSystemInfo({
  255. success: function(res) {
  256. that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
  257. },
  258. });
  259. let height = 0;
  260. let hightArr = [];
  261. for (let i = 0; i < len; i++) {
  262. //获取元素所在位置
  263. let query = uni.createSelectorQuery().in(this);
  264. let idView = "#b" + i;
  265. query.select(idView).boundingClientRect();
  266. query.exec(function(res) {
  267. let top = res[0].top;
  268. hightArr.push(top);
  269. that.hightArr = hightArr
  270. });
  271. };
  272. },
  273. tap: function(index, id) {
  274. this.toView = id;
  275. this.navActive = index;
  276. this.$set(this, 'lock', true);
  277. },
  278. getAllCategory: function() {
  279. let that = this;
  280. getCategoryList().then(res => {
  281. that.productList = res.data;
  282. that.$nextTick(res => {
  283. that.infoScroll();
  284. })
  285. })
  286. },
  287. scroll: function(e) {
  288. let scrollTop = e.detail.scrollTop;
  289. let scrollArr = this.hightArr;
  290. if (this.lock) {
  291. this.$set(this, 'lock', false);
  292. return;
  293. }
  294. for (let i = 0; i < scrollArr.length; i++) {
  295. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  296. this.navActive = 0
  297. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[
  298. 0]) {
  299. this.navActive = i
  300. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  301. this.navActive = scrollArr.length - 1
  302. }
  303. }
  304. },
  305. searchSubmitValue: function(e) {
  306. if (this.$util.trim(e.detail.value).length > 0)
  307. uni.navigateTo({
  308. url: '/pages/goods/goods_list/index?searchValue=' + e.detail.value
  309. })
  310. else
  311. return this.$util.Tips({
  312. title: this.$t(`搜索商品名称`)
  313. });
  314. },
  315. }
  316. }
  317. </script>
  318. <style>
  319. page {
  320. height: 100%;
  321. }
  322. </style>
  323. <style scoped lang="scss">
  324. /deep/uni-scroll-view {
  325. padding-bottom: 0 !important;
  326. }
  327. .sys-title {
  328. z-index: 10;
  329. position: relative;
  330. height: 40px;
  331. line-height: 40px;
  332. font-size: 30rpx;
  333. color: #333;
  334. background-color: #fff;
  335. // #ifdef APP-PLUS
  336. text-align: center;
  337. // #endif
  338. // #ifdef MP
  339. text-align: left;
  340. padding-left: 30rpx;
  341. // #endif
  342. }
  343. .sys-head {
  344. background-color: #fff;
  345. }
  346. .productSort {
  347. display: flex;
  348. flex-direction: column;
  349. //#ifdef MP
  350. height: calc(100vh - var(--window-top)) !important;
  351. //#endif
  352. //#ifndef MP
  353. height: 100vh //#endif
  354. }
  355. .productSort .header {
  356. width: 100%;
  357. height: 96rpx;
  358. background-color: #fff;
  359. border-bottom: 1rpx solid #f5f5f5;
  360. }
  361. .productSort .header .input {
  362. width: 700rpx;
  363. height: 60rpx;
  364. background-color: #f5f5f5;
  365. border-radius: 50rpx;
  366. box-sizing: border-box;
  367. padding: 0 25rpx;
  368. }
  369. .productSort .header .input .iconfont {
  370. font-size: 35rpx;
  371. color: #555;
  372. }
  373. .productSort .header .input .placeholder {
  374. color: #999;
  375. }
  376. .productSort .header .input input {
  377. font-size: 26rpx;
  378. height: 100%;
  379. width: 597rpx;
  380. }
  381. .productSort .scroll-box {
  382. flex: 1;
  383. overflow: hidden;
  384. display: flex;
  385. }
  386. // #ifndef MP
  387. uni-scroll-view {
  388. padding-bottom: 100rpx;
  389. }
  390. // #endif
  391. .productSort .aside {
  392. width: 180rpx;
  393. height: 100%;
  394. overflow: hidden;
  395. background-color: #f7f7f7;
  396. }
  397. .productSort .aside .item {
  398. height: 100rpx;
  399. width: 100%;
  400. font-size: 26rpx;
  401. color: #424242;
  402. text-align: center;
  403. }
  404. .productSort .aside .item.on {
  405. background-color: #fff;
  406. border-left: 4rpx solid var(--view-theme);
  407. width: 100%;
  408. color: var(--view-theme);
  409. font-weight: bold;
  410. }
  411. .productSort .conter {
  412. flex: 1;
  413. height: 100%;
  414. overflow: hidden;
  415. padding: 0 14rpx;
  416. background-color: #fff;
  417. position: relative;
  418. }
  419. .productSort .conter .listw {
  420. padding-top: 20rpx;
  421. }
  422. .productSort .conter .listw .title {
  423. height: 90rpx;
  424. }
  425. .productSort .conter .listw .title .line {
  426. width: 100rpx;
  427. height: 2rpx;
  428. background-color: #f0f0f0;
  429. }
  430. .productSort .conter .listw .title .name {
  431. font-size: 28rpx;
  432. color: #333;
  433. margin: 0 30rpx;
  434. font-weight: bold;
  435. }
  436. .productSort .conter .list {
  437. flex-wrap: wrap;
  438. }
  439. .productSort .conter .list .item {
  440. width: 177rpx;
  441. margin-top: 26rpx;
  442. }
  443. .productSort .conter .list .item .picture {
  444. width: 120rpx;
  445. height: 120rpx;
  446. border-radius: 50%;
  447. }
  448. .productSort .conter .list .item .picture image {
  449. width: 100%;
  450. height: 100%;
  451. border-radius: 50%;
  452. }
  453. .productSort .conter .list .item .name {
  454. font-size: 24rpx;
  455. color: #333;
  456. height: 56rpx;
  457. line-height: 56rpx;
  458. width: 120rpx;
  459. text-align: center;
  460. }
  461. .page-footer {
  462. position: fixed;
  463. bottom: 0;
  464. z-index: 30;
  465. display: flex;
  466. align-items: center;
  467. justify-content: space-around;
  468. width: 100%;
  469. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  470. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  471. box-sizing: border-box;
  472. border-top: solid 1rpx #F3F3F3;
  473. background-color: #fff;
  474. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  475. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  476. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  477. .foot-item {
  478. display: flex;
  479. width: max-content;
  480. align-items: center;
  481. justify-content: center;
  482. flex-direction: column;
  483. position: relative;
  484. .count-num {
  485. position: absolute;
  486. display: flex;
  487. justify-content: center;
  488. align-items: center;
  489. width: 40rpx;
  490. height: 40rpx;
  491. top: 0rpx;
  492. right: -15rpx;
  493. color: #fff;
  494. font-size: 20rpx;
  495. background-color: #FD502F;
  496. border-radius: 50%;
  497. padding: 4rpx;
  498. }
  499. }
  500. .foot-item image {
  501. height: 50rpx;
  502. width: 50rpx;
  503. text-align: center;
  504. margin: 0 auto;
  505. }
  506. .foot-item .txt {
  507. font-size: 24rpx;
  508. &.active {}
  509. }
  510. }
  511. </style>