goods_cate1.vue 9.0 KB

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