mirror of
https://gitee.com/yudaocode/yudao-ui-admin-vben.git
synced 2025-12-30 10:32:25 +00:00
feat:【antd】【mall】bargain 优化完善
This commit is contained in:
@@ -99,16 +99,14 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
},
|
},
|
||||||
async onOpenChange(isOpen: boolean) {
|
async onOpenChange(isOpen: boolean) {
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
|
// 关闭时重置表单状态
|
||||||
selectedSku.value = undefined;
|
selectedSku.value = undefined;
|
||||||
|
await formApi.setValues({ spuId: undefined, skuId: undefined });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加载数据
|
// 加载数据
|
||||||
const data = modalApi.getData<MallCommentApi.Comment>();
|
const data = modalApi.getData<MallCommentApi.Comment>();
|
||||||
if (!data || !data.id) {
|
if (!data || !data.id) {
|
||||||
// 新建模式:重置表单
|
|
||||||
// TODO @puhui999:这里的重置,可以统一到 103 行那么?
|
|
||||||
selectedSku.value = undefined;
|
|
||||||
await formApi.setValues({ spuId: undefined, skuId: undefined });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 编辑模式:加载数据
|
// 编辑模式:加载数据
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { MallSpuApi } from '#/api/mall/product/spu';
|
|||||||
|
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { CloseCircleFilled, PlusOutlined } from '@vben/icons';
|
import { IconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { Image, Tooltip } from 'ant-design-vue';
|
import { Image, Tooltip } from 'ant-design-vue';
|
||||||
|
|
||||||
@@ -110,9 +110,9 @@ function emitSpuChange() {
|
|||||||
class="h-full w-full rounded-lg object-cover"
|
class="h-full w-full rounded-lg object-cover"
|
||||||
/>
|
/>
|
||||||
<!-- 删除按钮 -->
|
<!-- 删除按钮 -->
|
||||||
<!-- TODO @puhui999:还是使用 IconifyIcon:使用自己的中立的图标,方便 antd 和 ele 共享 -->
|
<IconifyIcon
|
||||||
<CloseCircleFilled
|
|
||||||
v-if="!disabled"
|
v-if="!disabled"
|
||||||
|
icon="lucide:circle-x"
|
||||||
class="absolute -right-2 -top-2 cursor-pointer text-xl text-red-500 opacity-0 transition-opacity hover:text-red-600 group-hover:opacity-100"
|
class="absolute -right-2 -top-2 cursor-pointer text-xl text-red-500 opacity-0 transition-opacity hover:text-red-600 group-hover:opacity-100"
|
||||||
@click="handleRemoveSpu(index)"
|
@click="handleRemoveSpu(index)"
|
||||||
/>
|
/>
|
||||||
@@ -126,8 +126,7 @@ function emitSpuChange() {
|
|||||||
class="flex h-[60px] w-[60px] cursor-pointer items-center justify-center rounded-lg border-2 border-dashed transition-colors hover:border-primary hover:bg-primary/5"
|
class="flex h-[60px] w-[60px] cursor-pointer items-center justify-center rounded-lg border-2 border-dashed transition-colors hover:border-primary hover:bg-primary/5"
|
||||||
@click="handleOpenSpuSelect"
|
@click="handleOpenSpuSelect"
|
||||||
>
|
>
|
||||||
<!-- TODO @puhui999:还是使用 IconifyIcon:使用自己的中立的图标,方便 antd 和 ele 共享 -->
|
<IconifyIcon icon="lucide:plus" class="text-xl text-gray-400" />
|
||||||
<PlusOutlined class="text-xl text-gray-400" />
|
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -32,30 +32,6 @@ const spuId = ref<number>();
|
|||||||
const { params, name } = useRoute();
|
const { params, name } = useRoute();
|
||||||
const { closeCurrentTab } = useTabs();
|
const { closeCurrentTab } = useTabs();
|
||||||
const activeTabName = ref('info');
|
const activeTabName = ref('info');
|
||||||
// TODO @puhui999:这个要不要类似 ele 里,直接写到 html 里?
|
|
||||||
const tabList = ref([
|
|
||||||
{
|
|
||||||
key: 'info',
|
|
||||||
tab: '基础设置',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'sku',
|
|
||||||
tab: '价格库存',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'delivery',
|
|
||||||
tab: '物流设置',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'description',
|
|
||||||
tab: '商品详情',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'other',
|
|
||||||
tab: '其它设置',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const formLoading = ref(false); // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formLoading = ref(false); // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
const isDetail = ref(name === 'ProductSpuDetail'); // 是否查看详情
|
const isDetail = ref(name === 'ProductSpuDetail'); // 是否查看详情
|
||||||
const skuListRef = ref(); // 商品属性列表 Ref
|
const skuListRef = ref(); // 商品属性列表 Ref
|
||||||
@@ -95,22 +71,22 @@ const propertyList = ref<PropertyAndValues[]>([]); // 商品属性列表
|
|||||||
const ruleConfig: RuleConfig[] = [
|
const ruleConfig: RuleConfig[] = [
|
||||||
{
|
{
|
||||||
name: 'stock',
|
name: 'stock',
|
||||||
rule: (arg) => arg >= 0,
|
rule: (arg: number) => arg >= 0,
|
||||||
message: '商品库存必须大于等于 1 !!!',
|
message: '商品库存必须大于等于 1 !!!',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'price',
|
name: 'price',
|
||||||
rule: (arg) => arg >= 0.01,
|
rule: (arg: number) => arg >= 0.01,
|
||||||
message: '商品销售价格必须大于等于 0.01 元!!!',
|
message: '商品销售价格必须大于等于 0.01 元!!!',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'marketPrice',
|
name: 'marketPrice',
|
||||||
rule: (arg) => arg >= 0.01,
|
rule: (arg: number) => arg >= 0.01,
|
||||||
message: '商品市场价格必须大于等于 0.01 元!!!',
|
message: '商品市场价格必须大于等于 0.01 元!!!',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'costPrice',
|
name: 'costPrice',
|
||||||
rule: (arg) => arg >= 0.01,
|
rule: (arg: number) => arg >= 0.01,
|
||||||
message: '商品成本价格必须大于等于 0.00 元!!!',
|
message: '商品成本价格必须大于等于 0.00 元!!!',
|
||||||
},
|
},
|
||||||
]; // sku 相关属性校验规则
|
]; // sku 相关属性校验规则
|
||||||
@@ -222,7 +198,7 @@ async function handleSubmit() {
|
|||||||
item.secondBrokeragePrice = convertToInteger(item.secondBrokeragePrice);
|
item.secondBrokeragePrice = convertToInteger(item.secondBrokeragePrice);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 处理轮播图列表 TODO @puhui999:这个是必须的哇?
|
// 处理轮播图列表:上传组件可能返回对象或字符串,统一处理成字符串数组
|
||||||
const newSliderPicUrls: any[] = [];
|
const newSliderPicUrls: any[] = [];
|
||||||
values.sliderPicUrls!.forEach((item: any) => {
|
values.sliderPicUrls!.forEach((item: any) => {
|
||||||
// 如果是前端选的图
|
// 如果是前端选的图
|
||||||
@@ -344,7 +320,28 @@ onMounted(async () => {
|
|||||||
<Card
|
<Card
|
||||||
class="h-full w-full"
|
class="h-full w-full"
|
||||||
:loading="formLoading"
|
:loading="formLoading"
|
||||||
:tab-list="tabList"
|
:tab-list="[
|
||||||
|
{
|
||||||
|
key: 'info',
|
||||||
|
tab: '基础设置',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'sku',
|
||||||
|
tab: '价格库存',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'delivery',
|
||||||
|
tab: '物流设置',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'description',
|
||||||
|
tab: '商品详情',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'other',
|
||||||
|
tab: '其它设置',
|
||||||
|
},
|
||||||
|
]"
|
||||||
:active-key="activeTabName"
|
:active-key="activeTabName"
|
||||||
@tab-change="handleTabChange"
|
@tab-change="handleTabChange"
|
||||||
>
|
>
|
||||||
@@ -410,7 +407,6 @@ onMounted(async () => {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
// TODO @puhui999:这个样式是必须的哇?
|
|
||||||
:deep(.ant-tabs-tab-btn) {
|
:deep(.ant-tabs-tab-btn) {
|
||||||
font-size: 14px !important;
|
font-size: 14px !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
componentProps: {
|
componentProps: {
|
||||||
format: 'YYYY-MM-DD HH:mm:ss',
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
showTime: true,
|
||||||
placeholder: '请选择开始时间',
|
placeholder: '请选择开始时间',
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
@@ -44,51 +45,18 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
componentProps: {
|
componentProps: {
|
||||||
format: 'YYYY-MM-DD HH:mm:ss',
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
showTime: true,
|
||||||
placeholder: '请选择结束时间',
|
placeholder: '请选择结束时间',
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
fieldName: 'bargainFirstPrice',
|
|
||||||
label: '砍价起始价格(元)',
|
|
||||||
component: 'InputNumber',
|
|
||||||
componentProps: {
|
|
||||||
min: 0,
|
|
||||||
precision: 2,
|
|
||||||
step: 0.01,
|
|
||||||
placeholder: '请输入砍价起始价格',
|
|
||||||
},
|
|
||||||
rules: 'required',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldName: 'bargainMinPrice',
|
|
||||||
label: '砍价底价(元)',
|
|
||||||
component: 'InputNumber',
|
|
||||||
componentProps: {
|
|
||||||
min: 0,
|
|
||||||
precision: 2,
|
|
||||||
step: 0.01,
|
|
||||||
placeholder: '请输入砍价底价',
|
|
||||||
},
|
|
||||||
rules: 'required',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldName: 'stock',
|
|
||||||
label: '活动库存',
|
|
||||||
component: 'InputNumber',
|
|
||||||
componentProps: {
|
|
||||||
min: 1,
|
|
||||||
placeholder: '请输入活动库存',
|
|
||||||
},
|
|
||||||
rules: 'required',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
fieldName: 'helpMaxCount',
|
fieldName: 'helpMaxCount',
|
||||||
label: '助力人数',
|
label: '助力人数',
|
||||||
component: 'InputNumber',
|
component: 'InputNumber',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
min: 1,
|
min: 1,
|
||||||
placeholder: '请输入助力人数',
|
placeholder: '达到该人数才能砍到低价',
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
@@ -98,7 +66,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
component: 'InputNumber',
|
component: 'InputNumber',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
min: 1,
|
min: 1,
|
||||||
placeholder: '请输入砍价次数',
|
placeholder: '最大帮砍次数',
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
@@ -108,7 +76,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
component: 'InputNumber',
|
component: 'InputNumber',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
min: 1,
|
min: 1,
|
||||||
placeholder: '请输入购买限制',
|
placeholder: '最大购买次数',
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
@@ -120,7 +88,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
min: 0,
|
min: 0,
|
||||||
precision: 2,
|
precision: 2,
|
||||||
step: 0.01,
|
step: 0.01,
|
||||||
placeholder: '请输入最小砍价金额',
|
placeholder: '用户每次砍价的最小金额',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -131,9 +99,16 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
min: 0,
|
min: 0,
|
||||||
precision: 2,
|
precision: 2,
|
||||||
step: 0.01,
|
step: 0.01,
|
||||||
placeholder: '请输入最大砍价金额',
|
placeholder: '用户每次砍价的最大金额',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'spuId',
|
||||||
|
label: '砍价商品',
|
||||||
|
component: 'Input',
|
||||||
|
rules: 'required',
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { MallSpuApi } from '#/api/mall/product/spu';
|
||||||
import type { MallBargainActivityApi } from '#/api/mall/promotion/bargain/bargainActivity';
|
import type { MallBargainActivityApi } from '#/api/mall/promotion/bargain/bargainActivity';
|
||||||
|
import type {
|
||||||
|
RuleConfig,
|
||||||
|
SpuProperty,
|
||||||
|
} from '#/views/mall/product/spu/components';
|
||||||
|
|
||||||
import { computed, nextTick, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { cloneDeep, convertToInteger, formatToFraction } from '@vben/utils';
|
||||||
|
|
||||||
import { Button, message } from 'ant-design-vue';
|
import { Button, InputNumber, message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { useVbenForm } from '#/adapter/form';
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import { VxeColumn } from '#/adapter/vxe-table';
|
||||||
import { getSpu } from '#/api/mall/product/spu';
|
import { getSpu } from '#/api/mall/product/spu';
|
||||||
import {
|
import {
|
||||||
createBargainActivity,
|
createBargainActivity,
|
||||||
@@ -15,7 +22,11 @@ import {
|
|||||||
updateBargainActivity,
|
updateBargainActivity,
|
||||||
} from '#/api/mall/promotion/bargain/bargainActivity';
|
} from '#/api/mall/promotion/bargain/bargainActivity';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { SpuSkuSelect } from '#/views/mall/product/spu/components';
|
import {
|
||||||
|
getPropertyList,
|
||||||
|
SpuAndSkuList,
|
||||||
|
SpuSkuSelect,
|
||||||
|
} from '#/views/mall/product/spu/components';
|
||||||
|
|
||||||
import { useFormSchema } from '../data';
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
@@ -30,47 +41,6 @@ const getTitle = computed(() => {
|
|||||||
: $t('ui.actionTitle.create', ['砍价活动']);
|
: $t('ui.actionTitle.create', ['砍价活动']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ================= 商品选择相关 =================
|
|
||||||
const spuId = ref<number>();
|
|
||||||
const skuId = ref<number>();
|
|
||||||
const spuName = ref<string>('');
|
|
||||||
const skuInfo = ref<{
|
|
||||||
picUrl: string;
|
|
||||||
price: number;
|
|
||||||
skuName: string;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const spuSkuSelectRef = ref(); // 商品选择弹窗 Ref
|
|
||||||
|
|
||||||
/** 打开商品选择弹窗 */
|
|
||||||
const handleSelectProduct = () => {
|
|
||||||
spuSkuSelectRef.value?.open();
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 选择商品后的回调 */
|
|
||||||
async function handleSpuSelected(selectedSpuId: number, skuIds?: number[]) {
|
|
||||||
const spu = await getSpu(selectedSpuId);
|
|
||||||
if (!spu) return;
|
|
||||||
|
|
||||||
spuId.value = spu.id;
|
|
||||||
spuName.value = spu.name || '';
|
|
||||||
|
|
||||||
// 砍价活动只选择一个 SKU
|
|
||||||
if (skuIds && skuIds.length > 0) {
|
|
||||||
const selectedSku = spu.skus?.find((sku) => sku.id === skuIds[0]);
|
|
||||||
if (selectedSku) {
|
|
||||||
skuId.value = selectedSku.id;
|
|
||||||
skuInfo.value = {
|
|
||||||
skuName: selectedSku.name || '',
|
|
||||||
picUrl: selectedSku.picUrl || spu.picUrl || '',
|
|
||||||
price: Number(selectedSku.price) || 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================= end =================
|
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
commonConfig: {
|
commonConfig: {
|
||||||
componentProps: {
|
componentProps: {
|
||||||
@@ -78,46 +48,151 @@ const [Form, formApi] = useVbenForm({
|
|||||||
},
|
},
|
||||||
labelWidth: 130,
|
labelWidth: 130,
|
||||||
},
|
},
|
||||||
wrapperClass: 'grid-cols-2',
|
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
schema: useFormSchema(),
|
schema: useFormSchema(),
|
||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ================= 商品选择相关 =================
|
||||||
|
|
||||||
|
const spuSkuSelectRef = ref(); // 商品和属性选择 Ref
|
||||||
|
const spuAndSkuListRef = ref(); // SPU 和 SKU 列表组件 Ref
|
||||||
|
|
||||||
|
const ruleConfig: RuleConfig[] = [
|
||||||
|
{
|
||||||
|
name: 'productConfig.bargainFirstPrice',
|
||||||
|
rule: (arg) => arg > 0,
|
||||||
|
message: '商品砍价起始价格必须大于 0 !!!',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'productConfig.bargainMinPrice',
|
||||||
|
rule: (arg) => arg >= 0,
|
||||||
|
message: '商品砍价底价不能小于 0 !!!',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'productConfig.stock',
|
||||||
|
rule: (arg) => arg >= 1,
|
||||||
|
message: '商品活动库存必须大于等于 1 !!!',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const spuList = ref<MallSpuApi.Spu[]>([]); // 选择的 SPU 列表
|
||||||
|
const spuPropertyList = ref<SpuProperty<MallSpuApi.Spu>[]>([]); // SPU 属性列表
|
||||||
|
|
||||||
|
/** 打开商品选择器 */
|
||||||
|
function openSpuSelect() {
|
||||||
|
spuSkuSelectRef.value?.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 选择商品后的回调 */
|
||||||
|
async function handleSpuSelected(spuId: number, skuIds?: number[]) {
|
||||||
|
await formApi.setFieldValue('spuId', spuId);
|
||||||
|
await getSpuDetails(spuId, skuIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取 SPU 详情 */
|
||||||
|
async function getSpuDetails(
|
||||||
|
spuId: number,
|
||||||
|
skuIds?: number[],
|
||||||
|
products?: MallBargainActivityApi.BargainProduct[],
|
||||||
|
) {
|
||||||
|
const res = await getSpu(spuId);
|
||||||
|
if (!res) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
spuList.value = [];
|
||||||
|
|
||||||
|
// 筛选指定的 SKU(砍价活动只选择一个 SKU)
|
||||||
|
const selectSkus =
|
||||||
|
skuIds === undefined
|
||||||
|
? res.skus
|
||||||
|
: res.skus?.filter((sku) => skuIds.includes(sku.id!));
|
||||||
|
|
||||||
|
// 为每个 SKU 配置砍价活动相关的配置
|
||||||
|
selectSkus?.forEach((sku) => {
|
||||||
|
let config: MallBargainActivityApi.BargainProduct = {
|
||||||
|
spuId: res.id!,
|
||||||
|
skuId: sku.id!,
|
||||||
|
bargainFirstPrice: 1,
|
||||||
|
bargainMinPrice: 1,
|
||||||
|
stock: 1,
|
||||||
|
};
|
||||||
|
// 如果是编辑模式,回填已有配置
|
||||||
|
if (products !== undefined) {
|
||||||
|
const product = products.find((item) => item.skuId === sku.id);
|
||||||
|
if (product) {
|
||||||
|
// 分转元
|
||||||
|
product.bargainFirstPrice = formatToFraction(
|
||||||
|
product.bargainFirstPrice,
|
||||||
|
) as unknown as number;
|
||||||
|
product.bargainMinPrice = formatToFraction(
|
||||||
|
product.bargainMinPrice,
|
||||||
|
) as unknown as number;
|
||||||
|
}
|
||||||
|
config = product || config;
|
||||||
|
}
|
||||||
|
// 动态添加 productConfig 属性到 SKU
|
||||||
|
(
|
||||||
|
sku as MallSpuApi.Sku & {
|
||||||
|
productConfig: MallBargainActivityApi.BargainProduct;
|
||||||
|
}
|
||||||
|
).productConfig = config;
|
||||||
|
});
|
||||||
|
res.skus = selectSkus;
|
||||||
|
|
||||||
|
const spuProperties: SpuProperty<MallSpuApi.Spu>[] = [
|
||||||
|
{
|
||||||
|
spuId: res.id!,
|
||||||
|
spuDetail: res,
|
||||||
|
propertyList: getPropertyList(res),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 直接赋值,因为砍价活动只选择一个 SPU
|
||||||
|
spuList.value = [res];
|
||||||
|
spuPropertyList.value = spuProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================= end =================
|
||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
async onConfirm() {
|
async onConfirm() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
modalApi.lock();
|
||||||
// 验证商品和 SKU 选择
|
try {
|
||||||
if (!spuId.value) {
|
// 获取砍价商品配置(深拷贝避免直接修改原对象)
|
||||||
|
const products: MallBargainActivityApi.BargainProduct[] = cloneDeep(
|
||||||
|
spuAndSkuListRef.value?.getSkuConfigs('productConfig') || [],
|
||||||
|
);
|
||||||
|
if (products.length === 0) {
|
||||||
message.error('请选择砍价商品');
|
message.error('请选择砍价商品');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!skuId.value) {
|
// 价格需要转为分
|
||||||
message.error('请选择商品 SKU');
|
products.forEach((item) => {
|
||||||
return;
|
item.bargainFirstPrice = convertToInteger(item.bargainFirstPrice);
|
||||||
}
|
item.bargainMinPrice = convertToInteger(item.bargainMinPrice);
|
||||||
|
});
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
modalApi.lock();
|
|
||||||
try {
|
|
||||||
const values = await formApi.getValues();
|
const values = await formApi.getValues();
|
||||||
const data = {
|
const data = {
|
||||||
...values,
|
...values,
|
||||||
spuId: spuId.value,
|
// 用户每次砍价金额元转分
|
||||||
skuId: skuId.value,
|
|
||||||
bargainFirstPrice: Math.round((values.bargainFirstPrice || 0) * 100),
|
|
||||||
bargainMinPrice: Math.round((values.bargainMinPrice || 0) * 100),
|
|
||||||
randomMinPrice: values.randomMinPrice
|
randomMinPrice: values.randomMinPrice
|
||||||
? Math.round(values.randomMinPrice * 100)
|
? convertToInteger(values.randomMinPrice)
|
||||||
: undefined,
|
: undefined,
|
||||||
randomMaxPrice: values.randomMaxPrice
|
randomMaxPrice: values.randomMaxPrice
|
||||||
? Math.round(values.randomMaxPrice * 100)
|
? convertToInteger(values.randomMaxPrice)
|
||||||
: undefined,
|
: undefined,
|
||||||
|
// 合并砍价商品配置(砍价活动只有一个商品)
|
||||||
|
...products[0],
|
||||||
} as MallBargainActivityApi.BargainActivity;
|
} as MallBargainActivityApi.BargainActivity;
|
||||||
|
|
||||||
await (formData.value?.id
|
await (formData.value?.id
|
||||||
? updateBargainActivity(data)
|
? updateBargainActivity(data)
|
||||||
: createBargainActivity(data));
|
: createBargainActivity(data));
|
||||||
@@ -132,54 +207,44 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
async onOpenChange(isOpen: boolean) {
|
async onOpenChange(isOpen: boolean) {
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
formData.value = undefined;
|
formData.value = undefined;
|
||||||
spuId.value = undefined;
|
spuList.value = [];
|
||||||
skuId.value = undefined;
|
spuPropertyList.value = [];
|
||||||
spuName.value = '';
|
|
||||||
skuInfo.value = undefined;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加载表单数据
|
|
||||||
|
// 加载数据
|
||||||
const data = modalApi.getData<MallBargainActivityApi.BargainActivity>();
|
const data = modalApi.getData<MallBargainActivityApi.BargainActivity>();
|
||||||
if (!data || !data.id) {
|
if (!data || !data.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 加载数据
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
formData.value = await getBargainActivity(data.id);
|
formData.value = await getBargainActivity(data.id);
|
||||||
await nextTick();
|
// 对齐活动商品处理结构
|
||||||
|
await getSpuDetails(
|
||||||
|
formData.value.spuId,
|
||||||
|
[formData.value.skuId],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
spuId: formData.value.spuId,
|
||||||
|
skuId: formData.value.skuId,
|
||||||
|
bargainFirstPrice: formData.value.bargainFirstPrice, // 砍价起始价格,单位分
|
||||||
|
bargainMinPrice: formData.value.bargainMinPrice, // 砍价底价
|
||||||
|
stock: formData.value.stock, // 活动库存
|
||||||
|
},
|
||||||
|
],
|
||||||
|
);
|
||||||
// 设置表单值时,价格字段从分转换为元
|
// 设置表单值时,价格字段从分转换为元
|
||||||
await formApi.setValues({
|
await formApi.setValues({
|
||||||
...formData.value,
|
...formData.value,
|
||||||
bargainFirstPrice: (formData.value.bargainFirstPrice || 0) / 100,
|
|
||||||
bargainMinPrice: (formData.value.bargainMinPrice || 0) / 100,
|
|
||||||
randomMinPrice: formData.value.randomMinPrice
|
randomMinPrice: formData.value.randomMinPrice
|
||||||
? formData.value.randomMinPrice / 100
|
? formatToFraction(formData.value.randomMinPrice)
|
||||||
: undefined,
|
: undefined,
|
||||||
randomMaxPrice: formData.value.randomMaxPrice
|
randomMaxPrice: formData.value.randomMaxPrice
|
||||||
? formData.value.randomMaxPrice / 100
|
? formatToFraction(formData.value.randomMaxPrice)
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
// 加载商品和 SKU 信息
|
|
||||||
if (formData.value.spuId) {
|
|
||||||
const spu = await getSpu(formData.value.spuId);
|
|
||||||
if (spu) {
|
|
||||||
spuId.value = spu.id;
|
|
||||||
spuName.value = spu.name || '';
|
|
||||||
if (formData.value.skuId) {
|
|
||||||
const selectedSku = spu.skus?.find(
|
|
||||||
(sku) => sku.id === formData.value?.skuId,
|
|
||||||
);
|
|
||||||
if (selectedSku) {
|
|
||||||
skuId.value = selectedSku.id;
|
|
||||||
skuInfo.value = {
|
|
||||||
skuName: selectedSku.name || '',
|
|
||||||
picUrl: selectedSku.picUrl || spu.picUrl || '',
|
|
||||||
price: Number(selectedSku.price) || 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.unlock();
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
@@ -188,67 +253,67 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Modal class="w-3/5" :title="getTitle">
|
<div>
|
||||||
<div class="mx-4">
|
<Modal :title="getTitle" class="w-[70%]">
|
||||||
<Form />
|
<Form class="mx-4">
|
||||||
|
<!-- 商品选择 -->
|
||||||
<!-- 商品选择区域 -->
|
<template #spuId>
|
||||||
<div class="mt-4">
|
<div class="w-full">
|
||||||
<div class="mb-2 flex items-center">
|
<Button v-if="!formData?.id" type="primary" @click="openSpuSelect">
|
||||||
<span class="text-sm font-medium">砍价活动商品:</span>
|
|
||||||
<Button class="ml-2" type="primary" @click="handleSelectProduct">
|
|
||||||
选择商品
|
选择商品
|
||||||
</Button>
|
</Button>
|
||||||
<span v-if="spuName" class="ml-4 text-sm text-gray-600">
|
|
||||||
已选择: {{ spuName }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- SKU 信息展示 -->
|
<!-- SPU 和 SKU 列表展示 -->
|
||||||
<div v-if="skuInfo" class="mt-4">
|
<SpuAndSkuList
|
||||||
<table class="w-full border-collapse border border-gray-300">
|
ref="spuAndSkuListRef"
|
||||||
<!-- TODO @puhui999:和 element-plus 有点差别哈;ps:是不是用 grid 组件呀?或者 vxe 组件
|
:rule-config="ruleConfig"
|
||||||
图片
|
:spu-list="spuList"
|
||||||
颜色
|
:spu-property-list-p="spuPropertyList"
|
||||||
版本
|
class="mt-4"
|
||||||
商品条码
|
>
|
||||||
销售价(元)
|
<!-- 扩展列:砍价活动特有配置 -->
|
||||||
市场价(元)
|
<template #default>
|
||||||
成本价(元)
|
<VxeColumn
|
||||||
库存
|
align="center"
|
||||||
砍价起始价格(元)
|
min-width="168"
|
||||||
砍价底价(元)
|
title="砍价起始价格(元)"
|
||||||
活动库存
|
>
|
||||||
-->
|
<template #default="{ row: sku }">
|
||||||
<thead>
|
<InputNumber
|
||||||
<tr class="bg-gray-100">
|
v-model:value="sku.productConfig.bargainFirstPrice"
|
||||||
<th class="border border-gray-300 px-4 py-2">商品图片</th>
|
:min="0"
|
||||||
<th class="border border-gray-300 px-4 py-2">SKU 名称</th>
|
:precision="2"
|
||||||
<th class="border border-gray-300 px-4 py-2">原价(元)</th>
|
:step="0.1"
|
||||||
</tr>
|
class="w-full"
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td class="border border-gray-300 px-4 py-2 text-center">
|
|
||||||
<img
|
|
||||||
v-if="skuInfo.picUrl"
|
|
||||||
:src="skuInfo.picUrl"
|
|
||||||
alt="商品图片"
|
|
||||||
class="h-16 w-16 object-cover"
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</template>
|
||||||
<td class="border border-gray-300 px-4 py-2">
|
</VxeColumn>
|
||||||
{{ skuInfo.skuName }}
|
<VxeColumn align="center" min-width="168" title="砍价底价(元)">
|
||||||
</td>
|
<template #default="{ row: sku }">
|
||||||
<td class="border border-gray-300 px-4 py-2 text-center">
|
<InputNumber
|
||||||
¥{{ (skuInfo.price / 100).toFixed(2) }}
|
v-model:value="sku.productConfig.bargainMinPrice"
|
||||||
</td>
|
:min="0"
|
||||||
</tr>
|
:precision="2"
|
||||||
</tbody>
|
:step="0.1"
|
||||||
</table>
|
class="w-full"
|
||||||
</div>
|
/>
|
||||||
</div>
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn align="center" min-width="168" title="活动库存">
|
||||||
|
<template #default="{ row: sku }">
|
||||||
|
<InputNumber
|
||||||
|
v-model:value="sku.productConfig.stock"
|
||||||
|
:max="sku.stock"
|
||||||
|
:min="0"
|
||||||
|
class="w-full"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</template>
|
||||||
|
</SpuAndSkuList>
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<!-- 商品选择器弹窗(单选模式) -->
|
<!-- 商品选择器弹窗(单选模式) -->
|
||||||
@@ -258,4 +323,5 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
:radio="true"
|
:radio="true"
|
||||||
@select="handleSpuSelected"
|
@select="handleSpuSelected"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user