commit
2434911064
|
@ -29,6 +29,17 @@
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column align="center" label="销量" min-width="90" prop="salesCount" />
|
<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 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>
|
</el-table>
|
||||||
</template>
|
</template>
|
||||||
<script generic="T extends Spu" lang="ts" setup>
|
<script generic="T extends Spu" lang="ts" setup>
|
||||||
|
@ -40,10 +51,13 @@ import { SpuProperty } from '@/views/mall/promotion/components/index'
|
||||||
|
|
||||||
defineOptions({ name: 'PromotionSpuAndSkuList' })
|
defineOptions({ name: 'PromotionSpuAndSkuList' })
|
||||||
|
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
spuList: T[]
|
spuList: T[]
|
||||||
ruleConfig: RuleConfig[]
|
ruleConfig: RuleConfig[]
|
||||||
spuPropertyListP: SpuProperty<T>[]
|
spuPropertyListP: SpuProperty<T>[]
|
||||||
|
isDelete?: boolean //spu是否可以多选
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const spuData = ref<Spu[]>([]) // 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
|
* 将传进来的值赋值给 skuList
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
:rule-config="ruleConfig"
|
:rule-config="ruleConfig"
|
||||||
:spu-list="spuList"
|
:spu-list="spuList"
|
||||||
:spu-property-list-p="spuPropertyList"
|
:spu-property-list-p="spuPropertyList"
|
||||||
|
:isDelete="true"
|
||||||
|
@delete="deleteSpu"
|
||||||
>
|
>
|
||||||
<el-table-column align="center" label="优惠金额" min-width="168">
|
<el-table-column align="center" label="优惠金额" min-width="168">
|
||||||
<template #default="{ row: sku }">
|
<template #default="{ row: sku }">
|
||||||
|
@ -47,6 +49,7 @@ import { cloneDeep } from 'lodash-es'
|
||||||
import * as DiscountActivityApi from '@/api/mall/promotion/discount/discountActivity'
|
import * as DiscountActivityApi from '@/api/mall/promotion/discount/discountActivity'
|
||||||
import * as ProductSpuApi from '@/api/mall/product/spu'
|
import * as ProductSpuApi from '@/api/mall/product/spu'
|
||||||
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
|
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
|
||||||
|
import {formatToFraction} from "@/utils";
|
||||||
|
|
||||||
defineOptions({ name: 'PromotionDiscountActivityForm' })
|
defineOptions({ name: 'PromotionDiscountActivityForm' })
|
||||||
|
|
||||||
|
@ -65,8 +68,8 @@ const spuAndSkuListRef = ref() // sku 限时折扣 配置组件Ref
|
||||||
const ruleConfig: RuleConfig[] = []
|
const ruleConfig: RuleConfig[] = []
|
||||||
const spuList = ref<DiscountActivityApi.SpuExtension[]>([]) // 选择的 spu
|
const spuList = ref<DiscountActivityApi.SpuExtension[]>([]) // 选择的 spu
|
||||||
const spuPropertyList = ref<SpuProperty<DiscountActivityApi.SpuExtension>[]>([])
|
const spuPropertyList = ref<SpuProperty<DiscountActivityApi.SpuExtension>[]>([])
|
||||||
|
const spuIds = ref<number[]>([]);
|
||||||
const selectSpu = (spuId: number, skuIds: number[]) => {
|
const selectSpu = (spuId: number, skuIds: number[]) => {
|
||||||
formRef.value.setValues({ spuId })
|
|
||||||
getSpuDetails(spuId, skuIds)
|
getSpuDetails(spuId, skuIds)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -75,14 +78,22 @@ const selectSpu = (spuId: number, skuIds: number[]) => {
|
||||||
const getSpuDetails = async (
|
const getSpuDetails = async (
|
||||||
spuId: number,
|
spuId: number,
|
||||||
skuIds: number[] | undefined,
|
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[]
|
const res = (await ProductSpuApi.getSpuDetailList([spuId])) as DiscountActivityApi.SpuExtension[]
|
||||||
if (res.length == 0) {
|
if (res.length == 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
spuList.value = []
|
//spuList.value = []
|
||||||
// 因为只能选择一个
|
// 因为只能选择一个
|
||||||
const spu = res[0]
|
const spu = res[0]
|
||||||
const selectSkus =
|
const selectSkus =
|
||||||
|
@ -100,15 +111,19 @@ const getSpuDetails = async (
|
||||||
config = product || config
|
config = product || config
|
||||||
}
|
}
|
||||||
sku.productConfig = 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[]
|
spu.skus = selectSkus as DiscountActivityApi.SkuExtension[]
|
||||||
spuProperties.push({
|
spuPropertyList.value.push({
|
||||||
spuId: spu.id!,
|
spuId: spu.id!,
|
||||||
spuDetail: spu,
|
spuDetail: spu,
|
||||||
propertyList: getPropertyList(spu)
|
propertyList: getPropertyList(spu)
|
||||||
})
|
})
|
||||||
spuList.value.push(spu)
|
spuList.value.push(spu)
|
||||||
spuPropertyList.value = spuProperties
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= end =================
|
// ================= end =================
|
||||||
|
@ -126,8 +141,10 @@ const open = async (type: string, id?: number) => {
|
||||||
const data = (await DiscountActivityApi.getDiscountActivity(
|
const data = (await DiscountActivityApi.getDiscountActivity(
|
||||||
id
|
id
|
||||||
)) as DiscountActivityApi.DiscountActivityVO
|
)) as DiscountActivityApi.DiscountActivityVO
|
||||||
const supId = data.products[0].spuId
|
for (let productsKey in data.products) {
|
||||||
await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products)
|
const supId = data.products[productsKey].spuId
|
||||||
|
await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products,"load")
|
||||||
|
}
|
||||||
formRef.value.setValues(data)
|
formRef.value.setValues(data)
|
||||||
} finally {
|
} finally {
|
||||||
formLoading.value = false
|
formLoading.value = false
|
||||||
|
@ -149,9 +166,20 @@ const submitForm = async () => {
|
||||||
const data = formRef.value.formModel as DiscountActivityApi.DiscountActivityVO
|
const data = formRef.value.formModel as DiscountActivityApi.DiscountActivityVO
|
||||||
// 获取 折扣商品配置
|
// 获取 折扣商品配置
|
||||||
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
|
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
|
||||||
|
let timp = false;
|
||||||
products.forEach((item: DiscountActivityApi.DiscountProductVO) => {
|
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
|
data.products = products
|
||||||
// 真正提交
|
// 真正提交
|
||||||
if (formType.value === 'create') {
|
if (formType.value === 'create') {
|
||||||
|
@ -173,7 +201,16 @@ const submitForm = async () => {
|
||||||
const resetForm = async () => {
|
const resetForm = async () => {
|
||||||
spuList.value = []
|
spuList.value = []
|
||||||
spuPropertyList.value = []
|
spuPropertyList.value = []
|
||||||
|
spuIds.value = []
|
||||||
await nextTick()
|
await nextTick()
|
||||||
formRef.value.getElFormRef().resetFields()
|
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>
|
</script>
|
||||||
|
|
|
@ -72,17 +72,6 @@ const crudSchemas = reactive<CrudSchema[]>([
|
||||||
width: 120
|
width: 120
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: '优惠类型',
|
|
||||||
field: 'discountType',
|
|
||||||
dictType: DICT_TYPE.PROMOTION_DISCOUNT_TYPE,
|
|
||||||
dictClass: 'number',
|
|
||||||
isSearch: true,
|
|
||||||
form: {
|
|
||||||
component: 'Radio',
|
|
||||||
value: 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: '活动商品',
|
label: '活动商品',
|
||||||
field: 'spuId',
|
field: 'spuId',
|
||||||
|
|
|
@ -70,17 +70,17 @@
|
||||||
~ {{ formatDate(scope.row.endTime, 'YYYY-MM-DD') }}
|
~ {{ formatDate(scope.row.endTime, 'YYYY-MM-DD') }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="商品图片" prop="spuName" min-width="80">
|
<!-- <el-table-column label="商品图片" prop="spuName" min-width="80">-->
|
||||||
<template #default="scope">
|
<!-- <template #default="scope">-->
|
||||||
<el-image
|
<!-- <el-image-->
|
||||||
:src="scope.row.picUrl"
|
<!-- :src="scope.row.picUrl"-->
|
||||||
class="h-40px w-40px"
|
<!-- class="h-40px w-40px"-->
|
||||||
:preview-src-list="[scope.row.picUrl]"
|
<!-- :preview-src-list="[scope.row.picUrl]"-->
|
||||||
preview-teleported
|
<!-- preview-teleported-->
|
||||||
/>
|
<!-- />-->
|
||||||
</template>
|
<!-- </template>-->
|
||||||
</el-table-column>
|
<!-- </el-table-column>-->
|
||||||
<el-table-column label="商品标题" prop="spuName" min-width="300" />
|
<!-- <el-table-column label="商品标题" prop="spuName" min-width="300" />-->
|
||||||
<el-table-column label="活动状态" align="center" prop="status" min-width="100">
|
<el-table-column label="活动状态" align="center" prop="status" min-width="100">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
|
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
|
||||||
|
|
Loading…
Reference in New Issue