123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <template>
- <view class="content">
- <empty v-if="list.length === 0"></empty>
- <view class="guess" v-if="list.length !=0">
- <view v-for="(item, index) in list" :key="index" class="guess-item" @click="navToDetailPage(item)">
- <image :src="item.image"></image>
- <view class="guess-box">
- <view class="title clamp">{{ item.store_name }}</view>
- <view class="guessbtm-box flex">
- <view class="price">¥{{ item.price }} <text class="yuan">¥{{ item.ot_price }}</text> </view>
- <image @click.stop="toggleSpec(item.id)" class="btn" src="../../static/icon/cart.png" mode="">
- </image>
- </view>
- </view>
- </view>
- <uni-load-more :status="loadingType"></uni-load-more>
- </view>
- <view class="cart" @click="navtab">
- <view class="text" v-if="total>0">
- {{total}}
- </view>
- <image class="cart-icon" src="/static/img/cartIcon.png" mode="scaleToFill"></image>
- </view>
- </view>
- </template>
- <script>
- import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
- import empty from '@/components/empty';
- import {
- getCartList,
- } from '@/api/cart.js';
- import {
- getProducts,
- cartAdd
- } from '@/api/product.js';
- export default {
- data() {
- return {
- page: 1,
- limit: 20,
- loadingType: 'more',
- list: [],
- total: 0
- };
- },
- components: {
- empty,
- uniLoadMore
- },
- onLoad() {
- this.loadData();
- },
- onShow() {
- this.loadCart();
- },
- onReachBottom() {
- this.loadData();
- },
- onReady() {},
- methods: {
- navtab() {
- uni.switchTab({
- url: '/pages/cart/cart'
- })
- },
- async loadCart() {
- let obj = this;
- getCartList({
- type: 0
- })
- .then(function(e) {
- obj.total = e.data.valid.length;
- })
- .catch(function(e) {
- console.log(e);
- });
- },
- navToDetailPage(opt) {
- uni.navigateTo({
- url: '/pages/product/product?id=' + opt.id
- })
- },
- loadData() {
- if (this.loadingType == 'loading' || this.loadingType == 'nomore') {
- return
- }
- this.loadingType = 'loading'
- getProducts({
- page: this.page,
- limit: this.limit,
- cid: 1
- }).then(({
- data
- }) => {
- this.list = this.list.concat(data)
- this.page++
- if (data.length != this.limit) {
- this.loadingType = 'nomore'
- } else {
- this.loadingType = 'more'
- }
- })
- },
- toggleSpec(str) {
- const that = this;
- that.total++
- cartAdd({
- cartNum: 1, //商品数量
- uniqueId: '', //商品标签
- new: 0, //商品是否新增加到购物车1为不加入0为加入
- mer_id: 0,
- is_consumer: 0,
- productId: str
- }).then(e => {
- uni.showToast({
- title: '成功加入购物车',
- type: 'top',
- duration: 2000
- });
- that.loadCart();
- }).catch((e)=>{
- that.total--
- })
- },
- }
- };
- </script>
- <style lang="scss">
- page,
- .content {
- min-height: 100%;
- height: auto;
- }
- .cart {
- position: fixed;
- right: 30rpx;
- bottom: 60rpx;
- .cart-icon {
- width: 150rpx;
- height: 150rpx;
- }
- .text {
- background-color: $color-red;
- color: #FFF;
- position: absolute;
- top: 0;
- right: 0;
- width: 40rpx;
- height: 40rpx;
- z-index: 999;
- text-align: center;
- border-radius: 99rpx;
- }
- }
- .guess {
- display: flex;
- justify-content: space-between;
- flex-wrap: wrap;
- padding: 20rpx;
- }
- .guess-item {
- margin-top: 20rpx;
- width: 345rpx;
- background: #FFFFFF;
- box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
- border-radius: 10rpx;
- image {
- width: 345rpx;
- height: 345rpx;
- border-radius: 10rpx;
- }
- .guess-box {
- padding: 28rpx 20rpx;
- width: 345rpx;
- .title {
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #333333;
- }
- .price {
- font-size: 36rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #FF6B2E;
- .yuan {
- display: inline-block;
- margin-left: 10rpx;
- font-size: 26rpx;
- font-family: PingFang SC;
- font-weight: 500;
- text-decoration: line-through;
- color: #989898;
- }
- }
- .btn {
- width: 44rpx;
- height: 44rpx;
- background: #00ca95;
- border-radius: 50rpx;
- }
- }
- }
- </style>
|