goods_cate1.vue 9.7 KB

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