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

pull/533/head
YunaiV 2024-08-26 21:58:24 +08:00
commit af1bec2a8c
4 changed files with 51 additions and 40 deletions

View File

@ -32,7 +32,6 @@
格式为 <b style="color: #f56c6c">{{ fileType.join('/') }}</b> 的文件
</div>
</template>
<!-- TODO @puhui9991表单展示的时候位置会偏掉已发微信-->
<template #file="row">
<div class="flex items-center">
<span>{{ row.file.name }}</span>

View File

@ -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

View File

@ -25,12 +25,13 @@
订单金额优惠
<el-form-item>
<!-- TODO @puhui999需要考虑 100 换算哈 -->
<el-input
<el-input-number
v-model="rule.discountPrice"
:min="0"
:precision="2"
:step="0.1"
class="w-150px! p-x-20px!"
placeholder=""
type="number"
controls-position="right"
/>
</el-form-item>
@ -71,9 +72,9 @@
inactive-text="否"
inline-prompt
/>
<RewardRuleCouponShowcase
<RewardRuleCouponSelect
v-if="rule.giveCoupon"
ref="rewardRuleCouponShowcaseRef"
ref="rewardRuleCouponSelectRef"
v-model="rule!"
/>
</el-col>
@ -88,12 +89,14 @@
</template>
<script lang="ts" setup>
import RewardRuleCouponShowcase from './RewardRuleCouponShowcase.vue'
import RewardRuleCouponSelect from './RewardRuleCouponSelect.vue'
import { RewardActivityVO } from '@/api/mall/promotion/reward/rewardActivity'
import { PromotionConditionTypeEnum } from '@/utils/constants'
import { useVModel } from '@vueuse/core'
import { isEmpty } from '@/utils/is'
defineOptions({ name: 'RewardRule' })
const props = defineProps<{
modelValue: RewardActivityVO
}>()
@ -104,7 +107,7 @@ const emits = defineEmits<{
}>()
const formData = useVModel(props, 'modelValue', emits) //
const rewardRuleCouponShowcaseRef = ref<InstanceType<typeof RewardRuleCouponShowcase>[]>() // Ref
const rewardRuleCouponSelectRef = ref<InstanceType<typeof RewardRuleCouponSelect>[]>() // Ref
/** 删除优惠规则 */
const deleteRule = (ruleIndex: number) => {
@ -127,14 +130,20 @@ const addRule = () => {
/** 设置规则优惠券-提交时 */
const setRuleCoupon = () => {
if (isEmpty(rewardRuleCouponShowcaseRef.value)) {
if (isEmpty(rewardRuleCouponSelectRef.value)) {
return
}
rewardRuleCouponShowcaseRef.value?.forEach((item) => item.setGiveCouponList())
//
formData.value.rules.forEach((rule) => {
if (!rule.giveCoupon) {
rule.couponIds = []
rule.couponCounts = []
}
})
//
rewardRuleCouponSelectRef.value?.forEach((item) => item.setGiveCouponList())
}
defineExpose({ setRuleCoupon })
</script>
<style lang="scss" scoped></style>

View File

@ -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 })