diff --git a/src/pages/shop/components/product-cart.vue b/src/pages/shop/components/product-cart.vue
index 8873087..998380c 100644
--- a/src/pages/shop/components/product-cart.vue
+++ b/src/pages/shop/components/product-cart.vue
@@ -1,24 +1,33 @@
-
+
emit('add', v)"
@remove="(v) => emit('remove', v)"
/>
-
+
@@ -30,28 +39,26 @@ import { filePath } from "@/sheep/utils/file"
import ProductRow from "./product-row.vue"
import ProductTotal from "./product-total.vue"
-const emit = defineEmits(["update:modelValue", "submit", "add", "remove"])
+const emit = defineEmits(["update:modelValue", "add", "remove", "submit"])
-export type Props = {
- modelValue: any
- carList: any
- totPrice: number
- totCount: number
-}
-const props = withDefaults(defineProps(), {
- modelValue: false,
- carList: [],
- totPrice: 0,
- totCount: 0,
-})
+const props = withDefaults(
+ defineProps<{
+ modelValue: any
+ cartList: any
+ totPrice: number
+ totCount: number
+ }>(),
+ {
+ modelValue: false,
+ cartList: [],
+ totPrice: 0,
+ totCount: 0,
+ },
+)
-const doClose = () => {
- emit("update:modelValue", false)
-}
+const doClose = () => emit("update:modelValue", false)
-const doPay = () => {
- emit("submit")
-}
+const doPay = () => emit("submit")
const getHeight = () => {
const { bottom } = uni.getSystemInfoSync().safeAreaInsets!
diff --git a/src/pages/shop/components/product-row.vue b/src/pages/shop/components/product-row.vue
index e4776ae..4b0b92f 100644
--- a/src/pages/shop/components/product-row.vue
+++ b/src/pages/shop/components/product-row.vue
@@ -1,41 +1,45 @@
-
+
{{ props.productName }}
- 规格:{{ "" + props.spec + props.unit }}
-
-
-
-
-
- ¥{{ (Number(productPrice) / 100).toFixed(2) }}
- x{{ productCount }}
+
+ ¥{{ hooks.useMoney(props.promotionPrice) }}
+ ¥{{ hooks.useMoney(props.retailPrice) }}
+ 单位:{{ props.unit }}
{{ hooks.useFormatNum("库存", "", props.stock) }}
-
+
{{ hooks.useFormatNum("销量", "", props.salesCount) }}
+
+
+ ¥{{ hooks.useMoney(productPrice) }}
+ x {{ productCount }}
+
+
加入购物车
-
-
-
-
- {{ productCount }}
-
-
+
+ ¥{{ hooks.useMoney(totalPrice) }}
+
+
+
+
+ {{ productCount }}
+
+
+
@@ -48,46 +52,50 @@ import { hooks, router } from "@@/index"
const emit = defineEmits(["onClickAddToCart", "add", "remove"])
export type Props = {
- mode?: "default" | "car"
+ mode?: "default" | "cart"
productId: string
- spuId?: string
- merchantId: string
+ merchantId?: string
picUrl: string
productName: string
- productCount?: number
- productPrice?: number
salesCount?: number
stock?: number
- spec?: string
unit?: string
- onClickAddToCart?: () => void
+ spec?: string
+ retailPrice?: number
+ promotionPrice?: number
+
+ productCount?: number
+ productPrice?: number
+ spuId?: string
+ totalPrice?: string | number
}
const props = withDefaults(defineProps(), {
mode: "default",
productId: "",
- spuId: "",
merchantId: "",
picUrl: "",
productName: "",
- productCount: 0,
- productPrice: 0,
salesCount: 0,
stock: 0,
- spec: "",
unit: "",
+ spec: "",
+ retailPrice: 0,
+ promotionPrice: 0,
+
+ productCount: 0,
+ productPrice: 0,
+ spuId: "",
+ totalPrice: 0,
})
-const handleClickAddToCar = () => {
- if (props.productId) {
- emit("onClickAddToCart", { ...props })
- }
+const handleClickAddToCart = () => {
+ if (props.productId) emit("onClickAddToCart", { ...props })
}
const add = () => {
if (props.productCount + 1 >= 99) {
return
}
- // emit("add", { productId: props.productId, productCount: props.productCount + 1 })
emit("add", { productId: props.productId, productCount: props.productCount, spuId: props.spuId })
}
@@ -95,13 +103,6 @@ const remove = () => {
if (props.productCount - 1 < 0) {
return
}
- // emit("remove", { productId: props.productId, productCount: props.productCount - 1 })
emit("remove", { productId: props.productId, productCount: props.productCount, spuId: props.spuId })
}
-
-
diff --git a/src/pages/shop/components/product-sku.vue b/src/pages/shop/components/product-sku.vue
index 2b88015..d2daab7 100644
--- a/src/pages/shop/components/product-sku.vue
+++ b/src/pages/shop/components/product-sku.vue
@@ -5,70 +5,61 @@
showFooter
title="加入购物车"
position="bottom"
- size="60%"
+ size="70%"
+ bgColor="#ECF4F9"
+ :duration="100"
@close="doClose"
>
-
-
-
-
-
-
-
- {{ state.goodsDetail.productName }}
-
-
-
- 售价¥{{ retailPrice }}
- 促销价¥{{ promotionPrice }}
-
-
- 库存{{ state.goodsDetail.stock }}
- 已售{{ state.goodsDetail.salesCount }}
-
+
+
+
+ 商品信息
+
+
+
+ {{ state.goodsDetail.productName }}
+
+ 促销 ¥{{ state.selectedSku.promotionPrice }}
+ 原价 ¥{{ state.selectedSku.retailPrice }}
+ 内装数量:{{ state.selectedSku.packageNum }}
+
-
-
- 规格
+
+
+ 包装单位
-
-
-
-
-
- 购买数量
-
-
-
-
-
- {{ String(state.goodsCount).padStart(2, "0") }}
-
-
-
+ {{ v.spec + " " + v.unit }}
-
-
+
+
+
+
+ 购买数量
+
+
+
+
+ {{ String(state.goodsCount).padStart(2, "0") }}
+
+
+
+
+
+
-
+
@@ -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 @@
-
-
-
-
-
-
-
-
-
-
-
- {{ property.name }}
-
-
-
-
-
- 购买数量
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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 @@
-
-
-
-
+
+
@@ -118,7 +117,7 @@
-
+