goods_cate1.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. <tabBar v-if="!is_diy" :pagePath="'/pages/goods_cate/goods_cate'"></tabBar>
  55. <view class="foot" v-if="is_diy && newData.menuList && newData.menuList.length">
  56. <view class="page-footer" id="target" :style="{'background-color':newData.bgColor.color[0].item}">
  57. <view class="foot-item" v-for="(item,index) in newData.menuList" :key="index" @click="goRouter(item)">
  58. <block v-if="item.link == activeRouter">
  59. <image :src="item.imgList[0]"></image>
  60. <view class="txt" :style="{color:newData.activeTxtColor.color[0].item}">{{$t(item.name)}}</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}">{{$t(item.name)}}</view>
  65. </block>
  66. <div class="count-num" v-if="item.link === '/pages/order_addcart/order_addcart' && cartNum > 0">
  67. {{cartNum}}
  68. </div>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  76. import {
  77. getCategoryList
  78. } from '@/api/store.js';
  79. import {
  80. mapState,
  81. mapGetters
  82. } from "vuex"
  83. import pageFooter from '@/components/pageFooter/index.vue'
  84. import {
  85. getNavigation
  86. } from '@/api/public.js'
  87. import tabBar from "@/pages/index/visualization/components/tabBar.vue";
  88. const app = getApp();
  89. export default {
  90. components: {
  91. pageFooter,
  92. tabBar
  93. },
  94. data() {
  95. return {
  96. navlist: [],
  97. productList: [],
  98. navActive: 0,
  99. number: "",
  100. is_diy: uni.getStorageSync('is_diy'),
  101. height: 0,
  102. hightArr: [],
  103. toView: "",
  104. tabbarH: 0,
  105. footH: 0,
  106. windowHeight: 0,
  107. newData: {},
  108. activeRouter: '',
  109. pageHeight: '100%',
  110. sysHeight: sysHeight,
  111. // #ifdef APP-PLUS
  112. pageHeight: app.globalData.windowHeight,
  113. // #endif
  114. lock: false
  115. }
  116. },
  117. computed: {
  118. ...mapState({
  119. cartNum: state => state.indexData.cartNum
  120. })
  121. },
  122. mounted() {
  123. let that = this
  124. // #ifdef H5
  125. uni.getSystemInfo({
  126. success: function(res) {
  127. that.pageHeight = res.windowHeight + 'px'
  128. }
  129. });
  130. // #endif
  131. let routes = getCurrentPages();
  132. let curRoute = routes[routes.length - 1].route
  133. this.activeRouter = '/' + curRoute
  134. this.getAllCategory();
  135. },
  136. methods: {
  137. getNav() {
  138. getNavigation().then(res => {
  139. this.newData = res.data
  140. })
  141. },
  142. goRouter(item) {
  143. var pages = getCurrentPages();
  144. var page = (pages[pages.length - 1]).$page.fullPath;
  145. if (item.link == page) return
  146. uni.switchTab({
  147. url: item.link,
  148. fail(err) {
  149. uni.redirectTo({
  150. url: item.link
  151. })
  152. }
  153. })
  154. },
  155. footHeight(data) {
  156. this.footH = data
  157. },
  158. infoScroll: function() {
  159. let that = this;
  160. let len = that.productList.length;
  161. this.number = that.productList[len - 1].children.length;
  162. //设置商品列表高度
  163. uni.getSystemInfo({
  164. success: function(res) {
  165. that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
  166. },
  167. });
  168. let height = 0;
  169. let hightArr = [];
  170. for (let i = 0; i < len; i++) {
  171. //获取元素所在位置
  172. let query = uni.createSelectorQuery().in(this);
  173. let idView = "#b" + i;
  174. query.select(idView).boundingClientRect();
  175. query.exec(function(res) {
  176. let top = res[0].top;
  177. hightArr.push(top);
  178. that.hightArr = hightArr
  179. });
  180. };
  181. },
  182. tap: function(index, id) {
  183. this.toView = id;
  184. this.navActive = index;
  185. this.$set(this, 'lock', true);
  186. },
  187. getAllCategory: function() {
  188. let that = this;
  189. getCategoryList().then(res => {
  190. that.productList = res.data;
  191. that.$nextTick(res => {
  192. that.infoScroll();
  193. })
  194. })
  195. },
  196. scroll: function(e) {
  197. let scrollTop = e.detail.scrollTop;
  198. let scrollArr = this.hightArr;
  199. if (this.lock) {
  200. this.$set(this, 'lock', false);
  201. return;
  202. }
  203. for (let i = 0; i < scrollArr.length; i++) {
  204. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  205. this.navActive = 0
  206. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[
  207. 0]) {
  208. this.navActive = i
  209. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  210. this.navActive = scrollArr.length - 1
  211. }
  212. }
  213. },
  214. searchSubmitValue: function(e) {
  215. if (this.$util.trim(e.detail.value).length > 0)
  216. uni.navigateTo({
  217. url: '/pages/goods/goods_list/index?searchValue=' + e.detail.value
  218. })
  219. else
  220. return this.$util.Tips({
  221. title: this.$t(`搜索商品名称`)
  222. });
  223. },
  224. }
  225. }
  226. </script>
  227. <style>
  228. page {
  229. height: 100%;
  230. }
  231. </style>
  232. <style scoped lang="scss">
  233. /deep/uni-scroll-view {
  234. padding-bottom: 0 !important;
  235. }
  236. .sys-title {
  237. z-index: 10;
  238. position: relative;
  239. height: 40px;
  240. line-height: 40px;
  241. font-size: 30rpx;
  242. color: #333;
  243. background-color: #fff;
  244. // #ifdef APP-PLUS
  245. text-align: center;
  246. // #endif
  247. // #ifdef MP
  248. text-align: left;
  249. padding-left: 30rpx;
  250. // #endif
  251. }
  252. .sys-head {
  253. background-color: #fff;
  254. }
  255. .productSort {
  256. display: flex;
  257. flex-direction: column;
  258. //#ifdef MP
  259. height: calc(100vh - var(--window-top)) !important;
  260. //#endif
  261. //#ifndef MP
  262. height: 100vh //#endif
  263. }
  264. .productSort .header {
  265. width: 100%;
  266. height: 96rpx;
  267. background-color: #fff;
  268. border-bottom: 1rpx solid #f5f5f5;
  269. }
  270. .productSort .header .input {
  271. width: 700rpx;
  272. height: 60rpx;
  273. background-color: #f5f5f5;
  274. border-radius: 50rpx;
  275. box-sizing: border-box;
  276. padding: 0 25rpx;
  277. }
  278. .productSort .header .input .iconfont {
  279. font-size: 35rpx;
  280. color: #555;
  281. }
  282. .productSort .header .input .placeholder {
  283. color: #999;
  284. }
  285. .productSort .header .input input {
  286. font-size: 26rpx;
  287. height: 100%;
  288. width: 597rpx;
  289. }
  290. .productSort .scroll-box {
  291. flex: 1;
  292. overflow: hidden;
  293. display: flex;
  294. }
  295. // #ifndef MP
  296. uni-scroll-view {
  297. padding-bottom: 100rpx;
  298. }
  299. // #endif
  300. .productSort .aside {
  301. width: 180rpx;
  302. height: 100%;
  303. overflow: hidden;
  304. background-color: #f7f7f7;
  305. }
  306. .productSort .aside .item {
  307. height: 100rpx;
  308. width: 100%;
  309. font-size: 26rpx;
  310. color: #424242;
  311. text-align: center;
  312. }
  313. .productSort .aside .item.on {
  314. background-color: #fff;
  315. border-left: 4rpx solid var(--view-theme);
  316. width: 100%;
  317. color: var(--view-theme);
  318. font-weight: bold;
  319. }
  320. .productSort .conter {
  321. flex: 1;
  322. height: 100%;
  323. overflow: hidden;
  324. padding: 0 14rpx;
  325. background-color: #fff;
  326. position: relative;
  327. }
  328. .productSort .conter .listw {
  329. padding-top: 20rpx;
  330. }
  331. .productSort .conter .listw .title {
  332. height: 90rpx;
  333. }
  334. .productSort .conter .listw .title .line {
  335. width: 100rpx;
  336. height: 2rpx;
  337. background-color: #f0f0f0;
  338. }
  339. .productSort .conter .listw .title .name {
  340. font-size: 28rpx;
  341. color: #333;
  342. margin: 0 30rpx;
  343. font-weight: bold;
  344. }
  345. .productSort .conter .list {
  346. flex-wrap: wrap;
  347. }
  348. .productSort .conter .list .item {
  349. width: 177rpx;
  350. margin-top: 26rpx;
  351. }
  352. .productSort .conter .list .item .picture {
  353. width: 120rpx;
  354. height: 120rpx;
  355. border-radius: 50%;
  356. }
  357. .productSort .conter .list .item .picture image {
  358. width: 100%;
  359. height: 100%;
  360. border-radius: 50%;
  361. }
  362. .productSort .conter .list .item .name {
  363. font-size: 24rpx;
  364. color: #333;
  365. height: 56rpx;
  366. line-height: 56rpx;
  367. width: 120rpx;
  368. text-align: center;
  369. }
  370. .page-footer {
  371. position: fixed;
  372. bottom: 0;
  373. z-index: 30;
  374. display: flex;
  375. align-items: center;
  376. justify-content: space-around;
  377. width: 100%;
  378. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  379. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  380. box-sizing: border-box;
  381. border-top: solid 1rpx #F3F3F3;
  382. background-color: #fff;
  383. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  384. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  385. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  386. .foot-item {
  387. display: flex;
  388. width: max-content;
  389. align-items: center;
  390. justify-content: center;
  391. flex-direction: column;
  392. position: relative;
  393. .count-num {
  394. position: absolute;
  395. display: flex;
  396. justify-content: center;
  397. align-items: center;
  398. width: 40rpx;
  399. height: 40rpx;
  400. top: 0rpx;
  401. right: -15rpx;
  402. color: #fff;
  403. font-size: 20rpx;
  404. background-color: #FD502F;
  405. border-radius: 50%;
  406. padding: 4rpx;
  407. }
  408. }
  409. .foot-item image {
  410. height: 50rpx;
  411. width: 50rpx;
  412. text-align: center;
  413. margin: 0 auto;
  414. }
  415. .foot-item .txt {
  416. font-size: 24rpx;
  417. &.active {}
  418. }
  419. }
  420. </style>