【修改】修改限时折扣:①【优化】商品允许选择多个;②【优化】选择后的 SKU,需要后面加个【删除】按钮;③【bug】展示的金额,貌似不对,大了 100 倍;④【优化】“优惠类型”,是每个 SKU 可以自定义已设置的
parent
ed36d2bfb4
commit
a06a50967e
|
@ -29,6 +29,17 @@
|
|||
</el-table-column>
|
||||
<el-table-column align="center" label="销量" min-width="90" prop="salesCount" />
|
||||
<el-table-column align="center" label="库存" min-width="90" prop="stock" />
|
||||
<el-table-column v-if="spuData.length > 1 && isDelete" align="center" label="操作" min-width="90" >
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
@click="deleteSpu(scope.row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
<script generic="T extends Spu" lang="ts" setup>
|
||||
|
@ -40,10 +51,13 @@ import { SpuProperty } from '@/views/mall/promotion/components/index'
|
|||
|
||||
defineOptions({ name: 'PromotionSpuAndSkuList' })
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const props = defineProps<{
|
||||
spuList: T[]
|
||||
ruleConfig: RuleConfig[]
|
||||
spuPropertyListP: SpuProperty<T>[]
|
||||
isDelete?: boolean //spu是否可以多选
|
||||
}>()
|
||||
|
||||
const spuData = ref<Spu[]>([]) // spu 详情数据列表
|
||||
|
@ -77,6 +91,19 @@ const imagePreview = (imgUrl: string) => {
|
|||
})
|
||||
}
|
||||
|
||||
// 删除时的触发事件
|
||||
const emits = defineEmits<{
|
||||
(e: 'delete', spuId: number): void
|
||||
}>()
|
||||
|
||||
/** 多选时可以删除spu **/
|
||||
const deleteSpu = async (spuId: number) => {
|
||||
await message.confirm('是否删除商品编号为' + spuId + '的数据?')
|
||||
let index = spuData.value.findIndex((item) => item.id == spuId)
|
||||
spuData.value.splice(index,1);
|
||||
emits('delete',spuId)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将传进来的值赋值给 skuList
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
:rule-config="ruleConfig"
|
||||
:spu-list="spuList"
|
||||
:spu-property-list-p="spuPropertyList"
|
||||
:isDelete="true"
|
||||
@delete="deleteSpu"
|
||||
>
|
||||
<el-table-column align="center" label="优惠金额" min-width="168">
|
||||
<template #default="{ row: sku }">
|
||||
|
@ -47,6 +49,7 @@ import { cloneDeep } from 'lodash-es'
|
|||
import * as DiscountActivityApi from '@/api/mall/promotion/discount/discountActivity'
|
||||
import * as ProductSpuApi from '@/api/mall/product/spu'
|
||||
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
|
||||
import {formatToFraction} from "@/utils";
|
||||
|
||||
defineOptions({ name: 'PromotionDiscountActivityForm' })
|
||||
|
||||
|
@ -65,8 +68,8 @@ const spuAndSkuListRef = ref() // sku 限时折扣 配置组件Ref
|
|||
const ruleConfig: RuleConfig[] = []
|
||||
const spuList = ref<DiscountActivityApi.SpuExtension[]>([]) // 选择的 spu
|
||||
const spuPropertyList = ref<SpuProperty<DiscountActivityApi.SpuExtension>[]>([])
|
||||
const spuIds = ref<number[]>([]);
|
||||
const selectSpu = (spuId: number, skuIds: number[]) => {
|
||||
formRef.value.setValues({ spuId })
|
||||
getSpuDetails(spuId, skuIds)
|
||||
}
|
||||
/**
|
||||
|
@ -75,14 +78,22 @@ const selectSpu = (spuId: number, skuIds: number[]) => {
|
|||
const getSpuDetails = async (
|
||||
spuId: number,
|
||||
skuIds: number[] | undefined,
|
||||
products?: DiscountActivityApi.DiscountProductVO[]
|
||||
products?: DiscountActivityApi.DiscountProductVO[],
|
||||
type?: string
|
||||
) => {
|
||||
const spuProperties: SpuProperty<DiscountActivityApi.SpuExtension>[] = []
|
||||
//如果已经包含spu则跳过
|
||||
if(spuIds.value.includes(spuId)){
|
||||
if(type !== "load"){
|
||||
message.error("数据重复选择!")
|
||||
}
|
||||
return;
|
||||
}
|
||||
spuIds.value.push(spuId)
|
||||
const res = (await ProductSpuApi.getSpuDetailList([spuId])) as DiscountActivityApi.SpuExtension[]
|
||||
if (res.length == 0) {
|
||||
return
|
||||
}
|
||||
spuList.value = []
|
||||
//spuList.value = []
|
||||
// 因为只能选择一个
|
||||
const spu = res[0]
|
||||
const selectSkus =
|
||||
|
@ -100,15 +111,19 @@ const getSpuDetails = async (
|
|||
config = product || config
|
||||
}
|
||||
sku.productConfig = config
|
||||
sku.price = formatToFraction(sku.price)
|
||||
sku.marketPrice = formatToFraction(sku.marketPrice)
|
||||
sku.costPrice = formatToFraction(sku.costPrice)
|
||||
sku.firstBrokeragePrice = formatToFraction(sku.firstBrokeragePrice)
|
||||
sku.secondBrokeragePrice = formatToFraction(sku.secondBrokeragePrice)
|
||||
})
|
||||
spu.skus = selectSkus as DiscountActivityApi.SkuExtension[]
|
||||
spuProperties.push({
|
||||
spuPropertyList.value.push({
|
||||
spuId: spu.id!,
|
||||
spuDetail: spu,
|
||||
propertyList: getPropertyList(spu)
|
||||
})
|
||||
spuList.value.push(spu)
|
||||
spuPropertyList.value = spuProperties
|
||||
}
|
||||
|
||||
// ================= end =================
|
||||
|
@ -126,8 +141,10 @@ const open = async (type: string, id?: number) => {
|
|||
const data = (await DiscountActivityApi.getDiscountActivity(
|
||||
id
|
||||
)) as DiscountActivityApi.DiscountActivityVO
|
||||
const supId = data.products[0].spuId
|
||||
await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products)
|
||||
for (let productsKey in data.products) {
|
||||
const supId = data.products[productsKey].spuId
|
||||
await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products,"load")
|
||||
}
|
||||
formRef.value.setValues(data)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
|
@ -149,9 +166,20 @@ const submitForm = async () => {
|
|||
const data = formRef.value.formModel as DiscountActivityApi.DiscountActivityVO
|
||||
// 获取 折扣商品配置
|
||||
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
|
||||
let timp = false;
|
||||
products.forEach((item: DiscountActivityApi.DiscountProductVO) => {
|
||||
item.discountType = data['discountType']
|
||||
if(item.discountPrice != null && item.discountPrice > 0){
|
||||
item.discountType = 1
|
||||
}else if(item.discountPercent != null && item.discountPercent > 0){
|
||||
item.discountType = 2
|
||||
}else{
|
||||
timp = true
|
||||
}
|
||||
})
|
||||
if(timp){
|
||||
message.error("优惠金额和折扣百分比需要填写一个");
|
||||
return;
|
||||
}
|
||||
data.products = products
|
||||
// 真正提交
|
||||
if (formType.value === 'create') {
|
||||
|
@ -173,7 +201,16 @@ const submitForm = async () => {
|
|||
const resetForm = async () => {
|
||||
spuList.value = []
|
||||
spuPropertyList.value = []
|
||||
spuIds.value = []
|
||||
await nextTick()
|
||||
formRef.value.getElFormRef().resetFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除spu
|
||||
*/
|
||||
const deleteSpu = (spuId: number) => {
|
||||
spuIds.value.splice(spuIds.value.findIndex((item) => item == spuId), 1)
|
||||
spuPropertyList.value.splice(spuPropertyList.value.findIndex((item) => item.spuId == spuId), 1)
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -72,17 +72,6 @@ const crudSchemas = reactive<CrudSchema[]>([
|
|||
width: 120
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '优惠类型',
|
||||
field: 'discountType',
|
||||
dictType: DICT_TYPE.PROMOTION_DISCOUNT_TYPE,
|
||||
dictClass: 'number',
|
||||
isSearch: true,
|
||||
form: {
|
||||
component: 'Radio',
|
||||
value: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '活动商品',
|
||||
field: 'spuId',
|
||||
|
|
|
@ -70,17 +70,17 @@
|
|||
~ {{ formatDate(scope.row.endTime, 'YYYY-MM-DD') }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品图片" prop="spuName" min-width="80">
|
||||
<template #default="scope">
|
||||
<el-image
|
||||
:src="scope.row.picUrl"
|
||||
class="h-40px w-40px"
|
||||
:preview-src-list="[scope.row.picUrl]"
|
||||
preview-teleported
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品标题" prop="spuName" min-width="300" />
|
||||
<!-- <el-table-column label="商品图片" prop="spuName" min-width="80">-->
|
||||
<!-- <template #default="scope">-->
|
||||
<!-- <el-image-->
|
||||
<!-- :src="scope.row.picUrl"-->
|
||||
<!-- class="h-40px w-40px"-->
|
||||
<!-- :preview-src-list="[scope.row.picUrl]"-->
|
||||
<!-- preview-teleported-->
|
||||
<!-- />-->
|
||||
<!-- </template>-->
|
||||
<!-- </el-table-column>-->
|
||||
<!-- <el-table-column label="商品标题" prop="spuName" min-width="300" />-->
|
||||
<el-table-column label="活动状态" align="center" prop="status" min-width="100">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
|
||||
|
|
Loading…
Reference in New Issue