goods_cate1.vue 9.5 KB

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