goods_cate1.vue 9.8 KB

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