Commit 62f400a1 authored by Junling Bu's avatar Junling Bu
Browse files

fix[litemall-vue]: #245

parent 5e0be573
......@@ -37,7 +37,7 @@
label="总计"
@submit="cartSubmit"
>
<van-checkbox v-model="allCheckedStatus" @change="setCheckAll" style="padding: 0 10px;">全选</van-checkbox>
<van-checkbox v-model="checkedAll" @click="setCheckAll" style="padding: 0 10px;">全选</van-checkbox>
</van-submit-bar>
</div>
</template>
......@@ -57,25 +57,16 @@ export default {
checkedAll: false,
isSubmit: false,
checkedGoods: [],
AllGoods: [],
allCheckedStatus: false,
goods: [],
count: 0
allGoods: [],
goods: []
};
},
activated() {
this.checkedAll = false;
this.isEditor = false;
this.isSubmit = false;
},
created() {
this.init();
},
computed: {
submitBarText() {
const count = this.count;
return this.isEditor ? '删除' : `结算${count ? `(${count})` : ''}`;
return this.isEditor ? '删除' : '结算';
},
totalPrice() {
return this.goods.reduce(
......@@ -102,9 +93,8 @@ export default {
init() {
cartList().then(res => {
this.goods = res.data.data.cartList;
this.AllGoods = this.getAllList();
this.allGoods = this.getAllList();
this.checkedGoods = this.getCheckedList(this.goods);
this.count = this.checkedGoods.length;
});
},
getAllList() {
......@@ -149,10 +139,10 @@ export default {
}
},
setCheckAll(val) {
if (this.checkedGoods.length === this.AllGoods.length) {
if (this.checkedGoods.length === this.allGoods.length) {
this.checkedGoods = [];
} else {
this.checkedGoods = this.AllGoods;
this.checkedGoods = this.allGoods;
}
},
deleteCart(o) {
......@@ -175,19 +165,25 @@ export default {
});
let delProductIds = [];
_.each(_.difference(this.AllGoods, index), v => {
_.each(_.difference(this.allGoods, index), v => {
let productId = _.find(this.goods, result => {
return result.id === v;
}).productId;
delProductIds.push(productId);
});
//没选中的不掉接口
if (delProductIds.length > 0) {
cartChecked({productIds: delProductIds, isChecked: 0});
}
if (addProductIds.length > 0) {
cartChecked({productIds: addProductIds, isChecked: 1});
}
if(index.length === this.allGoods.length){
this.checkedAll = true
}
else{
this.checkedAll = false
}
},
deleteNext(o) {
let productIds = [];
......@@ -199,9 +195,8 @@ export default {
cartDelete({productIds: productIds}).then(res => {
this.goods = res.data.data.cartList;
this.AllGoods = this.getAllList();
this.allGoods = this.getAllList();
this.checkedGoods = this.getCheckedList(this.goods);
this.count = this.checkedGoods.length;
});
}
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment