goods_cate1.vue 9.7 KB

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