goods_cate1.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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/2-002.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. },
  193. getAllCategory: function(type) {
  194. let that = this;
  195. if (type || !uni.getStorageSync('CAT1_DATA')) {
  196. getCategoryList().then(res => {
  197. uni.setStorageSync('CAT1_DATA', res.data)
  198. that.productList = res.data;
  199. that.$nextTick(res => {
  200. that.infoScroll();
  201. })
  202. })
  203. } else {
  204. that.productList = uni.getStorageSync('CAT1_DATA')
  205. that.$nextTick(res => {
  206. that.infoScroll();
  207. })
  208. }
  209. },
  210. scroll: function(e) {
  211. let scrollTop = e.detail.scrollTop;
  212. let scrollArr = this.hightArr;
  213. if (this.lock) {
  214. this.$set(this, 'lock', false);
  215. return;
  216. }
  217. for (let i = 0; i < scrollArr.length; i++) {
  218. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  219. this.navActive = 0
  220. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[
  221. 0]) {
  222. this.navActive = i
  223. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  224. this.navActive = scrollArr.length - 1
  225. }
  226. }
  227. uni.$emit('scroll');
  228. },
  229. searchSubmitValue: function(e) {
  230. if (this.$util.trim(e.detail.value).length > 0)
  231. uni.navigateTo({
  232. url: '/pages/goods/goods_list/index?searchValue=' + e.detail.value
  233. })
  234. else
  235. return this.$util.Tips({
  236. title: this.$t(`搜索商品名称`)
  237. });
  238. },
  239. }
  240. }
  241. </script>
  242. <style>
  243. page {
  244. height: 100%;
  245. }
  246. </style>
  247. <style scoped lang="scss">
  248. /deep/uni-scroll-view {
  249. padding-bottom: 0 !important;
  250. }
  251. .sys-title {
  252. z-index: 10;
  253. position: relative;
  254. height: 40px;
  255. line-height: 40px;
  256. font-size: 30rpx;
  257. color: #333;
  258. background-color: #fff;
  259. // #ifdef APP-PLUS
  260. text-align: center;
  261. // #endif
  262. // #ifdef MP
  263. text-align: left;
  264. padding-left: 30rpx;
  265. // #endif
  266. }
  267. .sys-head {
  268. background-color: #fff;
  269. }
  270. .productSort {
  271. display: flex;
  272. flex-direction: column;
  273. //#ifdef MP
  274. height: calc(100vh - var(--window-top)) !important;
  275. //#endif
  276. //#ifndef MP
  277. height: 100vh //#endif
  278. }
  279. .productSort .header {
  280. width: 100%;
  281. height: 96rpx;
  282. background-color: #fff;
  283. border-bottom: 1rpx solid #f5f5f5;
  284. }
  285. .productSort .header .input {
  286. width: 700rpx;
  287. height: 60rpx;
  288. background-color: #f5f5f5;
  289. border-radius: 50rpx;
  290. box-sizing: border-box;
  291. padding: 0 25rpx;
  292. }
  293. .productSort .header .input .iconfont {
  294. font-size: 35rpx;
  295. color: #555;
  296. }
  297. .productSort .header .input .placeholder {
  298. color: #999;
  299. }
  300. .productSort .header .input input {
  301. font-size: 26rpx;
  302. height: 100%;
  303. width: 597rpx;
  304. }
  305. .productSort .scroll-box {
  306. flex: 1;
  307. overflow: hidden;
  308. display: flex;
  309. }
  310. // #ifndef MP
  311. uni-scroll-view {
  312. padding-bottom: 100rpx;
  313. }
  314. // #endif
  315. .productSort .aside {
  316. width: 180rpx;
  317. height: 100%;
  318. overflow: hidden;
  319. background-color: #f7f7f7;
  320. }
  321. .productSort .aside .item {
  322. height: 100rpx;
  323. width: 100%;
  324. font-size: 26rpx;
  325. color: #424242;
  326. text-align: center;
  327. }
  328. .productSort .aside .item.on {
  329. background-color: #fff;
  330. border-left: 4rpx solid var(--view-theme);
  331. width: 100%;
  332. color: var(--view-theme);
  333. font-weight: bold;
  334. }
  335. .productSort .conter {
  336. flex: 1;
  337. height: 100%;
  338. overflow: hidden;
  339. padding: 0 14rpx;
  340. background-color: #fff;
  341. position: relative;
  342. padding-bottom: 200rpx;
  343. }
  344. .productSort .conter .listw {
  345. padding-top: 20rpx;
  346. }
  347. .productSort .conter .listw .title {
  348. height: 90rpx;
  349. }
  350. .productSort .conter .listw .title .line {
  351. width: 100rpx;
  352. height: 2rpx;
  353. background-color: #f0f0f0;
  354. }
  355. .productSort .conter .listw .title .name {
  356. font-size: 28rpx;
  357. color: #333;
  358. margin: 0 30rpx;
  359. font-weight: bold;
  360. }
  361. .productSort .conter .list {
  362. flex-wrap: wrap;
  363. }
  364. .productSort .conter .list .item {
  365. width: 177rpx;
  366. margin-top: 26rpx;
  367. }
  368. .productSort .conter .list .item .picture {
  369. width: 120rpx;
  370. height: 120rpx;
  371. border-radius: 50%;
  372. }
  373. // .productSort .conter .list .item .picture image {
  374. // width: 100%;
  375. // height: 100%;
  376. // border-radius: 50%;
  377. // }
  378. .productSort .conter .list .item .picture {
  379. /deep/,
  380. /deep/image,
  381. /deep/.easy-loadimage,
  382. /deep/uni-image {
  383. width: 120rpx;
  384. height: 120rpx;
  385. border-radius: 50%;
  386. }
  387. }
  388. .productSort .conter .list .item .name {
  389. font-size: 24rpx;
  390. color: #333;
  391. height: 56rpx;
  392. line-height: 56rpx;
  393. width: 120rpx;
  394. text-align: center;
  395. }
  396. </style>