Commit addd27d9 authored by Damon's avatar Damon

fix: 配件更新购物车

parent cf9e94e7
......@@ -53,8 +53,8 @@
:key="index"
:info="item"
:show-checked="false"
@numChange="numChange($event, index)"
@apply="apply(index)"
@numChange="numChange($event, item, index)"
@apply="apply(item, index)"
></select-parts>
<view class="load-more">
<u-loadmore :status="loadStatus" @loadmore="loadMore" />
......@@ -98,6 +98,7 @@ export default {
scrollId: '',
loadStatus: "loadmore",
lists: [],
submitList: [],
pageSize: 20,
pageNumber: 1
};
......@@ -110,11 +111,11 @@ export default {
},
// 配件数
partNum() {
return this.lists.reduce((counter, item) => !item.disabled && item.quantity > 0 ? counter += 1 : counter, 0)
return this.submitList.reduce((counter, item) => !item.disabled && item.quantity > 0 ? counter += 1 : counter, 0)
},
// 总数
num() {
return this.lists.reduce((counter, { disabled, quantity }) => !disabled ? counter += quantity : counter, 0)
return this.submitList.reduce((counter, { disabled, quantity }) => !disabled ? counter += quantity : counter, 0)
}
},
created() {
......@@ -219,16 +220,24 @@ export default {
}
},
// 加入申请
apply(index) {
apply(item, index) {
this.$set(this.lists[index], 'disabled', false)
// 如果购物车没有该记录,则添加
const findIndex = this.submitList.findIndex(v => v.id === item.id)
if (findIndex === -1) this.submitList.push(item)
},
// 改变数量
numChange(val, index) {
numChange(val, item, index) {
this.$set(this.lists[index], 'quantity', val)
// 如果购物车有该记录,则更新
const findIndex = this.submitList.findIndex(v => v.id === item.id)
this.$set(this.submitList[findIndex], 'quantity', val)
},
// 提交
submit() {
const lists = this.lists.filter(v => !v.disabled).map(v => {
const lists = this.submitList.filter(v => !v.disabled && v.quantity > 0).map(v => {
return {
part_id: v.skuId,
name: v.name,
......
Markdown is supported
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