From 2bae9aaa13d1f5b99ece5b5b76241a63e9dbe1cf Mon Sep 17 00:00:00 2001 From: weiwei Date: Fri, 30 May 2025 14:46:58 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=BC=80=E9=97=A8=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/cabinet/buy.vue | 18 +++++++++--------- src/pages/tabbar/my.vue | 3 ++- src/static/page/开门-black.svg | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 src/static/page/开门-black.svg diff --git a/src/pages/cabinet/buy.vue b/src/pages/cabinet/buy.vue index c335748..1255d30 100644 --- a/src/pages/cabinet/buy.vue +++ b/src/pages/cabinet/buy.vue @@ -1,18 +1,20 @@ @@ -77,38 +68,37 @@ import { shopApi } from "@/sheep/api" import { filePath } from "@/sheep/utils/file" import { computed, reactive, watch } from "vue" +import { hooks } from "@@/index" -const emit = defineEmits(["update:modelValue", "onAddToCar"]) +const emit = defineEmits(["update:modelValue", "onSkuAddToCart"]) + +const props = withDefaults( + defineProps<{ + modelValue: boolean + productData: any + }>(), + { + modelValue: false, + productData: {}, + }, +) -export type Props = { - modelValue: boolean - productData: any - onAddToCar?: () => void -} -const props = withDefaults(defineProps(), { - modelValue: false, - productData: {}, -}) const state = reactive({ goodsCount: 1, - selectedSku: {}, + selectedSku: { + retailPrice: 0, + promotionPrice: 0, + packageNum: 0, + }, goodsDetail: {}, }) -// 售价 -const retailPrice = computed(() => - state.selectedSku.retailPrice ? Number(state.selectedSku.retailPrice) * Number(state.goodsCount) : 0, -) -// 优惠价 -const promotionPrice = computed(() => - state.selectedSku.promotionPrice ? Number(state.selectedSku.promotionPrice) * Number(state.goodsCount) : 0, -) watch( () => props.modelValue, async (newValue) => { if (newValue) { // 获取商品详情 - const { data } = await shopApi.getSupermarketSpuDetail({ id: props.productData.productId }) + const { data } = await shopApi.getSupermarketSpuDetail({ id: props.productData.id }) state.goodsDetail = data if (data.skuList.length > 0) { state.selectedSku = state.goodsDetail.skuList[0] @@ -117,122 +107,37 @@ watch( }, ) -// SKU 列表 -// const skuList = computed(() => { -// let skuPrices = props.goodsInfo.skus; -// for (let price of skuPrices) { -// price.value_id_array = price.properties.map((item) => item.valueId); -// } -// return skuPrices; -// }); - -// 当前所选属性下,获取所有有库存的 SKU 们 -// function getCanUseSkuList() { -// let newSkus = []; -// for (let sku of skuList.value) { -// if (sku.stock <= 0) { -// continue; -// } -// let isOk = true; -// state.currentPropertyArray.forEach((propertyId) => { -// // propertyId 不为空,并且,这个 条 sku 没有被选中,则排除 -// if (propertyId.toString() !== "" && sku.value_id_array.indexOf(propertyId) < 0) { -// isOk = false; -// } -// }); -// if (isOk) { -// newSkus.push(sku); -// } -// } -// return newSkus; -// } - -// 选择规格 -function onSelectSku(skuItem: any) { - // const index = state.currentPropertyArray.findIndex((item: any) => item.id === skuItem.id); - // if (index === -1) { +// 选择规格/取消选择规格 +const onSelectSku = (skuItem: any) => { if (state.selectedSku.id === skuItem.id) { state.selectedSku = {} - } else { - state.selectedSku = skuItem + return } - // } else { - // state.currentPropertyArray.splice(index, 1); - // } - - // 清空已选择 - // let isChecked = true; // 选中 or 取消选中 - // if (state.currentPropertyArray[propertyId] !== undefined && state.currentPropertyArray[propertyId] === valueId) { - // 点击已被选中的,删除并填充 '' - // isChecked = false; - // state.currentPropertyArray.splice(propertyId, 1, ""); - // } else { - // 选中 - // state.currentPropertyArray[propertyId] = valueId; - // } - // 选中的 property 大类 - // let choosePropertyId: any = []; - // state.currentPropertyArray.forEach((currentPropertyId: string) => { - // if (currentPropertyId !== "") { - // // currentPropertyId 为空是反选 填充的 - // choosePropertyId.push(currentPropertyId); - // } - // }); - // 当前所选 property 下,所有可以选择的 SKU 们 - // let newSkuList = getCanUseSkuList(); - // 判断所有 property 大类是否选择完成 - // if (choosePropertyId.length === skuData.length && newSkuList.length) { - // newSkuList[0].name = state.selectedSku.goods_num || 1; - // state.selectedSku = newSkuList[0]; - // } else { - // state.selectedSku = {}; - // } - // if (choosePropertyId.length === skuData.value.length) { - // state.selectedSku = state.currentPropertyArray; - // } - // 改变 property 禁用状态 - // changeDisabled(isChecked, propertyId, valueId); + state.selectedSku = skuItem } // 加数量 const handleNumAdd = () => { - if (state.goodsCount >= state.goodsDetail.stock) { - return - } + if (state.goodsCount >= state.goodsDetail.stock) return uni.showToast({ title: "库存不足", icon: "none" }) state.goodsCount += 1 } // 减数量 const handleNumRemove = () => { - if (state.goodsCount <= 1) { - return - } + if (state.goodsCount <= 1) return state.goodsCount -= 1 } -// 点击加入购物车 -const handleClickAddToCar = async () => { - // 检查规格选择 - if (!state.selectedSku.id) { - uni.showToast({ - title: "请选择规格", - icon: "none", - duration: 1000, - }) - return - } +// 点击sku加入到购物车 +const handleSkuAddToCar = async () => { + // 检查包装单位选择 + if (!state.selectedSku.id) return uni.showToast({ title: "请选择包装单位", icon: "none" }) + // 检查库存 try { uni.showLoading({ title: "加载中", mask: true }) - const { code }: any = await shopApi.checkSpuStock({ - spuId: state.goodsDetail.id, - incrCount: state.goodsCount, - }) + const { code }: any = await shopApi.checkSpuStock({ spuId: state.goodsDetail.id, incrCount: state.goodsCount }) if (code != 0) { - return uni.showToast({ - title: "库存不足", - icon: "none", - duration: 1000, - }) + return uni.showToast({ title: "库存不足", icon: "none" }) } } catch (e) { console.error(e) @@ -240,22 +145,20 @@ const handleClickAddToCar = async () => { uni.hideLoading() } // 检查库存 - if (state.goodsDetail.stock === 0) { - uni.showToast({ - title: "库存不足", - icon: "none", - duration: 1000, - }) - return - } - emit("onAddToCar", { ...state.goodsDetail, productCount: state.goodsCount, productId: state.selectedSku.id }) + if (state.goodsDetail.stock === 0) return uni.showToast({ title: "库存不足", icon: "none" }) + + emit("onSkuAddToCart", { ...state.goodsDetail, productCount: state.goodsCount, productId: state.selectedSku.id }) } const doClose = () => { emit("update:modelValue", false) state.goodsCount = 1 - state.selectedSku = {} + state.selectedSku = { + retailPrice: 0, + promotionPrice: 0, + packageNum: 0, + } state.goodsDetail = {} } diff --git a/src/pages/shop/components/select-sku.vue b/src/pages/shop/components/select-sku.vue deleted file mode 100644 index 3eeb8c3..0000000 --- a/src/pages/shop/components/select-sku.vue +++ /dev/null @@ -1,447 +0,0 @@ - - - - - diff --git a/src/pages/shop/detail.vue b/src/pages/shop/detail.vue index 222a29b..c2e677b 100644 --- a/src/pages/shop/detail.vue +++ b/src/pages/shop/detail.vue @@ -71,7 +71,7 @@ - - {{ v.name }} - + {{ v.name }} - - - - + + @@ -118,7 +117,7 @@ - +