hengmei-two/pagesA/shopCart/shopCart.vue

293 lines
9.6 KiB
Vue
Raw Normal View History

2021-10-11 10:21:06 +00:00
<template>
<view>
<!-- 状态栏 -->
<status-nav :titleVal="'购物车'" :statusTitle="true"></status-nav>
<view :style="{paddingTop: statusHeight+'px'}" class="pad-zy30 pad-x160">
2021-10-22 03:07:32 +00:00
<view class="bacf radius20 mar-s20 pad20" v-if="cartList.length!=0">
2021-10-11 10:21:06 +00:00
<view class="fon28 col3 disjbac" style="height: 43rpx;">
<view class="bold">订单信息</view>
2021-10-22 03:07:32 +00:00
<view v-if="!cancle_del && cartList.length!=0" @tap="guanEv(0)"></view>
<view v-if="cancle_del && cartList.length!=0" @tap="guanEv(1)" class="edit-btn"> ×</view>
2021-10-11 10:21:06 +00:00
</view>
2021-11-02 10:23:53 +00:00
<view v-for="(item,index) in cartList" :key="index" class="disjbac pad-sx40 borbot posir cart-list-box" @touchstart="moveStart(index,$event)" @touchend="moveEnd">
2021-10-22 03:07:32 +00:00
<view class="disjbac width100" :style="{marginLeft:(showDel && isDang==index)?'-70px':'',paddingRight:(showDel && isDang==index)?'70px':''}">
<!-- -->
<view @tap="chooseItem(index)">
<image v-if="item.isActive" src="/static/public/chooseFS.png" class="flexs chooseDX" mode=""></image>
<image v-else src="/static/public/cancle-FS.png" class="flexs chooseDX" mode=""></image>
2021-10-11 10:21:06 +00:00
</view>
<image lazy-load @tap="chooseItem(index)" :src="item.imgSrc" class="order-image mar-z25 flexs" mode="aspectFill"></image>
2021-10-22 03:07:32 +00:00
<view class="width100 disjbac fc" style="height: 166rpx;">
<view class="width100">
2021-11-02 10:23:53 +00:00
<view @tap="goShoptDetail(item.spu_id,item.spu_activity_id)" class="fon28 col3 bold clips2">{{item.title}}</view>
<view class="order-sy">{{item.sku_name}}</view>
2021-10-22 03:07:32 +00:00
</view>
<view class="disjbac width100 mar-s10">
2022-03-04 08:48:40 +00:00
<view class="order-item-price"><span v-if="item.is_score!=1"></span><span v-else></span>{{item.price}} <span class="fon20 mar-z10" :style="{color:publicColor}" style="font-weight: 400;">{{item.mch_type_text}}</span></view>
2021-10-22 03:07:32 +00:00
<view class="fon26 col3 disac bold cart-input-box">
<image @tap="deladdEvent(index , 0)" src="/static/public/del.png" mode=""></image>
2022-01-28 09:04:37 +00:00
<input type="text" @input="inputNum($event,index)" v-model="item.num"/>
2021-10-22 03:07:32 +00:00
<image @tap="deladdEvent(index , 1)" src="/static/public/add.png" mode=""></image>
2021-10-11 10:21:06 +00:00
</view>
</view>
</view>
</view>
2021-10-22 03:07:32 +00:00
<view v-if="showDel && isDang==index" @tap="deltItem(index)" class="item-del-btn"></view>
2021-10-11 10:21:06 +00:00
</view>
</view>
2021-10-22 03:07:32 +00:00
<nothing-page v-if="cartList.length==0" :content="'暂无更多商品'"></nothing-page>
<view class="disjbac posixzy bacf pad-zy32" style="height: 124rpx;line-height: 124rpx;">
<view class="disac" @tap="chooseAll">
<view class="chooseAll-box">
<view v-if="isChooseAll"></view>
2021-10-11 10:21:06 +00:00
</view>
<view class="fon28 col3 mar-z10">全选</view>
</view>
<!-- 去支付 -->
<view v-if="!cancle_del" class="disjbac">
<view>
2021-11-02 10:23:53 +00:00
<view class="fon28" v-if="isScore!='score'"><span class="fon40 bold colf8">{{allPrice}}</span></view>
2021-10-22 03:07:32 +00:00
<view class="fon28" v-else><span class="fon40 bold colf8">{{allPrice}}</span></view>
2021-10-11 10:21:06 +00:00
</view>
2021-11-02 10:23:53 +00:00
<view @tap="goGetReadyDan" class="colf fon30 bold mar-z10 goBuy-btn" style="background: #3875F6;">{{cartList.length==0?'去购物':'去支付'}}</view>
2021-10-11 10:21:06 +00:00
</view>
<!-- 删除 -->
2021-10-22 03:07:32 +00:00
<view @tap="delBtn" v-else class="colf fon28 bold goBuy-btn" style="background: #F85050;">删除</view>
2021-10-11 10:21:06 +00:00
</view>
</view>
2022-03-04 08:48:40 +00:00
<!-- 用户信息授权手机号授权 -->
<auth-userInfo-mobileInfo></auth-userInfo-mobileInfo>
2021-10-11 10:21:06 +00:00
</view>
</template>
<script>
export default {
data() {
return {
showDel:false,
startX:'',//开始位置
endX:'',//结束位置
2021-10-22 03:07:32 +00:00
cancle_del:false,
cartList:[],//购物车列表
isChooseAll:false,//是否全选
isDang:0,//当前抹动的item
newList:[],//暂存准备购买商品
delIndex:[],//待删除商品的ID
page:1,
size:10,
2021-12-02 09:31:26 +00:00
isScore:'',
2022-01-28 09:04:37 +00:00
timeout:null
2021-10-11 10:21:06 +00:00
}
},
computed: {
// 主题颜色
publicColor() {
return this.$store.state.publicColor
},
statusHeight() {
return this.$store.state.statusHeight
}
},
2021-10-11 10:21:06 +00:00
onShow() {
2021-10-22 03:07:32 +00:00
uni.removeStorageSync('orderList');
uni.removeStorageSync('payType');
2021-10-22 03:07:32 +00:00
},
onLoad(options) {
options.isScore=='score' ? this.isScore = 'score' : ''
2022-03-21 01:44:07 +00:00
if(uni.getStorageSync('phone_active')!=0 && uni.getStorageSync('is_active')!=0){
2022-03-04 08:48:40 +00:00
this.checkList();
}
2021-10-11 10:21:06 +00:00
},
2021-10-22 03:07:32 +00:00
computed:{
allPrice(){
let sum = 0
this.cartList.forEach(item=>{
if(item.isActive) sum += item.price*1 * item.num
})
return sum;
},
2021-10-11 10:21:06 +00:00
},
methods: {
2022-01-28 09:04:37 +00:00
// 数量输入事件
inputNum(e,index){
clearTimeout(this.timeout);
let str = e.detail.value;
this.timeout = setTimeout(()=>{
if(str=='' || str==0){
this.cartList[index].num = 1;
}
},500)
},
2021-10-22 03:07:32 +00:00
checkList(){//查询列表事件
this.$requst.post('order/shopping-cart',{page:this.page,size:this.size,type:this.isScore}).then(res=>{
if(res.code==0){
if(res.data.length!=0){
res.data.forEach(item=>{
let nprice = '';
2021-11-02 10:23:53 +00:00
item.is_score ==1 ? nprice = item.score : nprice = item.sku.sku_price/100;
2021-10-22 03:07:32 +00:00
let obj = {
id:item.id,
2021-11-02 10:23:53 +00:00
spu_id:item.spu.id,
spu_activity_id:item.spu_activity_id,//活动商品id
2021-10-22 03:07:32 +00:00
imgSrc:this.$http + item.spu.spu_cover,
coding:item.sku.coding,
2021-11-02 10:23:53 +00:00
title:item.spu_name,
sku_name:item.sku.sku_name,
2021-10-22 03:07:32 +00:00
price:nprice,//实际价格
num:item.num,
isActive:false,
2021-11-02 10:23:53 +00:00
is_score:item.is_score,//是否是积分
2022-03-04 08:48:40 +00:00
group_id:0,//0发起拼团 1参与拼团 2单独购买
mch_type:item.spu.mch_type,//商品类型
mch_type_text:item.spu.mch_type_text//商品类型描述
2021-10-22 03:07:32 +00:00
}
this.cartList.push(obj)
})
}
}
})
},
deltItem(index){//删除购物车
this.$requst.post('order/shopping-cart-del',{id:this.cartList[index].id}).then(res=>{
if(res.code==0){
this.cartList.splice(index,1);
this.$toolAll.tools.showToast('删除成功');
}
})
},
deladdEvent(cur,index){//数量加减事件
if(index==0){//减少数量
if(this.cartList[cur].num>1) this.cartList[cur].num--;
} else {//增加数量
this.cartList[cur].num++;
}
this.$requst.post('order/shopping-cart-change-num',{id:this.cartList[cur].id,num:this.cartList[cur].num}).then(res=>{})
this.zanList();
},
chooseItem(index){//单选事件
this.cartList[index].isActive = !this.cartList[index].isActive;
let one = this.cartList.filter(function(item){
return item.isActive == false;
})
one.length==0 ? this.isChooseAll = true : this.isChooseAll = false
this.zanList();
},
chooseAll(){//全选事件
this.isChooseAll = !this.isChooseAll;
this.cartList.forEach(item=>{
this.isChooseAll ? item.isActive = true : item.isActive = false;
})
this.zanList();
},
zanList(){//暂存选中商品事件
this.delIndex = []
this.newList = this.cartList.filter(item=>item.isActive==true);
if(this.cancle_del){
this.cartList.filter((item,index)=>{
if(item.isActive) {
this.delIndex.push(item.id);
}
});
}
},
delBtn(){//底部删除事件
this.delIndex.forEach(item=>{
this.cartList.forEach((item1,index)=>{
if(item==item1.id){
this.cartList.splice(index,1);
this.$requst.post('order/shopping-cart-del',{id:item1.id}).then(res=>{
if(res.code==0){
} else {
this.$toolAll.tools.showToast(res.msg);
}
})
}
})
})
this.isChooseAll = false;
if(this.cartList.length==0){
this.cancle_del = false;
}
},
guanEv(index){//管理切换事件
index==0 ? this.cancle_del = true : this.cancle_del = false;
this.cartList.forEach(item=>item.isActive=false);
this.isChooseAll = false;
2021-10-11 10:21:06 +00:00
},
2021-10-22 03:07:32 +00:00
moveStart(index,e){//移动开始
this.isDang = index;
2021-10-11 10:21:06 +00:00
this.startX = e.touches[0].pageX
},
2021-10-22 03:07:32 +00:00
moveEnd(e){//移动结束
2021-10-11 10:21:06 +00:00
this.endX = e.changedTouches[0].pageX
if(this.startX-this.endX>0){
this.showDel = true;
} else this.showDel = false;
},
goGetReadyDan(){
2021-10-22 03:07:32 +00:00
let newUrl = '';
let isNei = '';
if(this.isScore=='score') {
isNei = 3
}
if(this.cartList.length == 0) {
if(isNei==3){
newUrl = '/pagesA/pointsMall/pointsMall';
} else {
newUrl = '/pages/tabbar/shop/shop';
}
2021-11-02 10:23:53 +00:00
uni.navigateTo({
url:newUrl
})
2021-10-22 03:07:32 +00:00
}
if(this.cartList.length > 0) {
// console.log(this.isAllEqual(this.newList));
2022-03-04 08:48:40 +00:00
if(this.isAllEqual(this.newList) || this.newList.length==1){
uni.setStorageSync('orderList',this.newList);
if(this.newList.length==0){
this.$toolAll.tools.showToast('请选择要支付的商品');
} else {
uni.setStorageSync('payType',0);
2022-03-04 08:48:40 +00:00
uni.navigateTo({
// url:`/pagesA/getReadyDan/getReadyDan?isNei=${isNei}`
url:`/pagesA/getReadyDan/getReadyDan-two?isNei=${isNei}`
2022-03-04 08:48:40 +00:00
})
}
2021-11-02 10:23:53 +00:00
} else {
2022-03-04 08:48:40 +00:00
this.$toolAll.tools.showToast('请选择相同类型的商品下单')
2021-11-02 10:23:53 +00:00
}
2021-10-22 03:07:32 +00:00
}
2021-11-02 10:23:53 +00:00
},
2022-03-04 08:48:40 +00:00
// 判断数组对象中的某个字段的值是否都相等
isAllEqual(array) {
if (array.length > 0) {
return !array.some(function(value, index) {
return value.mch_type !== array[0].mch_type;
});
} else {
return true;
}
},
2021-11-02 10:23:53 +00:00
goShoptDetail(id,is_activity){
// &isIntegral=${this.dataList[index].isIntegral}
if(this.isScore=='score'){
uni.navigateTo({
url:`/pagesB/shopDetail/shopDetail?id=${id}&isIntegral=true`
})
} else {
uni.navigateTo({
url:`/pagesB/shopDetail/shopDetail?id=${id}&is_activity=${is_activity}`
})
}
2021-10-11 10:21:06 +00:00
}
}
}
</script>
<style>
page {
background-color: #F5F5F5;
}
</style>