goods_cate1.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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(1);
  125. },
  126. watch: {
  127. isNew(newVal) {
  128. this.getAllCategory(1);
  129. }
  130. },
  131. methods: {
  132. getNav() {
  133. getNavigation().then(res => {
  134. this.newData = res.data
  135. })
  136. },
  137. goRouter(item) {
  138. var pages = getCurrentPages();
  139. var page = (pages[pages.length - 1]).$page.fullPath;
  140. if (item.link == page) return
  141. uni.switchTab({
  142. url: item.link,
  143. fail(err) {
  144. uni.redirectTo({
  145. url: item.link
  146. })
  147. }
  148. })
  149. },
  150. footHeight(data) {
  151. this.footH = data
  152. },
  153. infoScroll: function() {
  154. let that = this;
  155. let len = that.productList.length;
  156. this.number = that.productList[len - 1].children.length;
  157. //设置商品列表高度
  158. uni.getSystemInfo({
  159. success: function(res) {
  160. that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
  161. },
  162. });
  163. let height = 0;
  164. let hightArr = [];
  165. for (let i = 0; i < len; i++) {
  166. //获取元素所在位置
  167. let query = uni.createSelectorQuery().in(this);
  168. let idView = "#b" + i;
  169. query.select(idView).boundingClientRect();
  170. query.exec(function(res) {
  171. let top = res[0].top;
  172. hightArr.push(top);
  173. that.hightArr = hightArr
  174. });
  175. };
  176. },
  177. tap: function(index, id) {
  178. this.toView = id;
  179. this.navActive = index;
  180. this.$set(this, 'lock', true);
  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>
  232. page {
  233. height: 100%;
  234. }
  235. </style>
  236. <style scoped lang="scss">
  237. /deep/uni-scroll-view {
  238. padding-bottom: 0 !important;
  239. }
  240. .sys-title {
  241. z-index: 10;
  242. position: relative;
  243. height: 40px;
  244. line-height: 40px;
  245. font-size: 30rpx;
  246. color: #333;
  247. background-color: #fff;
  248. // #ifdef APP-PLUS
  249. text-align: center;
  250. // #endif
  251. // #ifdef MP
  252. text-align: left;
  253. padding-left: 30rpx;
  254. // #endif
  255. }
  256. .sys-head {
  257. background-color: #fff;
  258. }
  259. .productSort {
  260. display: flex;
  261. flex-direction: column;
  262. //#ifdef MP
  263. height: calc(100vh - var(--window-top)) !important;
  264. //#endif
  265. //#ifndef MP
  266. height: 100vh //#endif
  267. }
  268. .productSort .header {
  269. width: 100%;
  270. height: 96rpx;
  271. background-color: #fff;
  272. border-bottom: 1rpx solid #f5f5f5;
  273. }
  274. .productSort .header .input {
  275. width: 700rpx;
  276. height: 60rpx;
  277. background-color: #f5f5f5;
  278. border-radius: 50rpx;
  279. box-sizing: border-box;
  280. padding: 0 25rpx;
  281. }
  282. .productSort .header .input .iconfont {
  283. font-size: 35rpx;
  284. color: #555;
  285. }
  286. .productSort .header .input .placeholder {
  287. color: #999;
  288. }
  289. .productSort .header .input input {
  290. font-size: 26rpx;
  291. height: 100%;
  292. width: 597rpx;
  293. }
  294. .productSort .scroll-box {
  295. flex: 1;
  296. overflow: hidden;
  297. display: flex;
  298. }
  299. // #ifndef MP
  300. uni-scroll-view {
  301. padding-bottom: 100rpx;
  302. }
  303. // #endif
  304. .productSort .aside {
  305. width: 180rpx;
  306. height: 100%;
  307. overflow: hidden;
  308. background-color: #f7f7f7;
  309. }
  310. .productSort .aside .item {
  311. height: 100rpx;
  312. width: 100%;
  313. font-size: 26rpx;
  314. color: #424242;
  315. text-align: center;
  316. }
  317. .productSort .aside .item.on {
  318. background-color: #fff;
  319. border-left: 4rpx solid var(--view-theme);
  320. width: 100%;
  321. color: var(--view-theme);
  322. font-weight: bold;
  323. }
  324. .productSort .conter {
  325. flex: 1;
  326. height: 100%;
  327. overflow: hidden;
  328. padding: 0 14rpx;
  329. background-color: #fff;
  330. position: relative;
  331. padding-bottom: 200rpx;
  332. }
  333. .productSort .conter .listw {
  334. padding-top: 20rpx;
  335. }
  336. .productSort .conter .listw .title {
  337. height: 90rpx;
  338. }
  339. .productSort .conter .listw .title .line {
  340. width: 100rpx;
  341. height: 2rpx;
  342. background-color: #f0f0f0;
  343. }
  344. .productSort .conter .listw .title .name {
  345. font-size: 28rpx;
  346. color: #333;
  347. margin: 0 30rpx;
  348. font-weight: bold;
  349. }
  350. .productSort .conter .list {
  351. flex-wrap: wrap;
  352. }
  353. .productSort .conter .list .item {
  354. width: 177rpx;
  355. margin-top: 26rpx;
  356. }
  357. .productSort .conter .list .item .picture {
  358. width: 120rpx;
  359. height: 120rpx;
  360. border-radius: 50%;
  361. }
  362. // .productSort .conter .list .item .picture image {
  363. // width: 100%;
  364. // height: 100%;
  365. // border-radius: 50%;
  366. // }
  367. .productSort .conter .list .item .picture {
  368. /deep/,
  369. /deep/image,
  370. /deep/.easy-loadimage,
  371. /deep/uni-image {
  372. width: 120rpx;
  373. height: 120rpx;
  374. border-radius: 50%;
  375. }
  376. }
  377. .productSort .conter .list .item .name {
  378. font-size: 24rpx;
  379. color: #333;
  380. height: 56rpx;
  381. line-height: 56rpx;
  382. width: 120rpx;
  383. text-align: center;
  384. }
  385. </style>