fix: 修复更新数据可能有skudata不存在报错

This commit is contained in:
YeMingfei666 2025-03-15 10:43:49 +08:00
parent 72fddad3eb
commit a1b5a468a9
1 changed files with 8 additions and 11 deletions

View File

@ -341,7 +341,8 @@ export const useCartsStore = defineStore("carts", () => {
sendMessage('edit', { ...data, pack_number }); sendMessage('edit', { ...data, pack_number });
} }
function updateTag(key: string, val: any, cart: CartsState = selCart.value) { function updateTag(key: string, val: any, cart: CartsState = selCart.value) {
if (cart.number * 1 < cart.skuData.suitNum * 1) { const skuData = cart.skuData || { suitNum: 1 }
if (cart.number * 1 < skuData.suitNum * 1) {
return sendMessage('del', cart); return sendMessage('del', cart);
} }
console.log(key, val) console.log(key, val)
@ -578,32 +579,28 @@ export const useCartsStore = defineStore("carts", () => {
const giftIndex = giftList.value.findIndex((item) => item.id === newCart.id) const giftIndex = giftList.value.findIndex((item) => item.id === newCart.id)
const cartItem = list.value[index] || { is_gift: false }; const cartItem = list.value[index] || { is_gift: false };
const giftItem = giftList.value[giftIndex]; const giftItem = giftList.value[giftIndex];
if (isSelGift.value) {
if (giftItem) {
//操作赠菜 //操作赠菜
if (newCart.is_gift != giftItem.is_gift) { if (!newCart.is_gift) {
//修改了赠菜状态
giftList.value.splice(giftIndex, 1) giftList.value.splice(giftIndex, 1)
list.value.push({ ...giftItem, ...newCart }) list.value.push({ ...giftItem, ...newCart })
selListIndex.value = -1 selListIndex.value = -1
} else { } else {
giftList.value[giftIndex] = { ...giftItem, ...newCart } giftList.value[giftIndex] = { ...giftItem, ...newCart }
} }
ElMessage.success(msg.message || '修改成功')
return
} }
if (!isSelGift.value) { if (cartItem) {
//操作非赠菜 //操作非赠菜
if (newCart.is_gift != cartItem.is_gift) { if (newCart.is_gift) {
list.value.splice(index, 1) list.value.splice(index, 1)
giftList.value.push({ ...cartItem, ...newCart }) giftList.value.push({ ...cartItem, ...newCart })
selListIndex.value = -1 selListIndex.value = -1
} else { } else {
list.value[index] = { ...cartItem, ...newCart } list.value[index] = { ...cartItem, ...newCart }
} }
ElMessage.success(msg.message || '修改成功')
return
} }
ElMessage.success(msg.message || '修改成功')
} }
if (msg.operate_type === "manage_del") { if (msg.operate_type === "manage_del") {
const cartId = Array.isArray(msg.data) ? msg.data[0].id : msg.data.id const cartId = Array.isArray(msg.data) ? msg.data[0].id : msg.data.id