category.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <!-- <template>
  2. <view class="content">
  3. <scroll-view scroll-y class="left-aside">
  4. <view v-for="item in flist" :key="item.id" class="f-item b-b" :class="{ active: item.id === currentId }" @click="tabtap(item)">{{ item.cate_name }}</view>
  5. </scroll-view>
  6. <scroll-view scroll-with-animation scroll-y class="right-aside" @scroll="asideScroll" :scroll-top="tabScrollTop">
  7. <view v-for="item in flist" :key="item.id" class="s-list" :id="'main-' + item.id">
  8. <text class="s-item">{{ item.cate_name }}</text>
  9. <view class="t-list ">
  10. <view @click="navToList(item.id, titem.id)" class="t-item" v-for="titem in item.children" :key="titem.id">
  11. <image :src="titem.pic"></image>
  12. <text>{{ titem.cate_name }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. </scroll-view>
  17. </view>
  18. </template>
  19. <script>
  20. import { getCategoryList } from '@/api/product.js';
  21. export default {
  22. data() {
  23. return {
  24. sizeCalcState: false,
  25. tabScrollTop: 0,
  26. currentId: 9,
  27. flist: [],
  28. };
  29. },
  30. onLoad() {
  31. this.loadData();
  32. },
  33. // 监听导航栏输入框点击事件
  34. onNavigationBarSearchInputClicked(e) {
  35. uni.navigateTo({
  36. url: '/pages/product/search'
  37. });
  38. },
  39. methods: {
  40. // 载入数据
  41. async loadData() {
  42. let obj = this;
  43. getCategoryList({})
  44. .then(({ data }) => {
  45. obj.flist = data.map(function(s) {
  46. return s;
  47. });
  48. })
  49. .catch(err => {
  50. console.log(err);
  51. });
  52. },
  53. //一级分类点击
  54. tabtap(item) {
  55. console.log(item);
  56. // 判断有没有初始化页面高度对象数据
  57. if (!this.sizeCalcState) {
  58. this.calcSize();
  59. }
  60. // 获取当前点击的id
  61. this.currentId = item.id;
  62. console.log(item.top);
  63. this.tabScrollTop = item.top;
  64. console.log(this.tabScrollTop);
  65. },
  66. //右侧栏滚动
  67. asideScroll(e) {
  68. // 判断有没有初始化页面高度对象数据
  69. if (!this.sizeCalcState) {
  70. this.calcSize();
  71. }
  72. let scrollTop = e.detail.scrollTop;
  73. let box = 0; //列表包裹框高度初始化
  74. let bottom = 10; //距离页面底部多少像素左侧列表切换到最后一个一级分类
  75. // 查询当前页面对象
  76. let view = uni.createSelectorQuery().select('.content');
  77. view.fields(
  78. {
  79. id: true,
  80. dataset: true,
  81. rect: true,
  82. size: true,
  83. scrollOffset: true
  84. },
  85. function(e) {
  86. // 保存包裹框高度
  87. box = e.height;
  88. }
  89. ).exec();
  90. // 获取所有距离顶部大于滚轮距离页面高度的所有分类
  91. let tabs = this.flist.filter(item =>( item.top-10) <= scrollTop).reverse();
  92. if (tabs.length > 0) {
  93. // 判断是否已经到达滚轮底部
  94. if (box + scrollTop + bottom >= e.detail.scrollHeight) {
  95. this.currentId = this.flist[this.flist.length - 1].id;
  96. } else {
  97. this.currentId = tabs[0].id;
  98. }
  99. }
  100. },
  101. //计算右侧栏每个tab的高度等信息
  102. calcSize() {
  103. let h = 0;
  104. this.flist.forEach(item => {
  105. let view = uni.createSelectorQuery().select('#main-' + item.id);
  106. view.fields(
  107. {
  108. size: true
  109. },
  110. data => {
  111. item.top = h;
  112. h += data.height;
  113. item.bottom = h;
  114. }
  115. ).exec();
  116. });
  117. this.sizeCalcState = true;
  118. },
  119. navToList(sid, tid) {
  120. // 点击导航跳转到详细页面
  121. uni.navigateTo({
  122. url: '/pages/product/list?fid='+this.currentId+'&sid='+sid+'&tid='+tid
  123. });
  124. }
  125. }
  126. };
  127. </script>
  128. <style lang="scss">
  129. page,
  130. .content {
  131. height: 100%;
  132. background-color: #f8f8f8;
  133. }
  134. .content {
  135. display: flex;
  136. }
  137. .left-aside {
  138. flex-shrink: 0;
  139. width: 200rpx;
  140. height: 100%;
  141. background-color: #fff;
  142. }
  143. .f-item {
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. width: 100%;
  148. height: 100rpx;
  149. font-size: 32rpx;
  150. color: $font-color-base;
  151. position: relative;
  152. &.active {
  153. color: $base-color;
  154. background: #f8f8f8;
  155. &:before {
  156. content: '';
  157. position: absolute;
  158. left: 0;
  159. top: 50%;
  160. transform: translateY(-50%);
  161. height: 36rpx;
  162. width: 8rpx;
  163. background-color: $base-color;
  164. border-radius: 0 4px 4px 0;
  165. opacity: 0.8;
  166. }
  167. }
  168. }
  169. .right-aside {
  170. flex: 1;
  171. overflow: hidden;
  172. padding-left: 20rpx;
  173. padding-right: 20rpx;
  174. }
  175. .s-item {
  176. display: flex;
  177. align-items: center;
  178. height: 70rpx;
  179. padding-top: 8rpx;
  180. font-size: 32rpx;
  181. color: $font-color-dark;
  182. }
  183. .t-list {
  184. display: flex;
  185. flex-wrap: wrap;
  186. border-radius: 15rpx;
  187. width: 100%;
  188. background: #fff;
  189. padding-top: 12rpx;
  190. &:after {
  191. content: '';
  192. flex: 99;
  193. height: 0;
  194. }
  195. }
  196. .t-item {
  197. flex-shrink: 0;
  198. display: flex;
  199. justify-content: center;
  200. align-items: center;
  201. flex-direction: column;
  202. width: 171rpx;
  203. font-size: 28rpx;
  204. color: #666;
  205. padding-bottom: 20rpx;
  206. image {
  207. width: 140rpx;
  208. height: 140rpx;
  209. }
  210. }
  211. </style> -->
  212. <template>
  213. <view class="content">
  214. <view class="dddd" style="height: 10rpx;"></view>
  215. <!-- <view class="flex cate-wrap" :style="{'height': height}">
  216. <scroll-view scroll-y="true" class="left-wrap" :style="{'height': height}">
  217. <view class="left-item" v-for="(leftitem,leftindex) in flist" :class="{'action-item': currentIndex == leftindex}" @click="leftClick(leftindex)">
  218. {{leftitem.cate_name}}
  219. </view>
  220. </scroll-view>
  221. <scroll-view scroll-y="true" class="right-wrap" :style="{'height': height}" @scrolltolower="getProducts()">
  222. <view class="right-item" v-for="gooditem in list" @click="navto('/pages/product/product?id=' + gooditem.id)">
  223. <image :src="gooditem.image" mode="" class="good-img"></image>
  224. <view class="good-info flex">
  225. <view class="good-name clamp2">
  226. {{gooditem.store_name}}
  227. </view>
  228. <view class="good-price">
  229. ¥{{gooditem.price}}
  230. </view>
  231. </view>
  232. </view>
  233. <uni-load-more :status="loadingType"></uni-load-more>
  234. </scroll-view>
  235. </view> -->
  236. <view class="hotgoods">
  237. <view class="hotgoods-item" v-for="bditem in list" :key="bditem.id"
  238. @click="navto('/pages/product/product?id=' + bditem.id )" style="height: 520rpx;">
  239. <view class="image-wrapper">
  240. <image class="image" :src="bditem.image" mode="scaleToFill"></image>
  241. </view>
  242. <view class="flex" style="flex-direction: column;justify-content: space-between;align-items: flex-start;height: 170rpx;">
  243. <view class="title clamp2">{{bditem.store_name}}</view>
  244. <view class="hot-price">
  245. <view class="price">
  246. <text class="font-size-sm"></text>
  247. <text>¥{{ bditem.price * 1 }}</text>
  248. <text class="give-jf" v-if="bditem.give_consumption*1">赠{{bditem.give_consumption*1}}消费余额</text>
  249. <!-- <text class="ot-pirce">¥{{bditem.ot_price}}</text> -->
  250. </view>
  251. </view>
  252. </view>
  253. </view>
  254. </view>
  255. <uni-load-more :status="loadingType"></uni-load-more>
  256. </view>
  257. </template>
  258. <script>
  259. import { getCategoryList,getProducts } from '@/api/product.js';
  260. export default {
  261. data() {
  262. return {
  263. sizeCalcState: false,
  264. tabScrollTop: 0,
  265. currentId: 9,
  266. flist: [],
  267. height: '',
  268. currentIndex: 0,
  269. list: [],
  270. page: 1,
  271. limit: 20,
  272. loadingType: 'more',
  273. loaded: false,
  274. };
  275. },
  276. onLoad() {
  277. this.loadData();
  278. },
  279. // 监听导航栏输入框点击事件
  280. onNavigationBarSearchInputClicked(e) {
  281. uni.navigateTo({
  282. url: '/pages/product/search'
  283. });
  284. },
  285. onReady(res) {
  286. },
  287. onReachBottom() {
  288. this.getProducts()
  289. },
  290. methods: {
  291. leftClick(index) {
  292. this.currentIndex = index
  293. this.getProducts('reload')
  294. },
  295. getProducts(type) {
  296. if(type == 'reload') {
  297. this.list = []
  298. this.page = 1
  299. this.loadingType = 'more'
  300. this.loaded = false
  301. }
  302. if(this.loadingType == 'loading' || this.loadingType == 'noMore') {
  303. return
  304. }
  305. this.loadingType = 'loading'
  306. getProducts({
  307. // cid: index,
  308. page: this.page,
  309. limit: this.limit,
  310. mall_type: 2
  311. }).then(res => {
  312. this.list = this.list.concat(res.data)
  313. this.page++
  314. if(this.limit == res.data.length) {
  315. this.loadingType = 'more'
  316. }else {
  317. this.loadingType = 'noMore'
  318. }
  319. this.loaded = true
  320. })
  321. },
  322. // 载入数据
  323. async loadData() {
  324. let obj = this;
  325. obj.getProducts()
  326. // getCategoryList({})
  327. // .then(({ data }) => {
  328. // obj.flist = data.map(function(s) {
  329. // return s;
  330. // });
  331. // obj.getProducts()
  332. // })
  333. // .catch(err => {
  334. // console.log(err);
  335. // });
  336. },
  337. //一级分类点击
  338. tabtap(item) {
  339. console.log(item);
  340. // 判断有没有初始化页面高度对象数据
  341. if (!this.sizeCalcState) {
  342. this.calcSize();
  343. }
  344. // 获取当前点击的id
  345. this.currentId = item.id;
  346. console.log(item.top);
  347. this.tabScrollTop = item.top;
  348. console.log(this.tabScrollTop);
  349. },
  350. //右侧栏滚动
  351. asideScroll(e) {
  352. // 判断有没有初始化页面高度对象数据
  353. if (!this.sizeCalcState) {
  354. this.calcSize();
  355. }
  356. let scrollTop = e.detail.scrollTop;
  357. let box = 0; //列表包裹框高度初始化
  358. let bottom = 10; //距离页面底部多少像素左侧列表切换到最后一个一级分类
  359. // 查询当前页面对象
  360. let view = uni.createSelectorQuery().select('.content');
  361. view.fields(
  362. {
  363. id: true,
  364. dataset: true,
  365. rect: true,
  366. size: true,
  367. scrollOffset: true
  368. },
  369. function(e) {
  370. // 保存包裹框高度
  371. box = e.height;
  372. }
  373. ).exec();
  374. // 获取所有距离顶部大于滚轮距离页面高度的所有分类
  375. let tabs = this.flist.filter(item =>( item.top-10) <= scrollTop).reverse();
  376. if (tabs.length > 0) {
  377. // 判断是否已经到达滚轮底部
  378. if (box + scrollTop + bottom >= e.detail.scrollHeight) {
  379. this.currentId = this.flist[this.flist.length - 1].id;
  380. } else {
  381. this.currentId = tabs[0].id;
  382. }
  383. }
  384. },
  385. //计算右侧栏每个tab的高度等信息
  386. calcSize() {
  387. let h = 0;
  388. this.flist.forEach(item => {
  389. let view = uni.createSelectorQuery().select('#main-' + item.id);
  390. view.fields(
  391. {
  392. size: true
  393. },
  394. data => {
  395. item.top = h;
  396. h += data.height;
  397. item.bottom = h;
  398. }
  399. ).exec();
  400. });
  401. this.sizeCalcState = true;
  402. },
  403. navToList(sid, tid) {
  404. // 点击导航跳转到详细页面
  405. uni.navigateTo({
  406. url: '/pages/product/list?fid='+this.currentId+'&sid='+sid+'&tid='+tid
  407. });
  408. },
  409. navto(url) {
  410. uni.navigateTo({
  411. url
  412. })
  413. }
  414. }
  415. };
  416. </script>
  417. <style lang="scss">
  418. .cate-wrap {
  419. width:750rpx;
  420. .left-wrap {
  421. width: 180rpx;
  422. flex-shrink: 0;
  423. background-color: #f2f2f2;
  424. .left-item {
  425. width: 180rpx;
  426. height: 100rpx;
  427. line-height: 100rpx;
  428. font-size: 28rpx;
  429. font-weight: 500;
  430. color: #666666;
  431. text-align: center;
  432. }
  433. .action-item {
  434. background-color: #fff;
  435. font-weight: bold;
  436. position: relative;
  437. &::before {
  438. content: '';
  439. position: absolute;
  440. top: 0;
  441. left: 0;
  442. width: 3rpx;
  443. height: 100rpx;
  444. background: #FF7144;
  445. }
  446. }
  447. }
  448. .right-wrap {
  449. flex-wrap: 1;
  450. background-color: #fff;
  451. .right-item {
  452. width: 520rpx;
  453. height: 240rpx;
  454. padding: 30rpx 0;
  455. margin: 0 auto ;
  456. border-bottom: 1px solid #eee;
  457. display: flex;
  458. justify-content: flex-start;
  459. align-items: center;
  460. .good-img {
  461. width: 180rpx;
  462. height: 180rpx;
  463. border-radius: 20rpx;
  464. }
  465. .good-info {
  466. flex-direction: column;
  467. justify-content: space-between;
  468. align-items: flex-start;
  469. height: 100%;
  470. padding-left: 25rpx;
  471. .good-name {
  472. font-size: 30rpx;
  473. font-weight: bold;
  474. color: #333333;
  475. }
  476. .good-price {
  477. font-size: 34rpx;
  478. font-weight: bold;
  479. color: #FF4C4C;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. .hotgoods {
  486. margin-top: 20rpx;
  487. width: 100%;
  488. display: flex;
  489. flex-wrap: wrap;
  490. padding: 0 20rpx 30rpx;
  491. justify-content: space-between;
  492. .hotgoods-item {
  493. width: 345rpx;
  494. background-color: #ffffff;
  495. border-radius: 12rpx;
  496. box-shadow: 0 0 15rpx rgba(0, 0, 0, 0.2);
  497. margin-bottom: 15rpx;
  498. .image-wrapper {
  499. width: 345rpx;
  500. height: 345rpx;
  501. border-radius: 3px;
  502. overflow: hidden;
  503. position: relative;
  504. .image-bg {
  505. position: absolute;
  506. top: 0;
  507. left: 0;
  508. right: 0;
  509. bottom: 0;
  510. width: 100%;
  511. height: 100%;
  512. opacity: 1;
  513. border-radius: 12rpx 12rpx 0 0;
  514. z-index: 2;
  515. }
  516. .image {
  517. width: 100%;
  518. height: 100%;
  519. opacity: 1;
  520. border-radius: 12rpx 12rpx 0 0;
  521. }
  522. }
  523. .title {
  524. margin-top: 24rpx;
  525. padding: 0 20rpx;
  526. font-size: 32rpx;
  527. font-weight: 500;
  528. color: #333333;
  529. }
  530. .hot-price {
  531. display: flex;
  532. justify-content: flex-start;
  533. align-items: center;
  534. // padding: 14rpx 0 30rpx;
  535. .hotPrice-box {
  536. padding: 2rpx 6rpx;
  537. background: linear-gradient(90deg, #c79a4c, #f9df7f);
  538. border-radius: 5rpx;
  539. text-align: center;
  540. line-height: 28rpx;
  541. font-size: 20rpx;
  542. font-family: Source Han Sans CN;
  543. font-weight: 400;
  544. color: #ffffff;
  545. }
  546. .price {
  547. margin-left: 10rpx;
  548. font-size: 36rpx;
  549. color: #ff0000;
  550. font-weight: 500;
  551. display: flex;
  552. justify-content: flex-start;
  553. align-items: center;
  554. .jf {
  555. font-size: 20rpx;
  556. }
  557. .give-jf {
  558. display: inline-block;
  559. padding: 8rpx;
  560. background: linear-gradient(90deg, #FF834D, #FF2600);
  561. border-radius: 12rpx 0px 12rpx 0px;
  562. font-size: 22rpx;
  563. font-weight: 500;
  564. color: #FFFFFF;
  565. margin-left: 22rpx;
  566. }
  567. .ot-pirce {
  568. margin-left:10rpx;
  569. font-size: 26rpx;
  570. font-weight: 500;
  571. text-decoration: line-through;
  572. color: #999999;
  573. align-self: flex-end;
  574. }
  575. }
  576. .yuanPrice {
  577. margin-left: 10rpx;
  578. font-size: 20rpx;
  579. font-family: PingFang SC;
  580. font-weight: 500;
  581. text-decoration: line-through;
  582. color: #999999;
  583. }
  584. .cart-icon {
  585. image {
  586. width: 44rpx;
  587. height: 44rpx;
  588. }
  589. }
  590. }
  591. }
  592. }
  593. .ot-pirce {
  594. margin-left: 7rpx;
  595. font-size: 26rpx;
  596. font-weight: 500;
  597. text-decoration: line-through;
  598. color: #999999;
  599. align-self: flex-end;
  600. }
  601. </style>