Merge remote-tracking branch 'origin/dev' into dev

pull/546/MERGE
YunaiV 2024-09-09 09:30:56 +08:00
commit f07c74d83c
3 changed files with 85 additions and 47 deletions

View File

@ -180,17 +180,17 @@
</el-table-column>
<el-table-column align="center" label="销售价(元)" min-width="80">
<template #default="{ row }">
{{ formatToFraction(row.price) }}
{{ row.price }}
</template>
</el-table-column>
<el-table-column align="center" label="市场价(元)" min-width="80">
<template #default="{ row }">
{{ formatToFraction(row.marketPrice) }}
{{ row.marketPrice }}
</template>
</el-table-column>
<el-table-column align="center" label="成本价(元)" min-width="80">
<template #default="{ row }">
{{ formatToFraction(row.costPrice) }}
{{ row.costPrice }}
</template>
</el-table-column>
<el-table-column align="center" label="库存" min-width="80">
@ -211,12 +211,12 @@
<template v-if="formData!.subCommissionType">
<el-table-column align="center" label="一级返佣(元)" min-width="80">
<template #default="{ row }">
{{ formatToFraction(row.firstBrokeragePrice) }}
{{ row.firstBrokeragePrice }}
</template>
</el-table-column>
<el-table-column align="center" label="二级返佣(元)" min-width="80">
<template #default="{ row }">
{{ formatToFraction(row.secondBrokeragePrice) }}
{{ row.secondBrokeragePrice }}
</template>
</el-table-column>
</template>

View File

@ -30,13 +30,13 @@
<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"
v-if="spuData.length > 1 && deletable"
align="center"
label="操作"
min-width="90"
>
<template #default="scope">
<el-button type="primary" link @click="deleteSpu(scope.row.id)"> </el-button>
<el-button link type="primary" @click="deleteSpu(scope.row.id)"> </el-button>
</template>
</el-table-column>
</el-table>
@ -56,13 +56,13 @@ const props = defineProps<{
spuList: T[]
ruleConfig: RuleConfig[]
spuPropertyListP: SpuProperty<T>[]
isDelete?: boolean // SPU TODO deletable
deletable?: boolean // SPU
}>()
const spuData = ref<Spu[]>([]) // spu
const skuListRef = ref() // Ref
const spuPropertyList = ref<SpuProperty<T>[]>([]) // spuId sku
const expandRowKeys = ref<number[]>() // row-key 使 keys
const expandRowKeys = ref<string[]>([]) // row-key 使 keys
/**
* 获取所有 sku 活动配置
@ -71,10 +71,10 @@ const expandRowKeys = ref<number[]>() // 控制展开行需要设置 row-key 属
*/
const getSkuConfigs = (extendedAttribute: string) => {
skuListRef.value.validateSku()
const seckillProducts = []
const seckillProducts: any[] = []
spuPropertyList.value.forEach((item) => {
item.spuDetail.skus.forEach((sku) => {
seckillProducts.push(sku[extendedAttribute])
item.spuDetail.skus?.forEach((sku: any) => {
seckillProducts.push(sku[extendedAttribute] as any)
})
})
return seckillProducts
@ -124,10 +124,10 @@ watch(
() => props.spuPropertyListP,
(data) => {
if (!data) return
spuPropertyList.value = data as SpuProperty<T>[]
spuPropertyList.value = data as SpuProperty<T>[] as any
// spu sku SkuList
setTimeout(() => {
expandRowKeys.value = data.map((item) => item.spuId)
expandRowKeys.value = data.map((item) => item.spuId + '')
}, 200)
},
{

View File

@ -8,28 +8,40 @@
:schema="allSchemas.formSchema"
>
<!-- 先选择 -->
<!-- TODO @zhangshuai商品允许选择多个 -->
<!-- TODO @zhangshuai选择后的 SKU需要后面加个删除按钮 -->
<!-- TODO @zhangshuai展示的金额貌似不对大了 100 需要看下 -->
<!-- TODO @zhangshuai优惠类型是每个 SKU 可以自定义已设置哈因为每个商品 SKU 的折扣和减少价格可能不同具体交互可以注册一个 youzan.com 看看它的交互方式是如果设置了优惠金额则算减价如果再次设置了折扣百分比就算打折这样形成一个互斥的优惠类型 -->
<template #spuId>
<el-button @click="spuSelectRef.open()"></el-button>
<SpuAndSkuList
ref="spuAndSkuListRef"
:deletable="true"
: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 }">
<el-input-number v-model="sku.productConfig.discountPrice" :min="0" class="w-100%" />
<template #default="{ row }">
<el-input-number
v-model="row.productConfig.discountPrice"
:max="parseFloat(fenToYuan(row.price))"
:min="0"
:precision="2"
:step="0.1"
class="w-100%"
@change="handleSkuDiscountPriceChange(row)"
/>
</template>
</el-table-column>
<el-table-column align="center" label="折扣百分比(%)" min-width="168">
<template #default="{ row: sku }">
<el-input-number v-model="sku.productConfig.discountPercent" class="w-100%" />
<template #default="{ row }">
<el-input-number
v-model="row.productConfig.discountPercent"
:max="100"
:min="0"
:precision="2"
:step="0.1"
class="w-100%"
@change="handleSkuDiscountPercentChange(row)"
/>
</template>
</el-table-column>
</SpuAndSkuList>
@ -45,11 +57,12 @@
<script lang="ts" setup>
import { SpuAndSkuList, SpuProperty, SpuSelect } from '../components'
import { allSchemas, rules } from './discountActivity.data'
import { cloneDeep } from 'lodash-es'
import { cloneDeep, debounce } 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'
import { convertToInteger, erpCalculatePercentage, fenToYuan, yuanToFen } from '@/utils'
import { PromotionDiscountTypeEnum } from '@/utils/constants'
defineOptions({ name: 'PromotionDiscountActivityForm' })
@ -65,11 +78,19 @@ const formRef = ref() // 表单 Ref
const spuSelectRef = ref() // Ref
const spuAndSkuListRef = ref() // sku Ref
const ruleConfig: RuleConfig[] = []
const ruleConfig: RuleConfig[] = [
{
name: 'productConfig.discountPrice',
rule: (arg) => arg > 0,
message: '商品优惠金额不能为 0 '
}
]
const spuList = ref<DiscountActivityApi.SpuExtension[]>([]) // spu
const spuPropertyList = ref<SpuProperty<DiscountActivityApi.SpuExtension>[]>([])
const spuIds = ref<number[]>([])
const selectSpu = (spuId: number, skuIds: number[]) => {
// TODO puhui999: spu spuId spuIds 🤣
formRef.value.setValues({ spuId })
getSpuDetails(spuId, skuIds)
}
/**
@ -101,21 +122,20 @@ const getSpuDetails = async (
selectSkus?.forEach((sku) => {
let config: DiscountActivityApi.DiscountProductVO = {
skuId: sku.id!,
spuId: spu.id,
spuId: spu.id!,
discountType: 1,
discountPercent: 0,
discountPrice: 0
}
if (typeof products !== 'undefined') {
const product = products.find((item) => item.skuId === sku.id)
if (product) {
product.discountPercent = fenToYuan(product.discountPercent) as any
product.discountPrice = fenToYuan(product.discountPrice) as any
}
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[]
spuPropertyList.value.push({
@ -168,25 +188,13 @@ const submitForm = async () => {
//
formLoading.value = true
try {
const data = formRef.value.formModel as DiscountActivityApi.DiscountActivityVO
//
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
//
// TODO @puhui999 youzan
let discountInvalid = false
products.forEach((item: DiscountActivityApi.DiscountProductVO) => {
if (item.discountPrice != null && item.discountPrice > 0) {
item.discountType = 1
} else if (item.discountPercent != null && item.discountPercent > 0) {
item.discountType = 2
} else {
discountInvalid = true
}
item.discountPercent = convertToInteger(item.discountPercent)
item.discountPrice = convertToInteger(item.discountPrice)
})
if (discountInvalid) {
message.error('优惠金额和折扣百分比需要填写一个')
return
}
const data = cloneDeep(formRef.value.formModel) as DiscountActivityApi.DiscountActivityVO
data.products = products
//
if (formType.value === 'create') {
@ -204,6 +212,36 @@ const submitForm = async () => {
}
}
/** 处理 sku 优惠金额变动 */
const handleSkuDiscountPriceChange = debounce((row: any) => {
//
if (row.productConfig.discountPrice <= 0) {
return
}
//
row.productConfig.discountType = PromotionDiscountTypeEnum.PRICE.type
//
row.productConfig.discountPercent = erpCalculatePercentage(
row.price - yuanToFen(row.productConfig.discountPrice),
row.price
)
}, 200)
/** 处理 sku 优惠折扣变动 */
const handleSkuDiscountPercentChange = debounce((row: any) => {
//
if (row.productConfig.discountPercent <= 0 || row.productConfig.discountPercent >= 100) {
return
}
//
row.productConfig.discountType = PromotionDiscountTypeEnum.PERCENT.type
//
row.productConfig.discountPrice = fenToYuan(
row.price - row.price * (row.productConfig.discountPercent / 100.0 || 0)
)
}, 200)
/** 重置表单 */
const resetForm = async () => {
spuList.value = []