You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
high-mini/physical-merchants/classify/cart/cart.vue

650 lines
13 KiB

2 years ago
<template>
2 years ago
<view class="">
<!-- v-if="cartList.length>0" -->
2 years ago
<view class="cart-container backcor9">
2 years ago
<scroll-view :scroll-y="true" class="cart-list">
<uni-swipe-action>
<!-- 从这里开始遍历-->
<view v-for="(item,index) in cartList"
2 years ago
:class="(item.loseEfficacy?' loseEfficacy ':' ')+'marb10 border-8r backcolorfff paading10'"
2 years ago
:key="item.id">
2 years ago
<!-- :disabled="item.loseEfficacy" -->
2 years ago
<uni-swipe-action-item :auto-close="autoClose" :right-options="swipe_options"
@click="swipe_opt_event($event,item.id)" @change="swipe_change($event, item.id)">
<view class="cart-container2">
<checkbox-group @change="checkClick(item)">
2 years ago
<checkbox class="mycheck" :disabled="!isEdit&&item.loseEfficacy" color="#FFC71E"
2 years ago
:value="item.id" :checked="item.whetherCheck" />
</checkbox-group>
2 years ago
<view class="cart-detail">
2 years ago
<view class="cart-img">
<image :src="imageUrl+item.img" class="img border-8r" mode="aspectFill"></image>
2 years ago
</view>
2 years ago
<view class="cart-msg">
<view class="">
<view class="cart-msg-title font16 marb10 mart5">{{item.title}}</view>
<view class="cart-msg-parm font13 marb10 fcor777">{{item.skuName|| ''}}
</view>
2 years ago
</view>
2 years ago
<view class="cart-msg-price">
2 years ago
<view class="dis-flex">
<view class="cart-price font16 fcorred">
<!-- ¥ <text class="font20">18 </text>.8 -->
¥{{item.price}}
</view>
<!-- <view class="fcor666 margle10 font14 text-lt">
¥{{item.originalPrice}}
</view> -->
2 years ago
</view>
2 years ago
2 years ago
<view :class="'cart-num'+(item.loseEfficacy?' pont-event ':' ')">
2 years ago
2 years ago
<uni-number-box v-model="item.num" :min="1"
@noMoreLess="noMoreLess(item.id+'')"
@change="changeNumValue($event,item.id)" :max="999999999" />
2 years ago
</view>
2 years ago
</view>
2 years ago
2 years ago
</view>
</view>
</view>
2 years ago
</uni-swipe-action-item>
</view>
<noMore></noMore>
</uni-swipe-action>
</scroll-view>
<view class="cart-tool bg-white">
<view class="select-all">
<checkbox-group @change="checkAllClick">
<label>
<!-- :disabled="cartList.length == 0" -->
<checkbox class="mycheck" color="#FFC71E" :value="allCheck.value"
:checked="allCheck.whetherCheck" />
<text class="paddleft5 font16 fcor777">全选</text>
</label>
<!-- -->
</checkbox-group>
<text v-if="!isEdit" class="paddleft5 fcorred font16" @click="editDelete">编辑</text>
<text v-if="isEdit" class="icon-ymt delete paddleft5 fcorred" @click="deleteCart"></text>
2 years ago
</view>
2 years ago
<text v-if="isEdit" class="tool-right paddleft5 fcorred" @click="editDelete">退出编辑</text>
<view v-if="!isEdit" class="tool-right">
<view class="tool-jiesuan marRight10 ">
2 years ago
<!-- <text v-if="priceOrigin > 0" class="fcor666 margle10 marRight10 font14 text-lt">¥{{priceOrigin}}</text> -->
合计:<text v-if="priceAll>0" class="fcorred">¥{{priceAll | numFormat}}</text>
<text v-else class="fcorred">¥{{priceAll}}</text>
2 years ago
</view>
<view class="jiesuan-btn fcorfff " @click="settleAccount">
结算
</view>
2 years ago
</view>
2 years ago
2 years ago
</view>
</view>
2 years ago
<!-- <view v-else class="cart-container backcor9">
<view class="">
购物车内暂无商品快去购物吧
</view>
</view> -->
2 years ago
</view>
2 years ago
2 years ago
</template>
<script>
// import cartList from '@/pages/classify/cart-list/cart-list.vue'
2 years ago
import noMore from '@/components/no-more/no-more.vue'
2 years ago
import uniNumberBox from '@/uni_modules/uni-number-box/components/uni-number-box/uni-number-box.vue'
2 years ago
import {
getShoppingCartList,
2 years ago
goodsEditNum,
2 years ago
deleteShoppingCart
} from '@/Utils/physicalObject.js'
const app = getApp();
2 years ago
export default {
2 years ago
data() {
return {
imageUrl: app.globalData.imgUrl, //图片地址
cartList: [],
checkList: [],
allCheck: {
name: '全选',
whetherCheck: false,
value: 'all'
2 years ago
},
2 years ago
2 years ago
//
2 years ago
swipe_options: [{
2 years ago
text: '删除',
icon: ' delete ',
style: {
backgroundColor: '#E64340'
}
},
// {
// isCheck: false,
// text: "收藏",
// icon: ' shoucang32 ',
// style: {
// backgroundColor: '#f6c133'
// }
// },
2 years ago
2 years ago
],
2 years ago
swipe_item_index: null,
2 years ago
numberValue: 0,
cartList: [],
autoClose: false,
2 years ago
// listSelect:[],
2 years ago
isEdit: false,
showAction: 'none'
2 years ago
}
},
2 years ago
components: {
2 years ago
// cartList,
noMore,
2 years ago
"uni-number-box": uniNumberBox
2 years ago
},
2 years ago
computed: {
2 years ago
//现价金额
2 years ago
priceAll() {
2 years ago
let str = 0;
// for (var i = 0; i < this.cartList.length; i++) {
// if (this.cartList[i].whetherCheck) {
// str += this.cartList[i].num * this.cartList[i].price;
// }
// }
if (this.cartList.length > 0) {
this.cartList.map(item => {
if (item.whetherCheck) {
str =parseFloat((str + (item.num*item.price)).toFixed(2))
}
})
return str;
} else {
return 0;
2 years ago
}
2 years ago
2 years ago
},
// 原价
2 years ago
// priceOrigin(){
// var str = 0;
// for (var i = 0; i < this.cartList.length; i++) {
// if (this.cartList[i].whetherCheck) {
// str += this.cartList[i].num * this.cartList[i].originalPrice;
// }
// }
// return str;
// }
2 years ago
},
2 years ago
onLoad() {
2 years ago
2 years ago
// this.cartList.map(item=>{
// this.$set(item, 'checked', false);
// })
2 years ago
// this.initData();
2 years ago
2 years ago
},
2 years ago
onShow(){
this.initData();
},
2 years ago
methods: {
initData() {
2 years ago
uni.showLoading({
title: '加载中',
mask:true,
});
2 years ago
getShoppingCartList().then(res => {
2 years ago
uni.hideLoading();
2 years ago
if (res.return_code == '000000') {
console.log(res.return_data)
this.cartList = res.return_data;
this.allCheckInit();
2 years ago
2 years ago
} else {
uni.showToast({
title: res.return_msg,
icon: 'none',
duration: 2000
})
}
})
},
editDelete() {
2 years ago
this.isEdit = !this.isEdit;
2 years ago
if (!this.isEdit) { //退出编辑
this.cartList.map(item => {
2 years ago
if (item.whetherCheck && item.loseEfficacy) {
2 years ago
item.whetherCheck = false;
}
})
} else { //进入编辑
if (this.allCheck.whetherCheck) {
this.cartList.map(item => {
item.whetherCheck = true;
2 years ago
})
}
}
2 years ago
2 years ago
},
// 全选的点击事件
checkAllClick(e) {
2 years ago
this.allCheck.whetherCheck = !this.allCheck.whetherCheck;
if (this.allCheck.whetherCheck) {
this.cartList.map(item => {
2 years ago
if (!this.isEdit) { //商品的全选事件,loseEfficacy商品的失效,默认undefined
if (!item.loseEfficacy) {
2 years ago
item.whetherCheck = true
2 years ago
}
2 years ago
} else { //编辑的全选事件
item.whetherCheck = true
}
})
} else {
this.cartList.map(item => {
item.whetherCheck = false
})
}
2 years ago
},
2 years ago
2 years ago
// 单个商品的选择
checkClick(item) {
2 years ago
item.whetherCheck = !item.whetherCheck;
2 years ago
2 years ago
if (!item.whetherCheck) {
2 years ago
if (!this.isEdit && !item.loseEfficacy) { //商品
2 years ago
this.allCheck.whetherCheck = false;
} else if (this.isEdit) {
this.allCheck.whetherCheck = false;
2 years ago
}
2 years ago
2 years ago
} else {
2 years ago
// // 判断每一个商品是否是被选择的状态
// const goods = this.cartList.every(item => {
// if(!this.isEdit){//商品
2 years ago
// if(item.loseEfficacy){
2 years ago
// return true;
// }
// }
// return item.whetherCheck === true
// })
// if (goods) {
// this.allCheck.whetherCheck = true
// } else {
// this.allCheck.whetherCheck = false
// }
this.allCheckInit()
2 years ago
}
},
2 years ago
allCheckInit() {
2 years ago
if (this.cartList.length == 0) {
2 years ago
this.allCheck.whetherCheck = false;
return
}
2 years ago
2 years ago
// 判断每一个商品是否是被选择的状态
const goods = this.cartList.every(item => {
2 years ago
if (!this.isEdit) { //商品
if (item.loseEfficacy) {
return true;
}
}
2 years ago
return item.whetherCheck === true
})
if (goods) {
this.allCheck.whetherCheck = true
} else {
this.allCheck.whetherCheck = false
}
2 years ago
2 years ago
},
// 判断购物车内是否有商品
isHaveGoods() {
if (this.cartList.length == 0) {
2 years ago
uni.showToast({
title: '购物车内暂无商品喔',
duration: 1000,
2 years ago
icon: 'none'
2 years ago
});
2 years ago
2 years ago
return false
}
return true;
},
2 years ago
2 years ago
// 购物车删除
deleteCart() {
2 years ago
if (!this.isHaveGoods()) return;
2 years ago
var select = [];
for (var i = 0; i < this.cartList.length; i++) {
2 years ago
if (this.cartList[i].whetherCheck) {
2 years ago
select.push(this.cartList[i].id)
}
}
2 years ago
if (select.length == 0) {
2 years ago
uni.showToast({
title: '请勾选要移除购物车的商品',
duration: 1000,
2 years ago
icon: 'none'
2 years ago
});
return
2 years ago
} else {
// console.log(select.join(), "要移除的商品id")
2 years ago
let str = select.join();
2 years ago
this.noMoreLess(str)
2 years ago
}
2 years ago
2 years ago
},
// 结算
2 years ago
settleAccount() {
2 years ago
2 years ago
if (!this.isHaveGoods()) return;
if (this.priceAll > 0) {
2 years ago
let selestArr = this.cartList.filter(item => item.whetherCheck == true)
2 years ago
selestArr = JSON.stringify(selestArr)
2 years ago
2 years ago
// console.log(selestArr)
2 years ago
uni.navigateTo({
2 years ago
url: '/physical-merchants/settleAccounts/settleAccounts?goodsList=' + selestArr
2 years ago
})
2 years ago
} else {
2 years ago
uni.showToast({
title: '请勾选要购买的商品',
duration: 1000,
2 years ago
icon: 'none'
2 years ago
});
}
2 years ago
2 years ago
},
// 滑动点击
2 years ago
swipe_opt_event(e, id) {
2 years ago
console.log(e, "dianji")
2 years ago
if (e.index == 1) { //收藏
2 years ago
2 years ago
// console.log(e.content.isCheck)
// e.content.isCheck=!e.content.isCheck
2 years ago
2 years ago
// if(e.content.isCheck){
// e.content.icon=" shoucang32-select "
// }else{
// e.content.icon=" shoucang32 "
// }
this.showAction = 'right'
2 years ago
2 years ago
return
}
2 years ago
if (e.index == 0) { //删除
this.noMoreLess(id + "")
2 years ago
return
}
2 years ago
2 years ago
},
// 滑动事件
swipe_change(e, id) {
2 years ago
console.log(e, id)
// this.swipe_item_index= (e == 'none') ? null : v
2 years ago
},
2 years ago
noMoreLess(ids) {
2 years ago
let _this = this;
uni.showModal({
title: '提示',
content: '确定把该商品移除购物车吗?',
2 years ago
success: function(res) {
2 years ago
if (res.confirm) {
2 years ago
console.log('用户点击确定,要删除的id', ids);
let params = {
ids: ids
};
deleteShoppingCart(params).then(res => {
let title;
2 years ago
if (res.return_code == '000000') {
2 years ago
title = res.return_data;
} else {
2 years ago
title = res.return_msg;
}
uni.showToast({
title: title,
icon: 'none',
duration: 2000
2 years ago
})
2 years ago
_this.initData();
2 years ago
2 years ago
})
2 years ago
2 years ago
} else if (res.cancel) {
2 years ago
console.log('用户点击取消');
}
}
});
2 years ago
2 years ago
},
2 years ago
2 years ago
changeNumValue(v, id) {
2 years ago
console.log(v, id)
2 years ago
// console.log(this.cartList)
let params = {
2 years ago
id: id,
2 years ago
num: v
2 years ago
}
2 years ago
2 years ago
goodsEditNum(params).then(res => {
2 years ago
if (res.return_code == '000000') {
2 years ago
// uni.showToast({
// title: res.return_data,
// icon: 'none',
// duration: 2000
// })
2 years ago
} else {
2 years ago
//增加数量失败
// this.cartList.map(item=>{
// if(item.id == id){
// item.num = 1;
// }
// })
2 years ago
2 years ago
//重新刷新数据
this.initData();
2 years ago
2 years ago
uni.showToast({
title: res.return_msg,
icon: 'none',
duration: 2000
})
}
2 years ago
2 years ago
})
}
2 years ago
}
2 years ago
2 years ago
}
</script>
<style lang="scss" scoped>
2 years ago
.bg-white {
background-color: #fff;
}
.cart-container {
height: 100vh;
padding: 10px 20rpx 0px;
box-sizing: border-box;
position: relative;
}
2 years ago
2 years ago
.cart-list {
height: calc(100vh - 70px);
2 years ago
}
2 years ago
// 列表
.cart-container2 {
2 years ago
display: flex;
align-items: center;
2 years ago
.mycheck {
// margin:0 20rpx;
2 years ago
}
2 years ago
.cart-detail {
2 years ago
flex: 1;
display: flex;
2 years ago
align-items: center;
padding: 0 10rpx;
.cart-img {
.img {
vertical-align: middle;
width: 200rpx;
height: 200rpx;
}
2 years ago
}
2 years ago
.cart-msg {
flex: 1;
align-self: flex-start;
padding-left: 20rpx;
2 years ago
display: flex;
2 years ago
flex-direction: column;
2 years ago
justify-content: space-between;
2 years ago
.cart-msg-title {}
.cart-msg-parm {}
.cart-msg-price {
display: flex;
align-items: center;
justify-content: space-between;
.cart-price {}
.cart-num {}
2 years ago
}
}
}
2 years ago
2 years ago
}
2 years ago
.pont-event {
pointer-events: none;
}
2 years ago
2 years ago
// 失效
2 years ago
.loseEfficacy {
2 years ago
2 years ago
.cart-img {
position: relative;
:before {
content: '商品失效';
display: block;
height: 20rpx;
width: 120rpx;
line-height: 20rpx;
padding: 20rpx;
border-radius: 20rpx;
background-color: #E6E6E6;
position: absolute;
top: calc(50% - 30rpx);
left: 20rpx;
z-index: 10;
font-size: 28rpx;
text-align: center;
}
2 years ago
}
2 years ago
background-color: #ffffff;
opacity: 0.8;
2 years ago
}
2 years ago
// 底部
.cart-tool {
position: absolute;
bottom: 0;
left: 0;
right: 0;
box-sizing: border-box;
padding: 10px;
height: 60px;
// line-height: 60px;
2 years ago
display: flex;
2 years ago
justify-content: space-between;
2 years ago
align-items: center;
2 years ago
.select-all {
display: flex;
align-items: center;
2 years ago
}
2 years ago
.tool-right {
flex: 1;
display: flex;
justify-content: flex-end;
align-items: center;
.tool-jiesuan {}
.jiesuan-btn {
width: 200rpx;
height: 40px;
line-height: 40px;
text-align: center;
border-radius: 20px;
background: linear-gradient(to right, #FFCC1E, #FF8F19);
}
2 years ago
}
}
2 years ago
</style>