|
@@ -176,12 +176,29 @@
|
|
|
})
|
|
|
this.$store.state.vuex_tempData = null
|
|
|
this.promoActiveSn = opts.promoActiveSn
|
|
|
+ // 查询产品列表
|
|
|
this.pageInit()
|
|
|
},
|
|
|
+ onUnload() {
|
|
|
+ // 存储已选列表值
|
|
|
+ const hasCache = this.$store.state.vuex_cartList.find(k => k.sn == this.promoActiveSn)
|
|
|
+ if(hasCache){
|
|
|
+ hasCache.list = this.chooseList
|
|
|
+ }else{
|
|
|
+ this.$store.state.vuex_cartList.push({sn:this.promoActiveSn,list: this.chooseList})
|
|
|
+ }
|
|
|
+ this.$u.vuex('vuex_cartList', this.$store.state.vuex_cartList)
|
|
|
+ },
|
|
|
methods: {
|
|
|
// 初始化页面
|
|
|
pageInit(){
|
|
|
this.screenWidth = uni.getSystemInfoSync().windowWidth
|
|
|
+ // 购物车是否有缓存
|
|
|
+ const hasCache = this.$store.state.vuex_cartList.find(k => k.sn == this.promoActiveSn)
|
|
|
+ if(hasCache){
|
|
|
+ this.chooseList = hasCache.list
|
|
|
+ }
|
|
|
+ // 重置分页
|
|
|
this.total = 0
|
|
|
this.pageNo = 1
|
|
|
// 获取列表数据
|
|
@@ -193,8 +210,9 @@
|
|
|
item.checked = true
|
|
|
item.qty = 1
|
|
|
item.show = false
|
|
|
- this.chooseList.unshift(item)
|
|
|
+ this.chooseList.unshift(this.$u.deepClone(item))
|
|
|
}else{
|
|
|
+ item.qty = item.qty + 1
|
|
|
// 已添加,则增加数量
|
|
|
const row = this.chooseList.find(key => key.id == item.id)
|
|
|
if(row){
|
|
@@ -252,6 +270,10 @@
|
|
|
const rindex = this.chooseList.findIndex(key => key.id == e.index)
|
|
|
this.chooseList[rindex].qty = e.value
|
|
|
this.chooseList.splice()
|
|
|
+ // 更新页面产品数据
|
|
|
+ const aindex = this.list.findIndex(key => key.id == e.index)
|
|
|
+ this.list[aindex].qty = e.value
|
|
|
+ this.list.splice()
|
|
|
}else{
|
|
|
// 数量为0时,删除
|
|
|
this.chooseClick(e.index,0)
|
|
@@ -262,7 +284,10 @@
|
|
|
if(btns == 0) {
|
|
|
// 更新列表已选状态
|
|
|
const row = this.list.find(item => item.id == index)
|
|
|
- if(row){row.checked = false}
|
|
|
+ if(row){
|
|
|
+ row.checked = false
|
|
|
+ row.qty = 0
|
|
|
+ }
|
|
|
const rindex = this.chooseProductList.findIndex(item => item.id == index)
|
|
|
this.chooseProductList.splice(rindex, 1);
|
|
|
this.chooseList.splice(rindex, 1);
|
|
@@ -335,8 +360,13 @@
|
|
|
queryPromoProductByPage(params).then(res => {
|
|
|
if (res.code == 200 || res.status == 204 || res.status == 200) {
|
|
|
const list = res.data.list||[]
|
|
|
+ // 更新已选状态
|
|
|
list.map(k => {
|
|
|
- k.checked = false
|
|
|
+ const hasChecked = this.chooseList.find(s=>s.id == k.id)
|
|
|
+ k.checked = hasChecked
|
|
|
+ if(hasChecked){
|
|
|
+ k.qty = hasChecked.qty
|
|
|
+ }
|
|
|
})
|
|
|
_this.list = _this.list.concat(list)
|
|
|
_this.total = res.data.count || 0
|