|
|
|
@ -2,41 +2,49 @@
|
|
|
|
|
<view class="container">
|
|
|
|
|
<!-- 页面顶部 -->
|
|
|
|
|
<UiPageHeader :back="true">
|
|
|
|
|
<template slot="title">
|
|
|
|
|
<text>购物车</text>
|
|
|
|
|
<text v-if="total">({{total}})</text>
|
|
|
|
|
</template>
|
|
|
|
|
<template slot="operation" v-if="list.length">
|
|
|
|
|
<template slot="custom">
|
|
|
|
|
<view>
|
|
|
|
|
<text>购物车</text>
|
|
|
|
|
<text v-if="list.length">({{list.length}})</text>
|
|
|
|
|
</view>
|
|
|
|
|
<view v-if="mode == 'normal'" class="head--edit" @click="handleToggleMode">编辑</view>
|
|
|
|
|
<view v-else class="head--finsh" @click="handleToggleMode">完成</view>
|
|
|
|
|
</template>
|
|
|
|
|
</UiPageHeader>
|
|
|
|
|
|
|
|
|
|
<u-loadmore v-if="isLoading" status="loading" />
|
|
|
|
|
<!-- 购物车数据为空 -->
|
|
|
|
|
<BsEmpty v-if="!list.length && !isLoading" class="empty"
|
|
|
|
|
tips="去挑点喜欢的好货吧~">
|
|
|
|
|
<image slot="icon" class="empty--icon" src="@/static/goods/cart.png"></image>
|
|
|
|
|
<view slot="btn" class="empty--btn" @click="$Router.push('/')">去逛逛</view>
|
|
|
|
|
</BsEmpty>
|
|
|
|
|
|
|
|
|
|
<!-- 购物车商品列表 -->
|
|
|
|
|
<view v-if="list.length" class="cart-list">
|
|
|
|
|
<view v-else class="cart-list">
|
|
|
|
|
<view class="cart-item" v-for="(item, index) in list" :key="index"
|
|
|
|
|
@click="onTargetGoods(item.goods_id)">
|
|
|
|
|
@click="$Router.push(`goodsDetail?id=${item.id}`)">
|
|
|
|
|
<label class="cart-item--radio" @click.stop="handleCheckItem(item.id)">
|
|
|
|
|
<radio class="radio" color="#FF875B"
|
|
|
|
|
:checked="checkedIds.length ? checkedIds.find(i => i === item.id) : false" />
|
|
|
|
|
:checked="checkedIds.length ? checkedIds.includes(item.id) : false" />
|
|
|
|
|
</label>
|
|
|
|
|
<image class="cart-item--image" :src="item.goods.goods_image" mode="scaleToFill"></image>
|
|
|
|
|
<image class="cart-item--image" :src="item.product.mainPicture" mode="scaleToFill"></image>
|
|
|
|
|
<view class="cart-item--content">
|
|
|
|
|
<view class="cart-item--title"><text>{{ item.goods.goods_name }}</text></view>
|
|
|
|
|
<view class="cart-item--title"><text>{{ item.product.name }}</text></view>
|
|
|
|
|
<view class="cart-item--props">
|
|
|
|
|
<view class="cart-item--props-item" v-for="(props, idx) in item.goods.skuInfo.goods_props" :key="idx">
|
|
|
|
|
<text>{{ props.value.name }}</text>
|
|
|
|
|
<view class="cart-item--props-item" >
|
|
|
|
|
<text>{{ item.productSku.name }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="cart-item--footer">
|
|
|
|
|
<view class="cart-item--price">
|
|
|
|
|
<text class="unit">¥</text>
|
|
|
|
|
<text class="value">{{ item.goods.skuInfo.goods_price }}</text>
|
|
|
|
|
<text class="value">{{ item.productSku.sellPrice }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="cart-item--stepper">
|
|
|
|
|
<u-number-box :min="1" button-size="40rpx" bgColor="#F5F6FA"
|
|
|
|
|
:value="item.goods_num" @change="onChangeStepper($event, item)" >
|
|
|
|
|
:value="item.number" :max="item.maxBuyNum" @change="onChangeStepper($event, item)" >
|
|
|
|
|
<text slot="minus" class="cart-item--stepper-icon">-</text>
|
|
|
|
|
<!-- <text slot="input" class="cart-item--stepper-input">{{item.goods_num}}</text> -->
|
|
|
|
|
<text slot="plus" class="cart-item--stepper-icon">+</text>
|
|
|
|
|
</u-number-box>
|
|
|
|
|
</view>
|
|
|
|
@ -44,19 +52,16 @@
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<template v-if="!isLoading">
|
|
|
|
|
<view class="title">为您推荐</view>
|
|
|
|
|
<BsGoodsGroup></BsGoodsGroup>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<!-- 购物车数据为空 -->
|
|
|
|
|
<BsEmpty v-if="!list.length" class="empty"
|
|
|
|
|
tips="去挑点喜欢的好货吧~">
|
|
|
|
|
<image slot="icon" class="empty--icon" src="@/static/goods/cart.png"></image>
|
|
|
|
|
<view slot="btn" class="empty--btn" @click="onTargetIndex">去逛逛</view>
|
|
|
|
|
</BsEmpty>
|
|
|
|
|
<view class="title">为您推荐</view>
|
|
|
|
|
<BsGoodsGroup></BsGoodsGroup>
|
|
|
|
|
<!-- 底部操作栏 -->
|
|
|
|
|
<view v-if="!list.length" class="footer">
|
|
|
|
|
<view v-if="list.length" class="footer">
|
|
|
|
|
<label class="all-radio" @click="handleCheckAll">
|
|
|
|
|
<radio class="radio" color="#fa2209" :checked="checkedIds.length > 0 && checkedIds.length === list.length" />
|
|
|
|
|
<radio class="radio" color="#fa2209"
|
|
|
|
|
:checked="checkedIds.length > 0 && checkedIds.length === list.length" />
|
|
|
|
|
<text>全选</text>
|
|
|
|
|
</label>
|
|
|
|
|
<view class="total-info">
|
|
|
|
@ -71,12 +76,12 @@
|
|
|
|
|
<!-- dev:下面的disabled条件使用checkedIds.join方式判断 -->
|
|
|
|
|
<!-- dev:通常情况下vue项目使用checkedIds.length更合理, 但是length属性在微信小程序中不起作用 -->
|
|
|
|
|
<view v-if="mode == 'normal'" class="btn-item btn-main" :class="{ disabled: checkedIds.length === 0 }"
|
|
|
|
|
@click="handleOrder()">
|
|
|
|
|
<text>去结算 {{ checkedIds.length > 0 ? `(${checkedIds.length})` : '' }}</text>
|
|
|
|
|
@click="handleOrder()">
|
|
|
|
|
<text>去结算 {{ checkedIds.length > 0 ? `(${checkedIds.length})` : '' }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
<view v-if="mode == 'edit'" class="btn-item btn-main" :class="{ disabled: !checkedIds.length }"
|
|
|
|
|
@click="handleDelete()">
|
|
|
|
|
<text>删除</text>
|
|
|
|
|
@click="handleDelete()">
|
|
|
|
|
<text>删除</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
@ -84,203 +89,208 @@
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { debounce } from '@/common/utils/utils';
|
|
|
|
|
import BsEmpty from '@/components/BsEmpty.vue';
|
|
|
|
|
import BsGoodsGroup from '@/components/BsGoodsGroup.vue';
|
|
|
|
|
import cartData from '@/mock/cart.json'
|
|
|
|
|
<script>import { Debounce } from '@/common/utils';
|
|
|
|
|
import BsEmpty from '@/components/BsEmpty.vue';
|
|
|
|
|
import BsGoodsGroup from '@/components/BsGoodsGroup.vue';
|
|
|
|
|
import UiPageHeader from '../../components/UiPageHeader.vue';
|
|
|
|
|
import {ApiGetCartList, ApiPutCartNum, ApiDeleteCartGoods} from '@/common/api/cart';
|
|
|
|
|
|
|
|
|
|
const CartIdsIndex = 'CartIds'
|
|
|
|
|
const CartIdsIndex = 'CartIds'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
BsEmpty,
|
|
|
|
|
BsGoodsGroup,
|
|
|
|
|
UiPageHeader
|
|
|
|
|
BsEmpty,
|
|
|
|
|
BsGoodsGroup,
|
|
|
|
|
UiPageHeader
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
// 正在加载
|
|
|
|
|
isLoading: true,
|
|
|
|
|
// 当前模式: normal正常 edit编辑
|
|
|
|
|
mode: 'normal',
|
|
|
|
|
// 购物车商品列表
|
|
|
|
|
list: [],
|
|
|
|
|
// 购物车商品总数量
|
|
|
|
|
total: null,
|
|
|
|
|
// 选中的商品ID记录
|
|
|
|
|
checkedIds: [],
|
|
|
|
|
// 选中的商品总金额
|
|
|
|
|
totalPrice: '0.00'
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
// 正在加载
|
|
|
|
|
isLoading: true,
|
|
|
|
|
// 当前模式: normal正常 edit编辑
|
|
|
|
|
mode: 'normal',
|
|
|
|
|
// 购物车商品列表
|
|
|
|
|
list: [],
|
|
|
|
|
// 购物车商品总数量
|
|
|
|
|
total: null,
|
|
|
|
|
// 选中的商品ID记录
|
|
|
|
|
checkedIds: [],
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
// 监听选中的商品
|
|
|
|
|
checkedIds: {
|
|
|
|
|
handler(val) {
|
|
|
|
|
// 计算合计金额
|
|
|
|
|
this.onCalcTotalPrice()
|
|
|
|
|
// 记录到缓存中
|
|
|
|
|
uni.setStorageSync(CartIdsIndex, val)
|
|
|
|
|
},
|
|
|
|
|
immediate: false
|
|
|
|
|
},
|
|
|
|
|
// 监听购物车商品总数量
|
|
|
|
|
total(val) {
|
|
|
|
|
// 缓存并设置角标
|
|
|
|
|
// setCartTotalNum(val)
|
|
|
|
|
// setCartTabBadge()
|
|
|
|
|
}
|
|
|
|
|
// 监听选中的商品
|
|
|
|
|
checkedIds: {
|
|
|
|
|
handler(val) {
|
|
|
|
|
// 记录到缓存中
|
|
|
|
|
console.log(val);
|
|
|
|
|
uni.setStorageSync(CartIdsIndex, val)
|
|
|
|
|
},
|
|
|
|
|
immediate: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed : {
|
|
|
|
|
totalPrice(){
|
|
|
|
|
const checkedList = this.list.filter(item => this.checkedIds.includes(item.id));
|
|
|
|
|
let tempPrice = 0;
|
|
|
|
|
checkedList.forEach(item => {
|
|
|
|
|
// 商品单价, 为了方便计算先转换单位为分 (整数)
|
|
|
|
|
const unitPrice = item.productSku.sellPrice * 100
|
|
|
|
|
tempPrice += unitPrice * item.number
|
|
|
|
|
});
|
|
|
|
|
return (tempPrice / 100).toFixed(2)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow(options) {
|
|
|
|
|
// 获取购物车商品列表
|
|
|
|
|
// checkLogin() ? this.getCartList() : this.isLoading = false
|
|
|
|
|
this.isLoading = false
|
|
|
|
|
// 获取缓存中的选中记录
|
|
|
|
|
this.checkedIds = uni.getStorageSync(CartIdsIndex)
|
|
|
|
|
// 获取购物车商品列表
|
|
|
|
|
this.getCartList();
|
|
|
|
|
this.isLoading = false
|
|
|
|
|
// 获取缓存中的选中记录
|
|
|
|
|
this.checkedIds = uni.getStorageSync(CartIdsIndex)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
|
|
// 计算合计金额 (根据选中的商品)
|
|
|
|
|
onCalcTotalPrice() {
|
|
|
|
|
const app = this
|
|
|
|
|
// 选中的商品记录
|
|
|
|
|
const checkedList = app.list.filter(item => app.checkedIds.length ? app.checkedIds.find(i => i === item.id) : false)
|
|
|
|
|
// 计算总金额
|
|
|
|
|
let tempPrice = 0;
|
|
|
|
|
checkedList.forEach(item => {
|
|
|
|
|
// 商品单价, 为了方便计算先转换单位为分 (整数)
|
|
|
|
|
const unitPrice = item.goods.skuInfo.goods_price * 100
|
|
|
|
|
tempPrice += unitPrice * item.goods_num
|
|
|
|
|
})
|
|
|
|
|
app.totalPrice = (tempPrice / 100).toFixed(2)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 获取购物车商品列表
|
|
|
|
|
getCartList() {
|
|
|
|
|
const app = this
|
|
|
|
|
app.isLoading = true
|
|
|
|
|
// CartApi.list()
|
|
|
|
|
// .then(result => {
|
|
|
|
|
// app.list = result.data.list
|
|
|
|
|
// app.total = result.data.cartTotal
|
|
|
|
|
// // 清除checkedIds中无效的ID
|
|
|
|
|
// app.onClearInvalidId()
|
|
|
|
|
// })
|
|
|
|
|
// .finally(() => app.isLoading = false)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 清除checkedIds中无效的ID
|
|
|
|
|
onClearInvalidId() {
|
|
|
|
|
const app = this
|
|
|
|
|
const listIds = app.list.map(item => item.id)
|
|
|
|
|
app.checkedIds = listIds.filter(val => checkedIds.indexOf(val) > -1)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 切换当前模式
|
|
|
|
|
handleToggleMode() {
|
|
|
|
|
this.mode = this.mode == 'normal' ? 'edit' : 'normal'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 监听步进器更改事件
|
|
|
|
|
onChangeStepper({ value }, item) {
|
|
|
|
|
// 这里是组织首次启动时的执行
|
|
|
|
|
if (item.goods_num == value) return
|
|
|
|
|
// 记录一个节流函数句柄
|
|
|
|
|
if (!item.debounceHandle) {
|
|
|
|
|
item.oldValue = item.goods_num
|
|
|
|
|
item.debounceHandle = debounce(this.onUpdateCartNum, 500)
|
|
|
|
|
}
|
|
|
|
|
// 更新商品数量
|
|
|
|
|
item.goods_num = value
|
|
|
|
|
// 提交更新购物车数量 (节流)
|
|
|
|
|
item.debounceHandle(item, item.oldValue, value)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 提交更新购物车数量
|
|
|
|
|
onUpdateCartNum(item, oldValue, newValue) {
|
|
|
|
|
const app = this
|
|
|
|
|
// CartApi.update(item.goods_id, item.goods_sku_id, newValue)
|
|
|
|
|
// .then(result => {
|
|
|
|
|
// // 更新商品数量
|
|
|
|
|
// app.total = result.data.cartTotal
|
|
|
|
|
// // 重新计算合计金额
|
|
|
|
|
// app.onCalcTotalPrice()
|
|
|
|
|
// // 清除节流函数句柄
|
|
|
|
|
// item.debounceHandle = null
|
|
|
|
|
// })
|
|
|
|
|
// .catch(err => {
|
|
|
|
|
// // 还原商品数量
|
|
|
|
|
// item.goods_num = oldValue
|
|
|
|
|
// setTimeout(() => app.$toast(err.errMsg), 10)
|
|
|
|
|
// })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 跳转到商品详情页
|
|
|
|
|
onTargetGoods(goodsId) {
|
|
|
|
|
this.$navTo('pages/goods/detail', { goodsId })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 点击去逛逛按钮, 跳转到首页
|
|
|
|
|
onTargetIndex() {
|
|
|
|
|
this.$navTo('pages/index/index')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 选中商品
|
|
|
|
|
handleCheckItem(cartId) {
|
|
|
|
|
const { checkedIds } = this
|
|
|
|
|
const index = checkedIds.findIndex(id => id === cartId)
|
|
|
|
|
index < 0 ? checkedIds.push(cartId) : checkedIds.splice(index, 1)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 全选事件
|
|
|
|
|
handleCheckAll() {
|
|
|
|
|
const { checkedIds, list } = this
|
|
|
|
|
this.checkedIds = checkedIds.length === list.length ? [] : list.map(item => item.id)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 结算选中的商品
|
|
|
|
|
handleOrder() {
|
|
|
|
|
const app = this
|
|
|
|
|
app.$Router.push({path : '/orderSubmit', query:{mode: 'cart', ids : '1,2,3'}})
|
|
|
|
|
if (app.checkedIds.length) {
|
|
|
|
|
const cartIds = app.checkedIds.join()
|
|
|
|
|
app.$Router.push('orderSubmit', { mode: 'cart', cartIds })
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 获取购物车商品列表
|
|
|
|
|
*/
|
|
|
|
|
async getCartList() {
|
|
|
|
|
this.isLoading = true;
|
|
|
|
|
const {error, result} = await ApiGetCartList();
|
|
|
|
|
if(error){
|
|
|
|
|
uni.$u.toast(error.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
this.list = result.map(item => {
|
|
|
|
|
const singleBuyLimit = item.product.singleBuyLimit;
|
|
|
|
|
const stock = item.productSku.stock;
|
|
|
|
|
const maxBuyNum = singleBuyLimit ? Math.min(singleBuyLimit, stock || 1) : stock
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
maxBuyNum
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.onClearInvalidId();
|
|
|
|
|
this.isLoading = false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 清除checkedIds中无效的ID
|
|
|
|
|
*/
|
|
|
|
|
onClearInvalidId() {
|
|
|
|
|
// const app = this
|
|
|
|
|
// const listIds = app.list.map(item => item.id)
|
|
|
|
|
this.checkedIds = this.checkedIds.filter(i => this.list.findIndex(item => item.id === i));
|
|
|
|
|
// listIds.filter(val => checkedIds.indexOf(val) > -1)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 切换当前模式
|
|
|
|
|
*/
|
|
|
|
|
handleToggleMode() {
|
|
|
|
|
this.mode = this.mode == 'normal' ? 'edit' : 'normal'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 监听步进器更改事件
|
|
|
|
|
*/
|
|
|
|
|
onChangeStepper({ value }, item) {
|
|
|
|
|
|
|
|
|
|
// 这里是组织首次启动时的执行
|
|
|
|
|
if (item.number == value) {
|
|
|
|
|
uni.$u.toast('数量不能再少了');
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
// 记录一个节流函数句柄
|
|
|
|
|
if (!item.debounceHandle) {
|
|
|
|
|
item.oldValue = item.number
|
|
|
|
|
item.debounceHandle = Debounce(this.updateCartNum, 500)
|
|
|
|
|
}
|
|
|
|
|
// 更新商品数量
|
|
|
|
|
item.number = value
|
|
|
|
|
// 提交更新购物车数量 (节流)
|
|
|
|
|
item.debounceHandle(item, item.oldValue, value);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提交更新购物车数量
|
|
|
|
|
*/
|
|
|
|
|
async updateCartNum(item, oldValue, newValue) {
|
|
|
|
|
const {error, result} = await ApiPutCartNum({
|
|
|
|
|
id : item.id,
|
|
|
|
|
number : item.number
|
|
|
|
|
});
|
|
|
|
|
if(error){
|
|
|
|
|
this.$toast(error.message);
|
|
|
|
|
item.number = item.sku;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(result.isBeyondMaxLimit){
|
|
|
|
|
uni.$u.toast('数量超出范围');
|
|
|
|
|
item.number = result.canSetShoppingCartNumber;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除选中的商品弹窗事件
|
|
|
|
|
handleDelete() {
|
|
|
|
|
const app = this
|
|
|
|
|
if (!app.checkedIds.length) {
|
|
|
|
|
return false
|
|
|
|
|
/**
|
|
|
|
|
* 选中商品
|
|
|
|
|
*/
|
|
|
|
|
handleCheckItem(cartId) {
|
|
|
|
|
const { checkedIds } = this
|
|
|
|
|
const index = checkedIds.findIndex(id => id === cartId)
|
|
|
|
|
index < 0 ? checkedIds.push(cartId) : checkedIds.splice(index, 1)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 全选事件
|
|
|
|
|
*/
|
|
|
|
|
handleCheckAll() {
|
|
|
|
|
const { checkedIds, list } = this
|
|
|
|
|
this.checkedIds = checkedIds.length === list.length ? [] : list.map(item => item.id)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 结算选中的商品
|
|
|
|
|
*/
|
|
|
|
|
handleOrder() {
|
|
|
|
|
const ids = this.checkedIds;
|
|
|
|
|
if (ids.length) {
|
|
|
|
|
app.$Router.push('orderSubmit', { mode: 'cart', ids:ids.join(',') })
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除选中的商品
|
|
|
|
|
*/
|
|
|
|
|
handleDelete() {
|
|
|
|
|
const ids = this.checkedIds;
|
|
|
|
|
if (!ids.length) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: '友情提示',
|
|
|
|
|
content: '您确定要删除该商品吗?',
|
|
|
|
|
showCancel: true,
|
|
|
|
|
success:async ()=> {
|
|
|
|
|
const {error} = await ApiDeleteCartGoods({idList : ids.join(',')});
|
|
|
|
|
if(error){
|
|
|
|
|
uni.$u.toast(error.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
this.list = this.list.filter(item => !ids.includes(item.id));
|
|
|
|
|
// this.checkedIds = [];
|
|
|
|
|
this.onClearInvalidId();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: '友情提示',
|
|
|
|
|
content: '您确定要删除该商品吗?',
|
|
|
|
|
showCancel: true,
|
|
|
|
|
success({ confirm }) {
|
|
|
|
|
// 确认删除
|
|
|
|
|
confirm && app.onClearCart()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 确认删除商品
|
|
|
|
|
onClearCart() {
|
|
|
|
|
const app = this
|
|
|
|
|
// CartApi.clear(app.checkedIds)
|
|
|
|
|
// .then(result => app.getCartList())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|