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

fix[litemall-vue]: #245

parent 5e0be573
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
label="总计" label="总计"
@submit="cartSubmit" @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> </van-submit-bar>
</div> </div>
</template> </template>
...@@ -57,25 +57,16 @@ export default { ...@@ -57,25 +57,16 @@ export default {
checkedAll: false, checkedAll: false,
isSubmit: false, isSubmit: false,
checkedGoods: [], checkedGoods: [],
AllGoods: [], allGoods: [],
allCheckedStatus: false, goods: []
goods: [],
count: 0
}; };
}, },
activated() {
this.checkedAll = false;
this.isEditor = false;
this.isSubmit = false;
},
created() { created() {
this.init(); this.init();
}, },
computed: { computed: {
submitBarText() { submitBarText() {
const count = this.count; return this.isEditor ? '删除' : '结算';
return this.isEditor ? '删除' : `结算${count ? `(${count})` : ''}`;
}, },
totalPrice() { totalPrice() {
return this.goods.reduce( return this.goods.reduce(
...@@ -102,9 +93,8 @@ export default { ...@@ -102,9 +93,8 @@ export default {
init() { init() {
cartList().then(res => { cartList().then(res => {
this.goods = res.data.data.cartList; this.goods = res.data.data.cartList;
this.AllGoods = this.getAllList(); this.allGoods = this.getAllList();
this.checkedGoods = this.getCheckedList(this.goods); this.checkedGoods = this.getCheckedList(this.goods);
this.count = this.checkedGoods.length;
}); });
}, },
getAllList() { getAllList() {
...@@ -149,10 +139,10 @@ export default { ...@@ -149,10 +139,10 @@ export default {
} }
}, },
setCheckAll(val) { setCheckAll(val) {
if (this.checkedGoods.length === this.AllGoods.length) { if (this.checkedGoods.length === this.allGoods.length) {
this.checkedGoods = []; this.checkedGoods = [];
} else { } else {
this.checkedGoods = this.AllGoods; this.checkedGoods = this.allGoods;
} }
}, },
deleteCart(o) { deleteCart(o) {
...@@ -175,19 +165,25 @@ export default { ...@@ -175,19 +165,25 @@ export default {
}); });
let delProductIds = []; let delProductIds = [];
_.each(_.difference(this.AllGoods, index), v => { _.each(_.difference(this.allGoods, index), v => {
let productId = _.find(this.goods, result => { let productId = _.find(this.goods, result => {
return result.id === v; return result.id === v;
}).productId; }).productId;
delProductIds.push(productId); delProductIds.push(productId);
}); });
//没选中的不掉接口
if (delProductIds.length > 0) { if (delProductIds.length > 0) {
cartChecked({productIds: delProductIds, isChecked: 0}); cartChecked({productIds: delProductIds, isChecked: 0});
} }
if (addProductIds.length > 0) { if (addProductIds.length > 0) {
cartChecked({productIds: addProductIds, isChecked: 1}); cartChecked({productIds: addProductIds, isChecked: 1});
} }
if(index.length === this.allGoods.length){
this.checkedAll = true
}
else{
this.checkedAll = false
}
}, },
deleteNext(o) { deleteNext(o) {
let productIds = []; let productIds = [];
...@@ -199,9 +195,8 @@ export default { ...@@ -199,9 +195,8 @@ export default {
cartDelete({productIds: productIds}).then(res => { cartDelete({productIds: productIds}).then(res => {
this.goods = res.data.data.cartList; this.goods = res.data.data.cartList;
this.AllGoods = this.getAllList(); this.allGoods = this.getAllList();
this.checkedGoods = this.getCheckedList(this.goods); 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