2022-05-25 09:55:44 +00:00
|
|
|
|
<template>
|
|
|
|
|
<view class="pad-x120">
|
2022-05-26 10:35:10 +00:00
|
|
|
|
<view class="slide-box mar-x20 animated" v-for="(item, index) in listData" :key="index" :class="item.ifExit ? 'fadeIn' : 'fadeOutDown'" :style="{display: item.ifShow ? 'flex' : 'none'}">
|
2022-08-08 10:55:27 +00:00
|
|
|
|
<view class="slide-list" :style="{ transform: 'translate3d(' + item.slide_x + 'px, 0, 0)' }">
|
|
|
|
|
<view class="now-message-info" :style="{ width: windowWidth + 'px' }">
|
2022-05-25 09:55:44 +00:00
|
|
|
|
<!-- <view class="mo-item flexs" @tap.stop="chooseEv(index)" :class="item.ifcheck ? 'active-item' : ''"></view> -->
|
2022-06-06 05:49:21 +00:00
|
|
|
|
<label class="radio"><radio :checked="item.ifcheck" @tap.stop="chooseEv(index)" color="#ff3673" style="transform: scale(.8);"/></label>
|
|
|
|
|
<view class="shopp-img imgH mar-y20 mar-z10" @tap="goDetail(item.spuId)">
|
2022-05-25 09:55:44 +00:00
|
|
|
|
<image class="shopp-img imgH width100" :src="item.image" mode="aspectFill"></image>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="imgH disjb fc fon24 width100">
|
2022-08-08 10:55:27 +00:00
|
|
|
|
<view class="" @tap="goDetail(item.spuId)">
|
2022-05-25 09:55:44 +00:00
|
|
|
|
<view class="fon28 bold clips2">{{item.title}}</view>
|
|
|
|
|
<view class="clips2 line-h40">单位:{{item.content}}</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="disjbac">
|
|
|
|
|
<!-- 商品价格 -->
|
2022-07-15 03:10:06 +00:00
|
|
|
|
<view class="fon24 textc bold">¥<span class="fon28 ">{{item.price}}</span></view>
|
2022-05-25 09:55:44 +00:00
|
|
|
|
<!-- 商品数量 -->
|
|
|
|
|
<view class="disac">
|
|
|
|
|
<!-- 减数量 -->
|
2022-09-26 02:35:33 +00:00
|
|
|
|
<i class="icon icon-cut countBtn disjcac" @tap.stop="addCutEv(index,0)" :style="{backgroundColor: item.num==minNum || item.slide_x!=0 ? '#cccccc': '#ff3673'}"></i>
|
2022-05-25 09:55:44 +00:00
|
|
|
|
<!-- 实际数量 -->
|
|
|
|
|
<input type="digit" @blur="blurEv(index,$event)" @focus="focusEv(item.num)" class="fon24 tcenter countInput borbot-cc" :disabled="item.slide_x!=0" v-model="item.num">
|
|
|
|
|
<!-- 加数量 -->
|
2022-09-26 02:35:33 +00:00
|
|
|
|
<i class="icon icon-add countBtn disjcac" @tap.stop="addCutEv(index,1)" :style="{backgroundColor: item.num==maxNum || item.slide_x!=0 ? '#cccccc': '#ff3673'}"></i>
|
2022-05-25 09:55:44 +00:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2022-06-10 07:16:56 +00:00
|
|
|
|
<!-- 全选 -->
|
2022-05-25 09:55:44 +00:00
|
|
|
|
<view class="disjbac cart-foot-box fon24" :style="{bottom: footHeight+'px'}">
|
|
|
|
|
<label class="disac" @tap="chooseAll"><radio :checked="allChoose" color="#ff3673" style="transform: scale(.8);"/><text>全选</text></label>
|
|
|
|
|
<view class="disac">
|
2022-07-15 03:10:06 +00:00
|
|
|
|
<view class="fon24 mar-y30">合计:<span>¥{{allPrice}}</span></view>
|
2022-09-26 02:35:33 +00:00
|
|
|
|
<view class="fon32" :style="{background: !buyNum ? '#cccccc' : 'linear-gradient(to right,#ff3771 0%,#fd5549 100%)'}" @tap="submitEv">{{allPrice==0 ? '去购物' : `提交订单 (${buyNum})`}}</view>
|
2022-05-25 09:55:44 +00:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2022-05-27 09:43:21 +00:00
|
|
|
|
<view class="" v-if="listData.length!=0 && total==listData.length"><pitera textStr="—— 到底啦 ——"></pitera></view>
|
2022-05-25 09:55:44 +00:00
|
|
|
|
<nothing-page v-if="!ifLoading && !listData.length" content="你的购物车:这也空空,那也空空(*^▽^*)"></nothing-page>
|
2022-05-26 10:35:10 +00:00
|
|
|
|
<view class="loading-box" v-show="ifMore">
|
|
|
|
|
<view class="loader-16"></view>
|
|
|
|
|
</view>
|
2022-05-25 09:55:44 +00:00
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { mapState,mapGetters,mapMutations } from 'vuex'//引入mapState
|
|
|
|
|
import pitera from '@/components/nothing/pitera';
|
2022-05-27 09:43:21 +00:00
|
|
|
|
import {getCartNum} from '@/jsFile/public-api.js';
|
2022-05-25 09:55:44 +00:00
|
|
|
|
export default {
|
|
|
|
|
components:{
|
|
|
|
|
pitera
|
|
|
|
|
},
|
|
|
|
|
name: 'mark-slide-list',
|
|
|
|
|
props: {
|
|
|
|
|
list: { //数据list
|
|
|
|
|
type: Array,
|
|
|
|
|
default () {
|
|
|
|
|
return [
|
2022-05-27 09:43:21 +00:00
|
|
|
|
// {id: 1,image: 'https://s6.jpg.cm/2022/02/14/L4oDhy.jpg',title: '标题',content: '描述描述描述描述描述描述',slide_x: 0,price:199,num:1,ifcheck:false,ifExit:true,ifShow:true},
|
|
|
|
|
// {id: 1,image: 'https://s6.jpg.cm/2022/02/14/L4oDhy.jpg',title: '标题',content: '描述描述描述描述描述描述',slide_x: 0,price:199,num:1,ifcheck:false,ifExit:true,ifShow:true},
|
|
|
|
|
// {id: 1,image: 'https://s6.jpg.cm/2022/02/14/L4oDhy.jpg',title: '标题',content: '描述描述描述描述描述描述',slide_x: 0,price:199,num:1,ifcheck:false,ifExit:true,ifShow:true},
|
|
|
|
|
// {id: 1,image: 'https://s6.jpg.cm/2022/02/14/L4oDhy.jpg',title: '标题',content: '描述描述描述描述描述描述',slide_x: 0,price:199,num:1,ifcheck:false,ifExit:true,ifShow:true},
|
|
|
|
|
// {id: 1,image: 'https://s6.jpg.cm/2022/02/14/L4oDhy.jpg',title: '标题',content: '描述描述描述描述描述描述',slide_x: 0,price:199,num:1,ifcheck:false,ifExit:true,ifShow:true},
|
|
|
|
|
// {id: 1,image: 'https://s6.jpg.cm/2022/02/14/L4oDhy.jpg',title: '标题',content: '描述描述描述描述描述描述',slide_x: 0,price:199,num:1,ifcheck:false,ifExit:true,ifShow:true},
|
2022-05-25 09:55:44 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
button: { //按钮数据list
|
|
|
|
|
type: Array,
|
|
|
|
|
default () {
|
|
|
|
|
return [
|
|
|
|
|
// {title: '分享',background: '#c4c7cd'},
|
|
|
|
|
{title: '删除',background: 'linear-gradient(to right,#ff3771 0%,#fd5549 100%)'}
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-05-27 09:43:21 +00:00
|
|
|
|
skuId:{
|
|
|
|
|
type:String,
|
|
|
|
|
default:0
|
2022-05-25 09:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
windowWidth() {
|
|
|
|
|
return uni.getSystemInfoSync().windowWidth;
|
|
|
|
|
},
|
|
|
|
|
// 总价及合计
|
|
|
|
|
allPrice() {
|
|
|
|
|
let allPrice = 0;
|
|
|
|
|
this.listData.forEach(item=>{
|
|
|
|
|
if(item.ifcheck) {
|
2022-07-15 03:10:06 +00:00
|
|
|
|
allPrice += item.price*item.num;
|
2022-05-25 09:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// return this.$toolAll.tools.addXiaoShu(allPrice);
|
|
|
|
|
return allPrice.toString();
|
|
|
|
|
},
|
2022-06-13 08:13:03 +00:00
|
|
|
|
|
2022-05-25 09:55:44 +00:00
|
|
|
|
// 要删除的数量
|
|
|
|
|
buyNum() {
|
|
|
|
|
let buyNum = 0;
|
|
|
|
|
this.listData.forEach(item=>{
|
|
|
|
|
if(item.ifcheck) {
|
|
|
|
|
buyNum += 1;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return buyNum;
|
|
|
|
|
},
|
2022-06-13 08:13:03 +00:00
|
|
|
|
|
2022-05-25 09:55:44 +00:00
|
|
|
|
// 全选
|
|
|
|
|
allChoose() {
|
|
|
|
|
let ifAll = false;
|
|
|
|
|
if(this.listData.length) {
|
|
|
|
|
let temparr = this.listData.filter(item=>{return item.ifcheck==false})
|
|
|
|
|
temparr.length==0 ? ifAll = true : ifAll = false;
|
|
|
|
|
}
|
|
|
|
|
return ifAll
|
|
|
|
|
},
|
|
|
|
|
...mapState({
|
|
|
|
|
footHeight: state => state.moduleA.footHeight,
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
listData: [],
|
|
|
|
|
start_slide_x: 0,
|
|
|
|
|
btnWidth: 0,
|
|
|
|
|
startX: 0,
|
|
|
|
|
LastX: 0,
|
|
|
|
|
startTime: 0,
|
|
|
|
|
itemIndex: 0,
|
|
|
|
|
originalNum:0,//当前输入框原值
|
2022-06-06 06:15:31 +00:00
|
|
|
|
maxNum:99999,//最大可输入数量
|
2022-05-25 09:55:44 +00:00
|
|
|
|
minNum:1,//最小可输入数量
|
|
|
|
|
ifLoading:true,
|
2022-05-27 09:43:21 +00:00
|
|
|
|
page:1,
|
|
|
|
|
size:10,
|
2022-05-26 10:35:10 +00:00
|
|
|
|
total:0,
|
|
|
|
|
ifMore:false
|
2022-05-25 09:55:44 +00:00
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.listData = this.list;
|
2022-05-27 09:43:21 +00:00
|
|
|
|
this.getList();
|
2022-05-25 09:55:44 +00:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
getList(){
|
2022-05-26 10:35:10 +00:00
|
|
|
|
console.log('触底');
|
|
|
|
|
this.total = 0;
|
|
|
|
|
this.ifMore = true;
|
2022-05-27 09:43:21 +00:00
|
|
|
|
let params = {
|
|
|
|
|
page:this.page,
|
|
|
|
|
size:this.size
|
|
|
|
|
}
|
|
|
|
|
this.$requst.post('/api/order/shopping-cart',params).then(res=>{
|
|
|
|
|
if(res.code==0){
|
|
|
|
|
this.total = res.data.total;
|
|
|
|
|
if(this.page==1) this.listData = [];
|
|
|
|
|
if(res.data.list.length){
|
|
|
|
|
res.data.list.forEach(item=>{
|
|
|
|
|
let obj = {
|
|
|
|
|
id: item.id,
|
|
|
|
|
spuId:item.spu.id,
|
|
|
|
|
skuId:item.sku_id,
|
2022-05-27 11:59:47 +00:00
|
|
|
|
coding:item.sku.coding,
|
2022-05-27 09:43:21 +00:00
|
|
|
|
image: item.spu.spu_cover,
|
|
|
|
|
title: item.spu.spu_name,
|
|
|
|
|
content: item.spu.unit,
|
|
|
|
|
slide_x: 0,
|
2022-07-15 03:10:06 +00:00
|
|
|
|
price:item.spu.original_price,
|
2022-05-27 09:43:21 +00:00
|
|
|
|
num:item.num,
|
|
|
|
|
ifcheck:this.skuId==item.sku_id ? true : false,
|
|
|
|
|
ifExit:true,
|
|
|
|
|
ifShow:true,
|
|
|
|
|
}
|
|
|
|
|
this.listData.push(obj);
|
|
|
|
|
console.log(this.listData);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-26 10:35:10 +00:00
|
|
|
|
this.ifMore = false;
|
2022-05-27 09:43:21 +00:00
|
|
|
|
this.ifLoading = false;
|
|
|
|
|
})
|
2022-05-25 09:55:44 +00:00
|
|
|
|
// for (let i = 0; i < 10; i++) {
|
|
|
|
|
// this.listData.push({id: 1,image: 'https://s6.jpg.cm/2022/02/14/L4oDhy.jpg',title: '标题',content: '描述描述描述描述描述描述',slide_x: 0,price:199,num:1,ifcheck:false,ifExit:true,ifShow:true})
|
|
|
|
|
// }
|
|
|
|
|
},
|
|
|
|
|
// 全选事件
|
|
|
|
|
chooseAll(){
|
|
|
|
|
let exit = this.listData.filter(item=>item.ifcheck==false);
|
|
|
|
|
if(exit.length){
|
|
|
|
|
this.listData.forEach(item=>item.ifcheck = true);
|
|
|
|
|
} else {
|
|
|
|
|
this.listData.forEach(item=>{item.ifcheck = false});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 去购物、去结算、删除
|
|
|
|
|
submitEv(){
|
|
|
|
|
if(this.allPrice==0) {
|
|
|
|
|
// 去购物
|
|
|
|
|
console.log('去购物');
|
2022-05-27 09:43:21 +00:00
|
|
|
|
uni.reLaunch({
|
|
|
|
|
url:`/pages/tabbar/cate/cate?index=0`
|
|
|
|
|
})
|
2022-05-25 09:55:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
// 去结算
|
|
|
|
|
console.log('去结算');
|
2022-05-27 11:59:47 +00:00
|
|
|
|
let buyList = [];
|
|
|
|
|
this.listData.forEach(item=>{
|
|
|
|
|
if(item.ifcheck) {
|
|
|
|
|
let obj = {
|
|
|
|
|
sku_coding: item.coding,
|
|
|
|
|
num: item.num
|
|
|
|
|
}
|
|
|
|
|
buyList.push(obj);
|
2022-05-27 09:43:21 +00:00
|
|
|
|
}
|
2022-05-25 09:55:44 +00:00
|
|
|
|
})
|
2022-05-27 11:59:47 +00:00
|
|
|
|
uni.setStorageSync('buyList',buyList);
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url:'/pagesB/settlement/settlement'
|
|
|
|
|
})
|
2022-05-25 09:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 选中事件
|
|
|
|
|
chooseEv(index) {
|
|
|
|
|
this.listData[index].ifcheck = !this.listData[index].ifcheck;
|
|
|
|
|
},
|
|
|
|
|
// 数量加减事件
|
|
|
|
|
addCutEv(index,num) {
|
|
|
|
|
if(this.listData[index].slide_x==0){
|
|
|
|
|
if(num) {
|
|
|
|
|
// 加 ,如果当前商品数量不等于最大值
|
|
|
|
|
if(this.listData[index].num != this.maxNum) {
|
|
|
|
|
this.listData[index].num++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 减 ,如果当前商品数量大于最小值
|
|
|
|
|
if(this.listData[index].num > this.minNum) {
|
|
|
|
|
this.listData[index].num--;
|
2022-06-13 08:13:03 +00:00
|
|
|
|
}else{
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: '是否将该商品移除购物车?',
|
|
|
|
|
success: (res)=> {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
this.delShopEv(this.listData[index].id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-05-25 09:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-27 09:43:21 +00:00
|
|
|
|
this.$requst.post('/api/order/shopping-cart-change-num',{id:this.listData[index].id,num:this.listData[index].num}).then(res=>{
|
|
|
|
|
if(res.code!=0){
|
|
|
|
|
this.$toolAll.tools.showToast(res.msg);
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-05-25 09:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2022-06-13 08:13:03 +00:00
|
|
|
|
// 删除商品
|
|
|
|
|
delShopEv(id){
|
|
|
|
|
this.$requst.post('/api/order/shopping-cart-del',{id:id}).then(res=>{
|
|
|
|
|
if(res.code==0){
|
|
|
|
|
this.$toolAll.tools.showToast('删除成功');
|
|
|
|
|
this.getList();
|
|
|
|
|
}else{
|
|
|
|
|
this.$toolAll.tools.showToast(res.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2022-06-06 05:49:21 +00:00
|
|
|
|
// 查看商品详情
|
|
|
|
|
goDetail(id) {
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url:'/pagesB/shop-detail/shop-detail?id='+id
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2022-05-25 09:55:44 +00:00
|
|
|
|
// 输入框获取焦点事件
|
|
|
|
|
focusEv(num) {
|
|
|
|
|
// 储存当前商品的原始数值
|
|
|
|
|
this.originalNum = num;
|
|
|
|
|
},
|
|
|
|
|
// 输入框失去焦点事件
|
|
|
|
|
blurEv(index,e) {
|
|
|
|
|
// 失去焦点时,获取当前输入框里的数值
|
|
|
|
|
let currentNum = e.detail.value*1;
|
|
|
|
|
// 如果当前输入框的值不等于0或空,并且当前输入框的值大于最大值,当前商品的数量 = 最大值, 否则为当前输入框输入的值
|
|
|
|
|
this.listData[index].num = currentNum ? currentNum > this.maxNum ? this.maxNum : currentNum : this.originalNum;
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.slide-box {
|
|
|
|
|
width: 100%;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
/* border-radius: 10rpx; */
|
|
|
|
|
}
|
|
|
|
|
.slide-list {
|
|
|
|
|
transition: all 100ms;
|
|
|
|
|
transition-timing-function: ease-out;
|
|
|
|
|
min-width: 200%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.now-message-info {
|
|
|
|
|
position: relative;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
clear: both;
|
|
|
|
|
padding: 20rpx;
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
float: left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.imgH{height: 180rpx;}
|
|
|
|
|
.shopp-img{width: 180rpx;border-radius: 10rpx;}
|
|
|
|
|
|
|
|
|
|
.group-btn {
|
|
|
|
|
float: left;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
height: 220rpx;
|
|
|
|
|
min-width: 100rpx;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-div {
|
|
|
|
|
height: 220rpx;
|
|
|
|
|
color: #fff;
|
|
|
|
|
text-align: center;
|
|
|
|
|
padding: 0 50rpx;
|
|
|
|
|
font-size: 34rpx;
|
|
|
|
|
line-height: 220rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.top {
|
|
|
|
|
background-color: #c4c7cd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.removeM {
|
|
|
|
|
background-color: #ff3b32;
|
|
|
|
|
}
|
|
|
|
|
.countBtn{font-size: 36rpx;width: 40rpx;height: 40rpx;background-color: #000000;color: #FFFFFF; border-radius: 10rpx;}
|
|
|
|
|
.countInput{background-color: #FFFFFF;width: 80rpx;height: 40rpx!important; border-radius: 10rpx;padding: 0rpx 0;margin: 0 10rpx;}
|
2022-05-26 10:35:10 +00:00
|
|
|
|
.cart-foot-box{position: fixed;bottom: 0;right: 0;left: 0;background-color: #FFFFFF;z-index: 2; padding: 20rpx 20rpx;box-shadow: -6rpx 0rpx 10rpx rgba(0, 0, 0, 0);}
|
2022-05-25 09:55:44 +00:00
|
|
|
|
.cart-submit-btn{
|
|
|
|
|
|
|
|
|
|
color: #FFFFFF;
|
|
|
|
|
background-color: #cccccc;
|
|
|
|
|
padding: 20rpx 30rpx;
|
|
|
|
|
border-radius: 30rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.shopping-manage{position: fixed;right: 20rpx;bottom: 320rpx;width: 80rpx;height: 80rpx; border-radius: 100%;background-color: rgba(0, 0, 0, .6);color: #FFFFFF;font-size: 24rpx;display: flex;justify-content: center;align-items: center;}
|
|
|
|
|
</style>
|