{{ row.file.name }}
diff --git a/src/views/mall/promotion/rewardActivity/RewardForm.vue b/src/views/mall/promotion/rewardActivity/RewardForm.vue
index 623fbdfb..6556a156 100644
--- a/src/views/mall/promotion/rewardActivity/RewardForm.vue
+++ b/src/views/mall/promotion/rewardActivity/RewardForm.vue
@@ -74,6 +74,8 @@ import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as RewardActivityApi from '@/api/mall/promotion/reward/rewardActivity'
import { PromotionConditionTypeEnum, PromotionProductScopeEnum } from '@/utils/constants'
import ProductCategorySelect from '@/views/mall/product/category/components/ProductCategorySelect.vue'
+import { cloneDeep } from 'lodash-es'
+import { fenToYuan, yuanToFen } from '@/utils'
defineOptions({ name: 'ProductBrandForm' })
@@ -111,7 +113,12 @@ const open = async (type: string, id?: number) => {
formLoading.value = true
try {
const data = await RewardActivityApi.getReward(id)
+ // 转区段时间
data.startAndEndTime = [data.startTime, data.endTime]
+ // 规则分转元
+ data.rules.forEach((item: any) => {
+ item.discountPrice = fenToYuan(item.discountPrice || 0)
+ })
formData.value = data
// 获得商品范围
await getProductScope()
@@ -126,7 +133,7 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const submitForm = async () => {
// 校验表单
- if (!formRef) return
+ if (!formRef.value) return
const valid = await formRef.value.validate()
if (!valid) return
@@ -135,7 +142,14 @@ const submitForm = async () => {
try {
// 设置活动规则优惠券
rewardRuleRef.value?.setRuleCoupon()
- const data = formData.value
+ const data = cloneDeep(formData.value)
+ // 时间段转换
+ data.startTime = data.startAndEndTime![0]
+ data.endTime = data.startAndEndTime![1]
+ // 规则元转分
+ data.rules.forEach((item) => {
+ item.discountPrice = yuanToFen(item.discountPrice || 0)
+ })
// 设置商品范围
setProductScopeValues(data)
if (formType.value === 'create') {
@@ -170,16 +184,14 @@ const getProductScope = async () => {
formData.value.productSpuIds = formData.value.productScopeValues
break
case PromotionProductScopeEnum.CATEGORY.scope:
- // TODO @puhui999:可以直接 await nextTick() 呀。
- await nextTick(() => {
- let productCategoryIds = formData.value.productScopeValues as any
- if (Array.isArray(productCategoryIds) && productCategoryIds.length > 0) {
- // 单选时使用数组不能反显
- productCategoryIds = productCategoryIds[0]
- }
- // 设置品类编号
- formData.value.productCategoryIds = productCategoryIds
- })
+ await nextTick()
+ let productCategoryIds = formData.value.productScopeValues as any
+ if (Array.isArray(productCategoryIds) && productCategoryIds.length > 0) {
+ // 单选时使用数组不能反显
+ productCategoryIds = productCategoryIds[0]
+ }
+ // 设置品类编号
+ formData.value.productCategoryIds = productCategoryIds
break
default:
break
diff --git a/src/views/mall/promotion/rewardActivity/components/RewardRule.vue b/src/views/mall/promotion/rewardActivity/components/RewardRule.vue
index 1bb19482..a4bb8542 100644
--- a/src/views/mall/promotion/rewardActivity/components/RewardRule.vue
+++ b/src/views/mall/promotion/rewardActivity/components/RewardRule.vue
@@ -25,12 +25,13 @@
订单金额优惠
减
-
-
元
@@ -71,9 +72,9 @@
inactive-text="否"
inline-prompt
/>
-
@@ -88,12 +89,14 @@
-
-
diff --git a/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue b/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponSelect.vue
similarity index 84%
rename from src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue
rename to src/views/mall/promotion/rewardActivity/components/RewardRuleCouponSelect.vue
index d1e26bbd..fba04e81 100644
--- a/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue
+++ b/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponSelect.vue
@@ -40,7 +40,7 @@ import { isEmpty } from '@/utils/is'
import { useVModel } from '@vueuse/core'
import { findIndex } from '@/utils'
-// TODO @puhui999:要不就叫 RewardRuleCouponSelect
+defineOptions({ name: 'RewardRuleCouponSelect' })
const props = defineProps<{
modelValue: RewardRule
@@ -89,15 +89,13 @@ const initGiveCouponList = async () => {
if (!data) {
return
}
-
- for (let i = 0; i < data.length; i++) {
- const coupon = data[i]
- const index = findIndex(rewardRule.value.couponIds!, (item) => item.id === coupon.id)
+ data.forEach((coupon) => {
+ const index = findIndex(rewardRule.value.couponIds!, (couponId) => couponId === coupon.id)
list.value.push({
...coupon,
giveCount: rewardRule.value.couponCounts![index]
})
- }
+ })
}
/** 设置赠送的优惠券 */
@@ -106,15 +104,8 @@ const setGiveCouponList = () => {
return
}
- const couponIds: number[] = []
- const couponCounts: number[] = []
- for (let i = 0, len = list.value.length; i < len; i++) {
- couponIds.push(list.value[i].id)
- couponCounts.push(list.value[i].giveCount!)
- }
- // TODO @puhui999:可以考虑,直接使用 list 的 map 操作,简单一些。性能没啥差别的
- rewardRule.value.couponIds = couponIds
- rewardRule.value.couponCounts = couponCounts
+ rewardRule.value.couponIds = list.value.map((rule) => rule.id)
+ rewardRule.value.couponCounts = list.value.map((rule) => rule.giveCount || 0)
}
defineExpose({ setGiveCouponList })