@@ -360,7 +363,7 @@ const addSku = () => {
skuCode: '',
skuName: '',
price: 0,
- stock: 0,
+ stock: 0.0,
barcode: '',
weightG: 0,
status: '0'
@@ -492,6 +495,20 @@ const onSubmit = async () => {
submitData.skuList = [];
}
+ // 价格转换:元转分
+ if (submitData.spuPrice) {
+ submitData.spuPrice = Math.round(submitData.spuPrice * 100);
+ }
+ if (submitData.originalPrice) {
+ submitData.originalPrice = Math.round(submitData.originalPrice * 100);
+ }
+ if (submitData.skuList && submitData.skuList.length > 0) {
+ submitData.skuList = submitData.skuList.map((sku: any) => ({
+ ...sku,
+ price: sku.price ? Math.round(sku.price * 100) : 0
+ }));
+ }
+
form.id ? await putObj(submitData) : await addObj(submitData);
useMessage().success(form.id ? '修改成功' : '添加成功');
visible.value = false;
@@ -516,9 +533,23 @@ const getmallProductData = async (id: string) => {
await loadCategoryTree(form.merchantId);
}
+ // 价格转换:分转元
+ if (form.spuPrice) {
+ form.spuPrice = form.spuPrice / 100;
+ }
+ if (form.originalPrice) {
+ form.originalPrice = form.originalPrice / 100;
+ }
+ if (form.skuList && form.skuList.length > 0) {
+ form.skuList = form.skuList.map((sku: any) => ({
+ ...sku,
+ price: sku.price ? sku.price / 100 : 0
+ }));
+ }
+
// 处理分类ID回显为数组
if (res.data.categoryId && categoryOptions.value.length) {
- form.categoryId = findCategoryPath(categoryOptions.value, res.data.categoryId);
+ form.categoryId = findCategoryPath(categoryOptions.value, res.data.categoryId) as any;
}
// 如果没有SKU数据,根据定价方式初始化
@@ -749,6 +780,13 @@ defineExpose({
z-index: 2000;
}
+// 价格提示样式
+.price-tip {
+ font-size: 12px;
+ color: #909399;
+ margin-left: 8px;
+}
+
:deep(.el-dialog__body) {
background: #fff;
position: relative;
diff --git a/src/views/supermarket/mallProduct/index.vue b/src/views/supermarket/mallProduct/index.vue
index 861f4d1..6d2c404 100644
--- a/src/views/supermarket/mallProduct/index.vue
+++ b/src/views/supermarket/mallProduct/index.vue
@@ -74,8 +74,8 @@
暂无SKU
-
¥{{ scope.row.spuPrice || 0 }}
-
¥{{ scope.row.originalPrice }}
+
¥{{ ((scope.row.spuPrice || 0) / 100).toFixed(2) }}
+
¥{{ ((scope.row.originalPrice || 0) / 100).toFixed(2) }}
@@ -238,13 +238,13 @@ const {
// 获取SKU最低价格
const getMinPrice = (skuList: any[]) => {
if (!skuList || skuList.length === 0) return 0;
- return Math.min(...skuList.map(sku => sku.price || 0));
+ return (Math.min(...skuList.map(sku => (sku.price || 0) / 100))).toFixed(2);
};
// 获取SKU最高价格
const getMaxPrice = (skuList: any[]) => {
if (!skuList || skuList.length === 0) return 0;
- return Math.max(...skuList.map(sku => sku.price || 0));
+ return (Math.max(...skuList.map(sku => (sku.price || 0) / 100))).toFixed(2);
};
// 获取SKU总库存