|
|
|
@ -80,6 +80,57 @@ Page({ |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 点击了收藏按钮
|
|
|
|
storegeBtnClick: function () { |
|
|
|
var that = this; |
|
|
|
|
|
|
|
// 获取收藏的存货信息
|
|
|
|
var oldCollectionArr = this.data.collectionArray; |
|
|
|
var waitStorageArr = this.data.checkBoxArray; |
|
|
|
var goodsNameArrayAll = this.data.goodsArray; |
|
|
|
|
|
|
|
if (waitStorageArr.length <= 0) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择存货', |
|
|
|
}) |
|
|
|
return; |
|
|
|
} else { |
|
|
|
|
|
|
|
// 对比所选存货是否已经存在于收藏中 有:不重复添加 返回未添加过的数组
|
|
|
|
for (var i = 0; i < waitStorageArr.length; i++) { |
|
|
|
for (var j = 0; j < oldCollectionArr.length; j++) { |
|
|
|
if (Number(waitStorageArr[i]) == Number(oldCollectionArr[j].SaleGoods_ID)) { |
|
|
|
waitStorageArr.splice(i, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 对比原有数组和选中的数组 存在,将数组包含的其他值也取出加载
|
|
|
|
let choseCheck = []; |
|
|
|
for (var i = 0; i < that.data.goodsArray.length; i++) { |
|
|
|
for (var j = 0; j < waitStorageArr.length; j++) { |
|
|
|
if (Number(goodsNameArrayAll[i].SaleGoods_ID) == waitStorageArr[j]) { |
|
|
|
choseCheck.push(goodsNameArrayAll[i]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
oldCollectionArr = oldCollectionArr.concat(choseCheck); |
|
|
|
that.setData({ |
|
|
|
collectionArray: oldCollectionArr, |
|
|
|
currentTab: 1, |
|
|
|
}); |
|
|
|
wx.setStorage({ |
|
|
|
key: "storageGoodsKey", |
|
|
|
data: oldCollectionArr, |
|
|
|
success: function () { |
|
|
|
wx.showToast({ |
|
|
|
title: '收藏成功', |
|
|
|
}); |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 滑动切换tab |
|
|
|
*/ |
|
|
|
|