|
@@ -15,12 +15,12 @@
|
|
|
<view v-else>
|
|
|
<!-- 列表 -->
|
|
|
<view class="cart-list">
|
|
|
- <block v-for="(item, index) in cartList" :key="item.id">
|
|
|
+ <block v-for="(item, index) in cartList">
|
|
|
<view class="cart-item" :class="{ 'b-b': index !== cartList.length - 1 }">
|
|
|
<view class="image-wrapper">
|
|
|
<image
|
|
|
- :src="item.productInfo.image"
|
|
|
- :class="[item.loaded]"
|
|
|
+ :src="item.ActiveSku.image"
|
|
|
+ class="loaded"
|
|
|
mode="aspectFill"
|
|
|
lazy-load
|
|
|
@load="onImageLoad('cartList', index)"
|
|
@@ -29,27 +29,26 @@
|
|
|
<view class="iconfont iconroundcheckfill checkbox" :class="{ checked: item.checked }" @click="check('item', index)"></view>
|
|
|
</view>
|
|
|
<view class="item-right">
|
|
|
- <text class="clamp title">{{ item.productInfo.store_name }}</text>
|
|
|
+ <text class="clamp title">{{ item.product.store_name }}</text>
|
|
|
<!-- <text class="attr">{{ item.attr_val }}</text> -->
|
|
|
<view class="ex-addr">
|
|
|
<image src="../../static/img/shop.png" mode="" class="name-img"></image>
|
|
|
- 子臣台州旗舰店
|
|
|
+ {{item.mer_name}}
|
|
|
<image src="../../static/img/point.png" mode="" class="point-img"></image>
|
|
|
200m
|
|
|
</view>
|
|
|
- <text class="price">¥{{ item.productInfo.price }} <text class="oldprice">¥{{item.productInfo.oldPrice}}</text></text>
|
|
|
+ <text class="price">¥{{ item.ActiveSku.price }} <text class="oldprice">¥{{item.ActiveSku.ot_price}}</text></text>
|
|
|
<uni-number-box
|
|
|
class="step"
|
|
|
:min="1"
|
|
|
- :max="item.productInfo.stock"
|
|
|
- :value="item.cart_num > item.productInfo.stock ? item.productInfo.stock : item.cart_num"
|
|
|
- :isMax="item.cart_num >= item.productInfo.stock ? true : false"
|
|
|
+ :max="item.ActiveSku.stock"
|
|
|
+ :value="item.cart_num > item.ActiveSku.stock ? item.ActiveSku.stock : item.cart_num"
|
|
|
+ :isMax="item.cart_num >= item.ActiveSku.stock ? true : false"
|
|
|
:isMin="item.cart_num === 1"
|
|
|
:index="index"
|
|
|
@eventChange="numberChange"
|
|
|
></uni-number-box>
|
|
|
<text class="del-btn iconfont iconclose" @click="deleteCartItem(index)"></text>
|
|
|
-
|
|
|
</view>
|
|
|
<!-- <text class="del-btn iconfont iconclose" @click="deleteCartItem(index)"></text> -->
|
|
|
</view>
|
|
@@ -90,56 +89,7 @@ export default {
|
|
|
total: 0, //总价格
|
|
|
allChecked: false, //全选状态 true|false
|
|
|
empty: false, //空白页现实 true|false
|
|
|
- cartList: [
|
|
|
- {
|
|
|
- id: '11',
|
|
|
- productInfo: {
|
|
|
- image: '###',
|
|
|
- store_name: '鸭子总店',
|
|
|
- price: 99,
|
|
|
- stock: 99,
|
|
|
- oldPrice: 199
|
|
|
-
|
|
|
- },
|
|
|
- loaded: 'loaded',
|
|
|
- checked: false,
|
|
|
- attr_val: 1,
|
|
|
- cart_num: 1
|
|
|
-
|
|
|
- },
|
|
|
- {
|
|
|
- id: '11',
|
|
|
- productInfo: {
|
|
|
- image: '###',
|
|
|
- store_name: '鸭子总店',
|
|
|
- price: 99,
|
|
|
- stock: 99,
|
|
|
- oldPrice: 199
|
|
|
-
|
|
|
- },
|
|
|
- loaded: 'loaded',
|
|
|
- checked: false,
|
|
|
- attr_val: 1,
|
|
|
- cart_num: 1
|
|
|
-
|
|
|
- },
|
|
|
- {
|
|
|
- id: '11',
|
|
|
- productInfo: {
|
|
|
- image: '###',
|
|
|
- store_name: '鸭子总店',
|
|
|
- price: 99,
|
|
|
- stock: 99,
|
|
|
- oldPrice: 199
|
|
|
-
|
|
|
- },
|
|
|
- loaded: 'loaded',
|
|
|
- checked: false,
|
|
|
- attr_val: 1,
|
|
|
- cart_num: 1
|
|
|
-
|
|
|
- },
|
|
|
- ]
|
|
|
+ cartList: []
|
|
|
};
|
|
|
},
|
|
|
onShow() {
|
|
@@ -165,26 +115,39 @@ export default {
|
|
|
async loadData() {
|
|
|
let obj = this;
|
|
|
getCartList({})
|
|
|
- .then(function(e) {
|
|
|
+ .then(function(e) {
|
|
|
+ console.log(e.data.list)
|
|
|
+ let list = []
|
|
|
+ e.data.list.forEach( item => {
|
|
|
+ for(let i = 0 ; i < item.list.length; i++){
|
|
|
+ let newList = item.list[i]
|
|
|
+ newList.mer_name = item.mer_name
|
|
|
+ newList.checked = true
|
|
|
+ item.loaded = 'loaded';
|
|
|
+ list.push(newList)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log(list,"处理后的list")
|
|
|
+ obj.cartList = list
|
|
|
// 获取当前购物车物品增加数量
|
|
|
- let nub = obj.cartList.length;
|
|
|
+ // let nub = obj.cartList.length;
|
|
|
// 获取之前对象数组
|
|
|
- let aArray = obj.cartList.reverse();
|
|
|
+ // let aArray = obj.cartList.reverse();
|
|
|
// 获取返回数据对象数组
|
|
|
- let bArray = e.data.valid.reverse();
|
|
|
- obj.cartList = bArray
|
|
|
- .map((item, ind) => {
|
|
|
- // 设置返回数据默认为勾选状态
|
|
|
- item.checked = true;
|
|
|
- // 获取相同数组之前对象的数据
|
|
|
- let carlist = aArray[ind];
|
|
|
- // 判断之前是否已经加载完毕
|
|
|
- if (carlist && carlist.loaded == 'loaded') {
|
|
|
- item.loaded = 'loaded';
|
|
|
- }
|
|
|
- return item;
|
|
|
- })
|
|
|
- .reverse();
|
|
|
+ // let bArray = e.data.valid.reverse();
|
|
|
+ // obj.cartList = bArray
|
|
|
+ // .map((item, ind) => {
|
|
|
+ // // 设置返回数据默认为勾选状态
|
|
|
+ // item.checked = true;
|
|
|
+ // // 获取相同数组之前对象的数据
|
|
|
+ // let carlist = aArray[ind];
|
|
|
+ // // 判断之前是否已经加载完毕
|
|
|
+ // if (carlist && carlist.loaded == 'loaded') {
|
|
|
+ // item.loaded = 'loaded';
|
|
|
+ // }
|
|
|
+ // return item;
|
|
|
+ // })
|
|
|
+ // .reverse();
|
|
|
obj.calcTotal(); //计算总价
|
|
|
})
|
|
|
.catch(function(e) {
|
|
@@ -193,7 +156,8 @@ export default {
|
|
|
},
|
|
|
//监听image加载完成
|
|
|
onImageLoad(key, index) {
|
|
|
- // 修改载入完成后图片class样式
|
|
|
+ // 修改载入完成后图片class样式
|
|
|
+ console.log("ok")
|
|
|
this.$set(this[key][index], 'loaded', 'loaded');
|
|
|
},
|
|
|
//监听image加载失败
|
|
@@ -222,10 +186,11 @@ export default {
|
|
|
this.calcTotal(type);
|
|
|
},
|
|
|
//数量
|
|
|
- numberChange(data) {
|
|
|
+ numberChange(data) {
|
|
|
+ console.log(data)
|
|
|
let arr = this.cartList[data.index];
|
|
|
arr.cart_num = data.number;
|
|
|
- getCartNum({ id: arr.id, number: data.number })
|
|
|
+ getCartNum( arr.cart_id, {cart_num: data.number })
|
|
|
.then(e => {
|
|
|
console.log(e);
|
|
|
})
|
|
@@ -237,10 +202,12 @@ export default {
|
|
|
//删除
|
|
|
deleteCartItem(index) {
|
|
|
let list = this.cartList;
|
|
|
- let row = list[index];
|
|
|
- let id = row.id;
|
|
|
+ let row = list[index];
|
|
|
+ let delList = []
|
|
|
+ delList.push(row.cart_id)
|
|
|
+ // let id = row.id;
|
|
|
cartDel({
|
|
|
- ids: id
|
|
|
+ cart_id: delList
|
|
|
});
|
|
|
this.cartList.splice(index, 1);
|
|
|
uni.hideLoading();
|
|
@@ -251,12 +218,17 @@ export default {
|
|
|
uni.showModal({
|
|
|
content: '清空购物车?',
|
|
|
success: e => {
|
|
|
- if (e.confirm) {
|
|
|
- let st = this.cartList.map(e => {
|
|
|
- return e.id;
|
|
|
- });
|
|
|
+ if (e.confirm) {
|
|
|
+ let list = []
|
|
|
+ this.cartList.forEach(item => {
|
|
|
+ list.push(item.cart_id)
|
|
|
+ })
|
|
|
+ // let st = this.cartList.map(e => {
|
|
|
+ // return e.cart_id;
|
|
|
+ // });
|
|
|
+ // console.log(st.join(','))
|
|
|
cartDel({
|
|
|
- ids: st.join(',')
|
|
|
+ cart_id: list
|
|
|
}).then(e => {
|
|
|
console.log(e);
|
|
|
});
|
|
@@ -276,7 +248,7 @@ export default {
|
|
|
let checked = true;
|
|
|
list.forEach(item => {
|
|
|
if (item.checked === true) {
|
|
|
- total += item.productInfo.price * item.cart_num;
|
|
|
+ total += item.ActiveSku.price * item.cart_num;
|
|
|
} else if (checked === true) {
|
|
|
checked = false;
|
|
|
}
|
|
@@ -407,6 +379,9 @@ export default {
|
|
|
display: inline-block;
|
|
|
padding-left: 10rpx;
|
|
|
}
|
|
|
+ }
|
|
|
+ .title {
|
|
|
+ width: 350rpx;
|
|
|
}
|
|
|
.attr {
|
|
|
font-size: $font-sm + 2rpx;
|