|
|
@@ -16,12 +16,12 @@ |
|
|
|
<!-- 列表 --> |
|
|
|
<view class="cart-list"> |
|
|
|
<block v-for="(item, index) in cartList" :key="item.id"> |
|
|
|
<view class="cart-item" :class="{'b-b': index!==cartList.length-1}" :style="{'background':item.isset?'':'#f5f5f5'}" |
|
|
|
@click="navTo(`/pages/product/product?id=${item.product_id}&flash=0`)" |
|
|
|
> |
|
|
|
<view class="cart-item" :class="{'b-b': index!==cartList.length-1}" :style="{'background':item.isset?'':'#f5f5f5'}" |
|
|
|
@click="navTo(`/pages/product/product?id=${item.product_id}&flash=0`)"> |
|
|
|
<view class="image-wrapper"> |
|
|
|
<image :src="item.image" class="loaded" mode="aspectFill"></image> |
|
|
|
<view v-if="item.isset == true" class="yticon icon-xuanzhong checkbox" :class="{checked: item.choose}" @click.stop="check('item', index)"></view> |
|
|
|
<view v-if="item.isset == true" class="yticon icon-xuanzhong checkbox" :class="{checked: item.choose}" |
|
|
|
@click.stop="check('item', index)"></view> |
|
|
|
</view> |
|
|
|
<view class="item-right"> |
|
|
|
<text class="clamp title">{{item.title}}</text> |
|
|
@@ -39,7 +39,8 @@ |
|
|
|
<!-- 底部菜单栏 --> |
|
|
|
<view class="action-section" v-if="state != 'load'"> |
|
|
|
<view class="checkbox"> |
|
|
|
<image :src="allChoose?'/static/selected.png':'/static/select.png'" mode="aspectFit" @click="check('all')"></image> |
|
|
|
<image style="position: absolute;" :src="allChoose?'/static/selected.png':'/static/select.png'" mode="aspectFit" |
|
|
|
@click="check('all')"></image> |
|
|
|
<view class="clear-btn" :class="{show: allChoose}" @click="clearCart"> |
|
|
|
清空 |
|
|
|
</view> |
|
|
@@ -68,11 +69,11 @@ |
|
|
|
allChoose: false, //全选状态 true|false |
|
|
|
empty: false, //空白页现实 true|false |
|
|
|
cartList: [], |
|
|
|
state : 'load' |
|
|
|
state: 'load' |
|
|
|
}; |
|
|
|
}, |
|
|
|
onLoad() { |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
onPullDownRefresh() { |
|
|
|
this.state = 'load'; |
|
|
@@ -103,11 +104,11 @@ |
|
|
|
let data = await this.$api.request('/cart'); |
|
|
|
uni.stopPullDownRefresh(); |
|
|
|
this.state = 'loaded'; |
|
|
|
if (data){ |
|
|
|
if (data) { |
|
|
|
this.cartList = data; |
|
|
|
this.calcTotal(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
cartPrice(oldPrice, nowPrice) { |
|
|
@@ -128,18 +129,18 @@ |
|
|
|
}, |
|
|
|
//选中状态处理 |
|
|
|
async check(type, index) { |
|
|
|
|
|
|
|
|
|
|
|
let trueArr = []; |
|
|
|
let falseArr = []; |
|
|
|
let oldChoose = []; |
|
|
|
const list = this.cartList; |
|
|
|
//保存旧的数据 |
|
|
|
list.forEach(item => { |
|
|
|
if(item.choose){ |
|
|
|
if (item.choose) { |
|
|
|
oldChoose.push(item.cart_id); |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
//本地处理 |
|
|
|
if (type === 'item') { |
|
|
|
this.cartList[index].choose = !this.cartList[index].choose; |
|
|
@@ -163,9 +164,12 @@ |
|
|
|
this.allChoose = choose; |
|
|
|
} |
|
|
|
this.calcTotal(type); |
|
|
|
|
|
|
|
|
|
|
|
//远程处理 |
|
|
|
let result = await this.$api.request('/cart/choose_change', 'POST', {trueArr,falseArr}); |
|
|
|
let result = await this.$api.request('/cart/choose_change', 'POST', { |
|
|
|
trueArr, |
|
|
|
falseArr |
|
|
|
}); |
|
|
|
if (!result) { |
|
|
|
//恢复原来勾选的状态 |
|
|
|
list.forEach(item => { |
|
|
@@ -177,7 +181,7 @@ |
|
|
|
}) |
|
|
|
this.calcTotal(type); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
//数量 |
|
|
|
async numberChange(data) { |
|
|
@@ -185,28 +189,32 @@ |
|
|
|
let newNumber = data.number; |
|
|
|
this.cartList[data.index].number = newNumber; |
|
|
|
this.calcTotal(); |
|
|
|
|
|
|
|
|
|
|
|
let cart_id = this.cartList[data.index].cart_id; |
|
|
|
let result = await this.$api.request('/cart/number_change?id='+cart_id, 'GET', {number:newNumber}, false); |
|
|
|
let result = await this.$api.request('/cart/number_change?id=' + cart_id, 'GET', { |
|
|
|
number: newNumber |
|
|
|
}, false); |
|
|
|
if (!result) { |
|
|
|
this.cartList[data.index].number = oldNumber; |
|
|
|
this.calcTotal(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
//删除 |
|
|
|
async deleteCartItem(index) { |
|
|
|
let list = this.cartList; |
|
|
|
let row = list[index]; |
|
|
|
let id = row.cart_id; |
|
|
|
|
|
|
|
|
|
|
|
uni.showModal({ |
|
|
|
cancelText:'Cancel', |
|
|
|
confirmText:'OK', |
|
|
|
content: 'Confirm delete ' + list[index].title + '?' , |
|
|
|
cancelText: 'Cancel', |
|
|
|
confirmText: 'OK', |
|
|
|
content: 'Confirm delete ' + list[index].title + '?', |
|
|
|
success: async (e) => { |
|
|
|
if (e.confirm) { |
|
|
|
let result = await this.$api.request('/cart/delete?', 'POST', {id:id}); |
|
|
|
let result = await this.$api.request('/cart/delete?', 'POST', { |
|
|
|
id: id |
|
|
|
}); |
|
|
|
if (result) { |
|
|
|
let tempCart = this.cartList.splice(index, 1); |
|
|
|
this.calcTotal(); |
|
|
@@ -223,17 +231,19 @@ |
|
|
|
}); |
|
|
|
if (res.confirm) { |
|
|
|
let id = []; |
|
|
|
this.cartList.forEach(item=>{ |
|
|
|
this.cartList.forEach(item => { |
|
|
|
id.push(item.cart_id); |
|
|
|
}); |
|
|
|
let data = this.$api.request('/cart/delete', 'POST',{id:id}); |
|
|
|
let data = this.$api.request('/cart/delete', 'POST', { |
|
|
|
id: id |
|
|
|
}); |
|
|
|
let that = this; |
|
|
|
if (data) { |
|
|
|
setTimeout(function(){ |
|
|
|
setTimeout(function() { |
|
|
|
that.state = 'load'; |
|
|
|
that.cartList = []; |
|
|
|
that.getCart(); |
|
|
|
},300); |
|
|
|
}, 300); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
@@ -273,7 +283,7 @@ |
|
|
|
} |
|
|
|
this.$api.navTo(`/pages/order/createOrder?cart=${cartId.join(',')}`); |
|
|
|
}, |
|
|
|
navTo(url){ |
|
|
|
navTo(url) { |
|
|
|
this.$api.navTo(url); |
|
|
|
} |
|
|
|
} |
|
|
@@ -281,9 +291,10 @@ |
|
|
|
</script> |
|
|
|
|
|
|
|
<style lang='scss'> |
|
|
|
|
|
|
|
.container { |
|
|
|
padding-bottom: 134upx; |
|
|
|
|
|
|
|
|
|
|
|
/* 空白页 */ |
|
|
|
.empty { |
|
|
|
position: fixed; |
|
|
@@ -402,13 +413,13 @@ |
|
|
|
/* #ifdef H5 */ |
|
|
|
margin-bottom: 100upx; |
|
|
|
/* #endif */ |
|
|
|
position: fixed; |
|
|
|
position: absolute; |
|
|
|
left: 30upx; |
|
|
|
bottom: 30upx; |
|
|
|
right: 30upx; |
|
|
|
bottom: -80upx; |
|
|
|
z-index: 95; |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
width: 690upx; |
|
|
|
height: 100upx; |
|
|
|
padding: 0 30upx; |
|
|
|
background: rgba(255, 255, 255, .9); |
|
|
|