category.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <view class="container">
  3. <!-- <view class="vheigh"></view> -->
  4. <!-- 小程序头部兼容 -->
  5. <!-- 顶部logo and 搜索 start-->
  6. <view class="top-search flex">
  7. <view class="search-box flex" @click="clickSearch()">
  8. <image class="search" src="../../static/icon/search-h.png" mode=""></image>
  9. <view class="search-font"><input type="text" placeholder="输入关键词搜索" v-model="productname" /></view>
  10. </view>
  11. </view>
  12. <view class="tabbar"><image src="../../static/img/banner.png" mode=""></image></view>
  13. <!-- 精品 商品 -->
  14. <view class="scroll-view flex-tpl" :style="{ height: pageHeight }">
  15. <scroll-view scroll-y class="left-aside">
  16. <view v-for="item in flist" class="f-item" :class="{ active_top: item.id == erjiid }" @click="changeSlist(item.id)">{{ item.cate_name }}</view>
  17. </scroll-view>
  18. <scroll-view :scroll-with-animation="scrollAnimation" scroll-y class="right-aside" @scroll="loadData()">
  19. <view class="tlist-box" v-for="ls in bastList" :id="'main-' + ls.id">
  20. <view class="tlist-list flex_item" @click="navToDetailPage(ls)">
  21. <view class="tlist-img">
  22. <view class="img"><image :src="ls.image" :lazy-load="true" mode="scaleToFill"></image></view>
  23. </view>
  24. <view class="sell-out" v-if="ls.stock == 0"><text>已售罄</text></view>
  25. <view class="tlist-info">
  26. <view class="tlist-tip">
  27. <view class="ywyw">以物易物</view>
  28. <view class="bmhw">必买好物</view>
  29. </view>
  30. <view class="name ellipsis">{{ ls.store_name }}</view>
  31. <view class="tlist-price flex">
  32. <view class="price-box">
  33. <view class="price">
  34. ¥
  35. <text class="blod">{{ ls.price }}</text>
  36. <text class="fen" v-if="ls.unit_name">/{{ ls.unit_name }}</text>
  37. </view>
  38. </view>
  39. <view class="btn">立即购买</view>
  40. </view>
  41. <view class="bottom_border"></view>
  42. </view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { loadIndexs } from '@/api/index.js';
  51. import { getUserInfo } from '@/api/user.js';
  52. import { getProducts, getCategoryList } from '@/api/product.js';
  53. import { saveUrl, interceptor } from '@/utils/loginUtils.js';
  54. import { mapState } from 'vuex';
  55. export default {
  56. data() {
  57. return {
  58. scrollAnimation: true, //是否开启动画
  59. bastList: [], //精品推荐列表
  60. pageHeight: 0, //保存滚轮页面高度
  61. flist: [], //一级分类列表
  62. erjiid: '', //二级选择id
  63. page: 1,
  64. limit: 10,
  65. productname: '',
  66. loadingType: 'more' //加载更多状态
  67. };
  68. },
  69. computed: {
  70. ...mapState(['loginInterceptor']),
  71. ...mapState('user', ['hasLogin', 'userInfo'])
  72. },
  73. onReady(res) {
  74. // 初始化获取页面宽度
  75. var _this = this;
  76. uni.getSystemInfo({
  77. success: resu => {
  78. const query = uni.createSelectorQuery();
  79. query.select('.scroll-view').boundingClientRect();
  80. query.exec(function(res) {
  81. _this.pageHeight = resu.windowHeight - res[0].top + 'px';
  82. console.log('打印页面的剩余高度', _this.pageHeight);
  83. });
  84. },
  85. fail: res => {}
  86. });
  87. },
  88. onLoad: function(option) {},
  89. onShow: function() {
  90. this.productname = '';
  91. this.loadingType = 'more';
  92. this.page = 1;
  93. this.bastList = []; //精品推荐列表
  94. this.flist = [];
  95. // this.loadData();
  96. this.categoryList();
  97. },
  98. onReachBottom() {
  99. this.loadData();
  100. },
  101. methods: {
  102. categoryList() {
  103. getCategoryList({}).then(({ data }) => {
  104. data.forEach(e => {
  105. if (e.id == 9) {
  106. this.flist = e.children;
  107. this.erjiid = this.flist[0].id;
  108. console.log(this.flist, this.erjiid, 'shuj');
  109. }
  110. });
  111. this.loadData();
  112. });
  113. },
  114. changeSlist(id) {
  115. this.bastList = [];
  116. this.page = 1;
  117. this.limit = 10;
  118. this.loadingType = 'more';
  119. this.erjiid = id;
  120. this.loadData();
  121. },
  122. // 點擊搜索框
  123. clickSearch() {
  124. this.bastList = [];
  125. this.page = 1;
  126. this.limit = 10;
  127. this.loadingType = 'more';
  128. this.loadData();
  129. },
  130. // 请求载入数据
  131. async loadData() {
  132. let obj = this;
  133. if (obj.loadingType == 'nomore' || obj.loadingType == 'loading') {
  134. return;
  135. }
  136. obj.loadingType = 'loading';
  137. let data = {
  138. page: obj.page,
  139. limit: obj.limit,
  140. keyword: obj.productname,
  141. sid: obj.erjiid
  142. };
  143. getProducts(data).then(function(e) {
  144. obj.bastList = obj.bastList.concat(e.data);
  145. //判断是否还有下一页,有是more 没有是nomore
  146. if (obj.limit == e.data.length) {
  147. obj.page++;
  148. obj.loadingType = 'more';
  149. } else {
  150. obj.loadingType = 'nomore';
  151. }
  152. });
  153. },
  154. //轮播图切换修改背景色
  155. swiperChange(e) {
  156. const index = e.detail.current;
  157. this.swiperCurrent = index;
  158. this.titleNViewBackground = this.carouselList[index].background;
  159. },
  160. //详情页
  161. navToDetailPage(item) {
  162. let id = item.id;
  163. uni.navigateTo({
  164. url: '/pages/product/product?id=' + id + '&isyw=1'
  165. });
  166. },
  167. // 轮播图跳转
  168. bannerNavToUrl(item) {
  169. // #ifdef H5
  170. if (item.wap_url.indexOf('http') > 0) {
  171. window.location.href = item.wap_url;
  172. }
  173. // #endif
  174. //测试数据没有写id,用title代替
  175. uni.navigateTo({
  176. url: item.wap_url
  177. });
  178. }
  179. }
  180. };
  181. </script>
  182. <style lang="scss">
  183. page {
  184. .cate-section {
  185. position: relative;
  186. z-index: 5;
  187. border-radius: 16rpx 16rpx 0 0;
  188. margin-top: -20rpx;
  189. }
  190. }
  191. page {
  192. background: #f7f8f7;
  193. }
  194. .top-search {
  195. height: 80rpx;
  196. padding: 0 20rpx;
  197. background-color: #fff;
  198. .search-box {
  199. justify-content: center;
  200. width: 698rpx;
  201. height: 60rpx;
  202. background: #eeeeee;
  203. // box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
  204. border-radius: 30rpx;
  205. .search {
  206. width: 34rpx;
  207. height: 34rpx;
  208. }
  209. .search-font {
  210. width: 500rpx;
  211. margin-left: 14rpx;
  212. font-size: 28rpx;
  213. font-family: PingFang SC;
  214. font-weight: 500;
  215. color: #cbcbcb;
  216. }
  217. }
  218. }
  219. // 顶部轮播图
  220. .top-swiper {
  221. width: 750rpx;
  222. height: 360rpx;
  223. // margin: 20rpx 0 0;
  224. image {
  225. width: 750rpx;
  226. height: 360rpx;
  227. }
  228. }
  229. .swiper-btm {
  230. height: 60rpx;
  231. width: 750rpx;
  232. background-color: #fff;
  233. margin-bottom: 20rpx;
  234. font-size: 21rpx;
  235. font-weight: 500;
  236. color: #333333;
  237. .btm-item {
  238. flex-grow: 1;
  239. justify-content: center;
  240. image {
  241. width: 25rpx;
  242. height: 25rpx;
  243. margin-right: 14rpx;
  244. }
  245. }
  246. }
  247. .tabbar {
  248. margin: 18rpx auto 0;
  249. width: 720rpx;
  250. height: 272rpx;
  251. image {
  252. width: 100%;
  253. height: 100%;
  254. }
  255. }
  256. /* 分类 */
  257. .cate-section {
  258. display: flex;
  259. justify-content: space-around;
  260. align-items: center;
  261. flex-wrap: wrap;
  262. padding: 30rpx 22rpx;
  263. .cate-item {
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. font-size: $font-sm + 2rpx;
  268. color: $font-color-dark;
  269. }
  270. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  271. image {
  272. width: 88rpx;
  273. height: 88rpx;
  274. margin-bottom: 14rpx;
  275. border-radius: 50%;
  276. opacity: 0.7;
  277. }
  278. }
  279. /*公用边框样式*/
  280. %icon {
  281. margin-right: 10rpx;
  282. display: inline-block;
  283. padding: 2rpx 10rpx;
  284. border: 1rpx solid $color-yellow;
  285. color: $color-yellow;
  286. line-height: 1;
  287. font-size: $font-base;
  288. border-radius: 10rpx;
  289. }
  290. .vheigh {
  291. height: var(--status-bar-height);
  292. }
  293. .flex-tpl {
  294. display: flex;
  295. justify-content: space-between;
  296. }
  297. .scroll-view {
  298. margin-top: 15rpx;
  299. .left-aside {
  300. flex-shrink: 0;
  301. width: 180rpx;
  302. height: 100%;
  303. background: #f2f2f2;
  304. overflow: hidden;
  305. display: block;
  306. overflow-y: scroll;
  307. }
  308. }
  309. .f-item {
  310. display: flex;
  311. align-items: center;
  312. justify-content: center;
  313. width: 180rpx;
  314. height: 100rpx;
  315. font-size: 24rpx;
  316. color: $font-color-base;
  317. position: relative;
  318. &.active_top {
  319. background: #ffffff;
  320. font-size: 26rpx;
  321. font-weight: 500;
  322. color: rgba(51, 51, 51, 1);
  323. &:before {
  324. content: '';
  325. position: absolute;
  326. left: 0;
  327. top: 50%;
  328. transform: translateY(-50%);
  329. height: 100rpx;
  330. width: 8rpx;
  331. background-color: #fd377a;
  332. border-radius: 0 4px 4px 0;
  333. opacity: 0.8;
  334. }
  335. }
  336. }
  337. .right-aside {
  338. overflow: hidden;
  339. padding: 0rpx 20rpx;
  340. height: 100%;
  341. display: block;
  342. overflow-y: scroll;
  343. width: 100%;
  344. .image {
  345. width: 100%;
  346. padding-bottom: 15rpx;
  347. .imageLV {
  348. width: 100%;
  349. height: 200rpx;
  350. }
  351. }
  352. .tlist-box {
  353. .tlistname {
  354. font-size: 24rpx;
  355. padding: 25rpx 25rpx;
  356. border-top: 2rpx solid rgba(238, 238, 238, 1);
  357. border-bottom: 2rpx solid rgba(238, 238, 238, 1);
  358. }
  359. .tlist-list.flex_item {
  360. height: 0;
  361. min-height: 230rpx;
  362. align-items: stretch;
  363. }
  364. .tlist-list {
  365. padding: 25rpx 0rpx;
  366. position: relative;
  367. .tlist-img {
  368. width: 169rpx;
  369. position: relative;
  370. .img {
  371. width: 169rpx;
  372. height: 169rpx;
  373. image {
  374. width: 169rpx;
  375. height: 169rpx;
  376. }
  377. }
  378. .stock {
  379. margin-top: 13rpx;
  380. font-size: 26rpx;
  381. background: #fff1ee;
  382. width: 100%;
  383. color: #fb4912;
  384. padding: 6rpx 0;
  385. border-radius: 5rpx;
  386. justify-content: center;
  387. align-items: center;
  388. position: absolute;
  389. left: 0;
  390. bottom: 0;
  391. .img {
  392. width: 20rpx;
  393. height: 20rpx;
  394. flex-shrink: 0;
  395. }
  396. .stock-num {
  397. padding-left: 7rpx;
  398. font-size: 22rpx;
  399. border-radius: 5rpx;
  400. height: 32rpx;
  401. line-height: 32rpx;
  402. }
  403. }
  404. }
  405. .sell-out {
  406. position: absolute;
  407. width: 169rpx;
  408. height: 190rpx;
  409. background: rgba(255, 255, 255, 0.4);
  410. text-align: center;
  411. text {
  412. line-height: 190rpx;
  413. background: rgba(0, 0, 0, 0.5);
  414. color: #ffffff;
  415. padding: 10rpx 25rpx;
  416. border-radius: 25rpx;
  417. font-size: 20rpx;
  418. }
  419. }
  420. .tlist-info {
  421. font-size: 24rpx;
  422. width: 61%;
  423. padding-left: 25rpx;
  424. padding-right: 25rpx;
  425. position: relative;
  426. .tlist-tip {
  427. display: flex;
  428. align-items: center;
  429. .ywyw {
  430. width: 86rpx;
  431. height: 31rpx;
  432. background: linear-gradient(90deg, #fa0100 0%, #fa4716 100%);
  433. border-radius: 5rpx;
  434. text-align: center;
  435. line-height: 31rpx;
  436. font-size: 16rpx;
  437. font-family: PingFang SC;
  438. font-weight: 500;
  439. color: #ffffff;
  440. }
  441. .bmhw {
  442. margin-left: 10rpx;
  443. width: 86rpx;
  444. height: 31rpx;
  445. background: linear-gradient(90deg, #1b4282 0%, #2b5da6 100%);
  446. border-radius: 5rpx;
  447. text-align: center;
  448. line-height: 31rpx;
  449. font-size: 16rpx;
  450. font-family: PingFang SC;
  451. font-weight: 500;
  452. color: #ffffff;
  453. }
  454. }
  455. .bottom_border {
  456. position: absolute;
  457. border-bottom: 1px solid #eeeeee;
  458. left: 25rpx;
  459. bottom: 0;
  460. height: 2rpx;
  461. width: 100%;
  462. }
  463. .name {
  464. margin-top: 10rpx;
  465. color: #141821;
  466. font-weight: 500;
  467. font-size: 26rpx;
  468. &.ellipsis {
  469. overflow: hidden;
  470. text-overflow: ellipsis;
  471. white-space: nowrap;
  472. }
  473. }
  474. .info {
  475. color: #979797;
  476. font-size: 24rpx;
  477. padding: 8rpx 0rpx;
  478. }
  479. .tipBox {
  480. height: 50rpx;
  481. }
  482. .tip {
  483. padding: 10rpx 0rpx;
  484. text {
  485. border: 2rpx solid #ff1a27;
  486. color: #ff1a27;
  487. border-radius: 5rpx;
  488. font-size: 18rpx;
  489. padding: 5rpx 10rpx;
  490. margin-right: 15rpx;
  491. }
  492. }
  493. .tlist-price {
  494. position: absolute;
  495. left: 25rpx;
  496. width: 100%;
  497. bottom: 25rpx;
  498. .price-box {
  499. .price {
  500. color: #ff1a27;
  501. .blod {
  502. font-size: 35rpx;
  503. font-weight: bold;
  504. }
  505. .fen {
  506. color: #838691;
  507. }
  508. }
  509. }
  510. .btn {
  511. width: 85rpx;
  512. height: 30rpx;
  513. background: linear-gradient(90deg, #fa0100 0%, #fa4716 100%);
  514. border-radius: 14rpx;
  515. text-align: center;
  516. line-height: 30rpx;
  517. font-size: 14rpx;
  518. font-family: PingFang SC;
  519. font-weight: 500;
  520. color: #ffffff;
  521. }
  522. }
  523. }
  524. }
  525. }
  526. .tlist {
  527. .cate {
  528. padding: 25rpx 0rpx;
  529. color: #666666;
  530. font-size: 24rpx;
  531. }
  532. }
  533. }
  534. </style>