goods_cate1.vue 8.9 KB

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