mirror of
				https://gitee.com/hhyykk/ipms-sjy-ui.git
				synced 2025-11-04 12:18:43 +08:00 
			
		
		
		
	【代码优化】MALL: 满减送表单重构
This commit is contained in:
		@@ -1,34 +1,37 @@
 | 
			
		||||
import request from '@/config/axios'
 | 
			
		||||
 | 
			
		||||
export interface DiscountActivityVO {
 | 
			
		||||
export interface RewardActivityVO {
 | 
			
		||||
  id?: number
 | 
			
		||||
  name?: string
 | 
			
		||||
  startTime?: Date
 | 
			
		||||
  endTime?: Date
 | 
			
		||||
  startAndEndTime?: Date[] // 只前端使用
 | 
			
		||||
  remark?: string
 | 
			
		||||
  conditionType?: number
 | 
			
		||||
  productScope?: number
 | 
			
		||||
  productSpuIds?: number[]
 | 
			
		||||
  rules?: DiscountProductVO[]
 | 
			
		||||
  rules?: RewardRule[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 优惠规则
 | 
			
		||||
export interface DiscountProductVO {
 | 
			
		||||
  limit: number
 | 
			
		||||
  discountPrice: number
 | 
			
		||||
  freeDelivery: boolean
 | 
			
		||||
  point: number
 | 
			
		||||
  couponIds: number[]
 | 
			
		||||
  couponCounts: number[]
 | 
			
		||||
export interface RewardRule {
 | 
			
		||||
  limit?: number
 | 
			
		||||
  discountPrice?: number
 | 
			
		||||
  freeDelivery?: boolean
 | 
			
		||||
  givePoint?: boolean
 | 
			
		||||
  point?: number
 | 
			
		||||
  giveCoupon?: boolean
 | 
			
		||||
  couponIds?: number[]
 | 
			
		||||
  couponCounts?: number[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 新增满减送活动
 | 
			
		||||
export const createRewardActivity = async (data: DiscountActivityVO) => {
 | 
			
		||||
export const createRewardActivity = async (data: RewardActivityVO) => {
 | 
			
		||||
  return await request.post({ url: '/promotion/reward-activity/create', data })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更新满减送活动
 | 
			
		||||
export const updateRewardActivity = async (data: DiscountActivityVO) => {
 | 
			
		||||
export const updateRewardActivity = async (data: RewardActivityVO) => {
 | 
			
		||||
  return await request.put({ url: '/promotion/reward-activity/update', data })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <Dialog :title="dialogTitle" v-model="dialogVisible">
 | 
			
		||||
  <Dialog v-model="dialogVisible" :title="dialogTitle">
 | 
			
		||||
    <el-form
 | 
			
		||||
      ref="formRef"
 | 
			
		||||
      v-loading="formLoading"
 | 
			
		||||
      :model="formData"
 | 
			
		||||
      :rules="formRules"
 | 
			
		||||
      label-width="80px"
 | 
			
		||||
      v-loading="formLoading"
 | 
			
		||||
    >
 | 
			
		||||
      <el-form-item label="活动名称" prop="name">
 | 
			
		||||
        <el-input v-model="formData.name" placeholder="请输入活动名称" />
 | 
			
		||||
@@ -13,10 +13,10 @@
 | 
			
		||||
      <el-form-item label="活动时间" prop="startAndEndTime">
 | 
			
		||||
        <el-date-picker
 | 
			
		||||
          v-model="formData.startAndEndTime"
 | 
			
		||||
          type="datetimerange"
 | 
			
		||||
          range-separator="-"
 | 
			
		||||
          :start-placeholder="t('common.startTimeText')"
 | 
			
		||||
          :end-placeholder="t('common.endTimeText')"
 | 
			
		||||
          :start-placeholder="t('common.startTimeText')"
 | 
			
		||||
          range-separator="-"
 | 
			
		||||
          type="datetimerange"
 | 
			
		||||
        />
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="条件类型" prop="conditionType">
 | 
			
		||||
@@ -31,79 +31,7 @@
 | 
			
		||||
        </el-radio-group>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="优惠设置">
 | 
			
		||||
        <template v-for="(item, index) in formData.rules" :key="index">
 | 
			
		||||
          <el-row type="flex">
 | 
			
		||||
            <el-col :span="24" style="font-weight: bold; display: flex">
 | 
			
		||||
              活动层级{{ index + 1 }}
 | 
			
		||||
              <el-button
 | 
			
		||||
                link
 | 
			
		||||
                type="danger"
 | 
			
		||||
                style="margin-left: auto"
 | 
			
		||||
                v-if="index != 0"
 | 
			
		||||
                @click="deleteActivityRule(index)"
 | 
			
		||||
              >
 | 
			
		||||
                删除
 | 
			
		||||
              </el-button>
 | 
			
		||||
            </el-col>
 | 
			
		||||
            <e-form :ref="'formRef' + index" :model="item">
 | 
			
		||||
              <el-form-item
 | 
			
		||||
                label="优惠门槛:"
 | 
			
		||||
                prop="limit"
 | 
			
		||||
                label-width="100px"
 | 
			
		||||
                style="padding-left: 50px"
 | 
			
		||||
              >
 | 
			
		||||
                满
 | 
			
		||||
                <el-input
 | 
			
		||||
                  style="width: 150px; padding: 0 10px"
 | 
			
		||||
                  v-model="item.limit"
 | 
			
		||||
                  type="number"
 | 
			
		||||
                  placeholder=""
 | 
			
		||||
                />
 | 
			
		||||
                元
 | 
			
		||||
              </el-form-item>
 | 
			
		||||
              <el-form-item label="优惠内容:" label-width="100px" style="padding-left: 50px">
 | 
			
		||||
                <el-checkbox-group v-model="activityRules[index]" style="width: 100%">
 | 
			
		||||
                  <el-col :span="24">
 | 
			
		||||
                    <el-checkbox label="订单金额优惠" name="type" />
 | 
			
		||||
                    <el-form-item v-if="activityRules[index].includes('订单金额优惠')">
 | 
			
		||||
                      减
 | 
			
		||||
                      <el-input
 | 
			
		||||
                        style="width: 150px; padding: 0 20px"
 | 
			
		||||
                        v-model="item.discountPrice"
 | 
			
		||||
                        type="number"
 | 
			
		||||
                        placeholder=""
 | 
			
		||||
                      />
 | 
			
		||||
                      元
 | 
			
		||||
                    </el-form-item>
 | 
			
		||||
                  </el-col>
 | 
			
		||||
                  <el-col :span="24">
 | 
			
		||||
                    <el-checkbox v-model="item.freeDelivery" label="包邮" name="type" />
 | 
			
		||||
                  </el-col>
 | 
			
		||||
                  <el-col :span="24">
 | 
			
		||||
                    <el-checkbox label="送积分" name="type" />
 | 
			
		||||
                    <el-form-item v-if="activityRules[index].includes('送积分')">
 | 
			
		||||
                      送
 | 
			
		||||
                      <el-input
 | 
			
		||||
                        style="width: 150px; padding: 0 20px"
 | 
			
		||||
                        v-model="item.point"
 | 
			
		||||
                        type="number"
 | 
			
		||||
                        placeholder=""
 | 
			
		||||
                      />
 | 
			
		||||
                      积分
 | 
			
		||||
                    </el-form-item>
 | 
			
		||||
                  </el-col>
 | 
			
		||||
                  <!-- 优惠券待处理  也可以参考优惠劵的SpuShowcase-->
 | 
			
		||||
                  <!-- TODO 待实现!-->
 | 
			
		||||
                  <el-col :span="24">
 | 
			
		||||
                    <el-checkbox label="送优惠券" name="type" />
 | 
			
		||||
                  </el-col>
 | 
			
		||||
                </el-checkbox-group>
 | 
			
		||||
              </el-form-item>
 | 
			
		||||
            </e-form>
 | 
			
		||||
          </el-row>
 | 
			
		||||
        </template>
 | 
			
		||||
        <!-- TODO 实现:建议改成放在每一个【活动层级】的下面,有点类似主子表 -->
 | 
			
		||||
        <el-button type="primary" @click="addActivityStratum">添加活动层级</el-button>
 | 
			
		||||
        <RewardRule v-model="formData" />
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="活动商品" prop="productScope">
 | 
			
		||||
        <el-radio-group v-model="formData.productScope">
 | 
			
		||||
@@ -123,17 +51,16 @@
 | 
			
		||||
      >
 | 
			
		||||
        <el-select
 | 
			
		||||
          v-model="formData.productSpuIds"
 | 
			
		||||
          placeholder="请选择活动商品"
 | 
			
		||||
          clearable
 | 
			
		||||
          size="small"
 | 
			
		||||
          multiple
 | 
			
		||||
          filterable
 | 
			
		||||
          style="width: 400px"
 | 
			
		||||
          multiple
 | 
			
		||||
          placeholder="请选择活动商品"
 | 
			
		||||
          size="small"
 | 
			
		||||
        >
 | 
			
		||||
          <el-option v-for="item in productSpus" :key="item.id" :label="item.name" :value="item.id">
 | 
			
		||||
            <span style="float: left">{{ item.name }}</span>
 | 
			
		||||
            <span style="float: right; font-size: 13px; color: #8492a6">
 | 
			
		||||
              ¥{{ (item.price / 100.0).toFixed(2) }}
 | 
			
		||||
              ¥{{ fenToYuan(item.price) }}
 | 
			
		||||
            </span>
 | 
			
		||||
          </el-option>
 | 
			
		||||
        </el-select>
 | 
			
		||||
@@ -143,55 +70,33 @@
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
    </el-form>
 | 
			
		||||
    <template #footer>
 | 
			
		||||
      <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
 | 
			
		||||
      <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
 | 
			
		||||
      <el-button @click="dialogVisible = false">取 消</el-button>
 | 
			
		||||
    </template>
 | 
			
		||||
  </Dialog>
 | 
			
		||||
</template>
 | 
			
		||||
<script lang="ts" setup>
 | 
			
		||||
import RewardRule from './components/RewardRule.vue'
 | 
			
		||||
import { getSpuSimpleList } from '@/api/mall/product/spu'
 | 
			
		||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
 | 
			
		||||
import * as RewardActivityApi from '@/api/mall/promotion/reward/rewardActivity'
 | 
			
		||||
import { PromotionConditionTypeEnum, PromotionProductScopeEnum } from '@/utils/constants'
 | 
			
		||||
import { fenToYuan } from '@/utils'
 | 
			
		||||
 | 
			
		||||
/** 初始化 **/
 | 
			
		||||
onMounted(() => {
 | 
			
		||||
  getSpuSimpleList().then((response) => {
 | 
			
		||||
    productSpus.value = response
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
defineOptions({ name: 'ProductBrandForm' })
 | 
			
		||||
 | 
			
		||||
const { t } = useI18n() // 国际化
 | 
			
		||||
const message = useMessage() // 消息弹窗
 | 
			
		||||
 | 
			
		||||
const productSpus = ref<any[]>([]) // 商品数据
 | 
			
		||||
const dialogVisible = ref(false) // 弹窗的是否展示
 | 
			
		||||
const dialogTitle = ref('') // 弹窗的标题
 | 
			
		||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
 | 
			
		||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
 | 
			
		||||
const formData = ref({
 | 
			
		||||
  id: undefined,
 | 
			
		||||
  name: undefined,
 | 
			
		||||
  startAndEndTime: undefined,
 | 
			
		||||
  startTime: undefined,
 | 
			
		||||
  endTime: undefined,
 | 
			
		||||
const formData = ref<RewardActivityApi.RewardActivityVO>({
 | 
			
		||||
  conditionType: PromotionConditionTypeEnum.PRICE.type,
 | 
			
		||||
  remark: undefined,
 | 
			
		||||
  productScope: PromotionProductScopeEnum.ALL.scope,
 | 
			
		||||
  productSpuIds: undefined,
 | 
			
		||||
  rules: [
 | 
			
		||||
    {
 | 
			
		||||
      limit: undefined,
 | 
			
		||||
      discountPrice: undefined,
 | 
			
		||||
      freeDelivery: undefined,
 | 
			
		||||
      point: undefined,
 | 
			
		||||
      couponIds: [],
 | 
			
		||||
      couponCounts: []
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
})
 | 
			
		||||
const activityRules = reactive([]) // 优惠设置。每个元素都是一个 [],放“包邮”、“送积分”、“订单金额优惠”
 | 
			
		||||
  rules: []
 | 
			
		||||
} as RewardActivityApi.RewardActivityVO)
 | 
			
		||||
const formRules = reactive({
 | 
			
		||||
  name: [{ required: true, message: '活动名称不能为空', trigger: 'blur' }],
 | 
			
		||||
  startAndEndTime: [{ required: true, message: '活动时间不能为空', trigger: 'blur' }],
 | 
			
		||||
@@ -211,23 +116,8 @@ const open = async (type: string, id?: number) => {
 | 
			
		||||
  if (id) {
 | 
			
		||||
    formLoading.value = true
 | 
			
		||||
    try {
 | 
			
		||||
      let data = await RewardActivityApi.getReward(id)
 | 
			
		||||
      data.startAndEndTime = [new Date(data.startTime), new Date(data.endTime)]
 | 
			
		||||
      activityRules.splice(0, activityRules.length)
 | 
			
		||||
      data.rules.forEach((item) => {
 | 
			
		||||
        // TODO 是不是不用 reactive,直接 [] 就可以了?
 | 
			
		||||
        let array: string[] = reactive([])
 | 
			
		||||
        if (item.freeDelivery) {
 | 
			
		||||
          array.push('包邮')
 | 
			
		||||
        }
 | 
			
		||||
        if (item.point) {
 | 
			
		||||
          array.push('送积分')
 | 
			
		||||
        }
 | 
			
		||||
        if (item.discountPrice) {
 | 
			
		||||
          array.push('订单金额优惠')
 | 
			
		||||
        }
 | 
			
		||||
        activityRules.push(array)
 | 
			
		||||
      })
 | 
			
		||||
      const data = await RewardActivityApi.getReward(id)
 | 
			
		||||
      data.startAndEndTime = [data.startTime, data.endTime]
 | 
			
		||||
      formData.value = data
 | 
			
		||||
    } finally {
 | 
			
		||||
      formLoading.value = false
 | 
			
		||||
@@ -241,25 +131,15 @@ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成
 | 
			
		||||
const submitForm = async () => {
 | 
			
		||||
  // 校验表单
 | 
			
		||||
  if (!formRef) return
 | 
			
		||||
  const valid = await formRef.value.validate()
 | 
			
		||||
  if (!valid) return
 | 
			
		||||
  // 处理下数据兼容接口
 | 
			
		||||
  formData.value.startTime = +new Date(formData.value.startAndEndTime[0])
 | 
			
		||||
  formData.value.endTime = +new Date(formData.value.startAndEndTime[1])
 | 
			
		||||
  activityRules.forEach((item, index) => {
 | 
			
		||||
    formData.value.rules[index].freeDelivery = !!item.includes('包邮')
 | 
			
		||||
    if (!item.includes('送积分')) {
 | 
			
		||||
      formData.value.rules[index].point = undefined
 | 
			
		||||
    }
 | 
			
		||||
    if (!item.includes('订单金额优惠')) {
 | 
			
		||||
      formData.value.rules[index].discountPrice = undefined
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
  // TODO puhui999: 规则校验
 | 
			
		||||
  // const valid = await formRef.value.validate()
 | 
			
		||||
  // if (!valid) return
 | 
			
		||||
  // TODO puhui999: 处理下数据兼容接口
 | 
			
		||||
 | 
			
		||||
  // 提交请求
 | 
			
		||||
  formLoading.value = true
 | 
			
		||||
  try {
 | 
			
		||||
    const data = formData.value as RewardActivityApi.DiscountActivityVO
 | 
			
		||||
    const data = formData.value
 | 
			
		||||
    if (formType.value === 'create') {
 | 
			
		||||
      await RewardActivityApi.createRewardActivity(data)
 | 
			
		||||
      message.success(t('common.createSuccess'))
 | 
			
		||||
@@ -275,51 +155,18 @@ const submitForm = async () => {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const addActivityStratum = () => {
 | 
			
		||||
  formData.value.rules.push({
 | 
			
		||||
    limit: undefined,
 | 
			
		||||
    discountPrice: undefined,
 | 
			
		||||
    freeDelivery: undefined,
 | 
			
		||||
    point: undefined,
 | 
			
		||||
    couponIds: [],
 | 
			
		||||
    couponCounts: []
 | 
			
		||||
  })
 | 
			
		||||
  activityRules.push([])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const deleteActivityRule = (index) => {
 | 
			
		||||
  formData.value.rules.splice(index, 1)
 | 
			
		||||
  activityRules.splice(index, 1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 重置表单 */
 | 
			
		||||
const resetForm = () => {
 | 
			
		||||
  formData.value = {
 | 
			
		||||
    id: undefined,
 | 
			
		||||
    name: undefined,
 | 
			
		||||
    startAndEndTime: undefined,
 | 
			
		||||
    startTime: undefined,
 | 
			
		||||
    endTime: undefined,
 | 
			
		||||
    conditionType: PromotionConditionTypeEnum.PRICE.type,
 | 
			
		||||
    remark: undefined,
 | 
			
		||||
    productScope: PromotionProductScopeEnum.ALL.scope,
 | 
			
		||||
    productSpuIds: undefined,
 | 
			
		||||
    rules: [
 | 
			
		||||
      {
 | 
			
		||||
        limit: undefined,
 | 
			
		||||
        discountPrice: undefined,
 | 
			
		||||
        freeDelivery: undefined,
 | 
			
		||||
        point: undefined,
 | 
			
		||||
        couponIds: [],
 | 
			
		||||
        couponCounts: []
 | 
			
		||||
      }
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
  activityRules.splice(0, activityRules.length)
 | 
			
		||||
  activityRules.push(reactive([]))
 | 
			
		||||
  // 解决下有时刷新页面第一次点编辑报错
 | 
			
		||||
  nextTick(() => {
 | 
			
		||||
    formRef.value?.resetFields()
 | 
			
		||||
  })
 | 
			
		||||
    rules: []
 | 
			
		||||
  } as RewardActivityApi.RewardActivityVO
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 初始化 **/
 | 
			
		||||
const productSpus = ref<any[]>([]) // 商品数据
 | 
			
		||||
onMounted(async () => {
 | 
			
		||||
  productSpus.value = await getSpuSimpleList()
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,125 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <!-- 满减送活动规则组件 -->
 | 
			
		||||
  <el-row>
 | 
			
		||||
    <template v-if="formData.rules">
 | 
			
		||||
      <div v-for="(rule, index) in formData.rules" :key="index">
 | 
			
		||||
        <el-col :span="24">
 | 
			
		||||
          <span class="font-bold">活动层级{{ index + 1 }}</span>
 | 
			
		||||
          <el-button v-if="index !== 0" link type="danger" @click="deleteRule(index)">
 | 
			
		||||
            删除
 | 
			
		||||
          </el-button>
 | 
			
		||||
        </el-col>
 | 
			
		||||
        <el-form ref="formRef" :model="rule">
 | 
			
		||||
          <el-form-item label="优惠门槛:" label-width="100px" prop="limit">
 | 
			
		||||
            满
 | 
			
		||||
            <el-input
 | 
			
		||||
              v-model="rule.limit"
 | 
			
		||||
              :min="0"
 | 
			
		||||
              class="w-150px! p-x-20px!"
 | 
			
		||||
              placeholder=""
 | 
			
		||||
              type="number"
 | 
			
		||||
            />
 | 
			
		||||
            {{ PromotionConditionTypeEnum.PRICE.type === formData.conditionType ? '元' : '件' }}
 | 
			
		||||
          </el-form-item>
 | 
			
		||||
          <el-form-item label="优惠内容:" label-width="100px">
 | 
			
		||||
            <el-col :span="24">
 | 
			
		||||
              订单金额优惠
 | 
			
		||||
              <el-form-item>
 | 
			
		||||
                减
 | 
			
		||||
                <el-input
 | 
			
		||||
                  v-model="rule.discountPrice"
 | 
			
		||||
                  class="w-150px! p-x-20px!"
 | 
			
		||||
                  placeholder=""
 | 
			
		||||
                  type="number"
 | 
			
		||||
                />
 | 
			
		||||
                元
 | 
			
		||||
              </el-form-item>
 | 
			
		||||
            </el-col>
 | 
			
		||||
            <el-col :span="24">
 | 
			
		||||
              <span>包邮:</span>
 | 
			
		||||
              <el-switch
 | 
			
		||||
                v-model="rule.freeDelivery"
 | 
			
		||||
                active-text="是"
 | 
			
		||||
                inactive-text="否"
 | 
			
		||||
                inline-prompt
 | 
			
		||||
              />
 | 
			
		||||
            </el-col>
 | 
			
		||||
            <el-col :span="24">
 | 
			
		||||
              <span>送积分:</span>
 | 
			
		||||
              <el-switch
 | 
			
		||||
                v-model="rule.givePoint"
 | 
			
		||||
                active-text="是"
 | 
			
		||||
                inactive-text="否"
 | 
			
		||||
                inline-prompt
 | 
			
		||||
              />
 | 
			
		||||
              <el-form-item v-if="rule.givePoint">
 | 
			
		||||
                送
 | 
			
		||||
                <el-input
 | 
			
		||||
                  v-model="rule.point"
 | 
			
		||||
                  class="w-150px! p-x-20px!"
 | 
			
		||||
                  placeholder=""
 | 
			
		||||
                  type="number"
 | 
			
		||||
                />
 | 
			
		||||
                积分
 | 
			
		||||
              </el-form-item>
 | 
			
		||||
            </el-col>
 | 
			
		||||
            <!-- 优惠券待处理  也可以参考优惠劵的SpuShowcase-->
 | 
			
		||||
            <!-- TODO 待实现!-->
 | 
			
		||||
            <el-col :span="24">
 | 
			
		||||
              <span>送优惠券:</span>
 | 
			
		||||
              <el-switch
 | 
			
		||||
                v-model="rule.giveCoupon"
 | 
			
		||||
                active-text="是"
 | 
			
		||||
                inactive-text="否"
 | 
			
		||||
                inline-prompt
 | 
			
		||||
              />
 | 
			
		||||
            </el-col>
 | 
			
		||||
          </el-form-item>
 | 
			
		||||
        </el-form>
 | 
			
		||||
      </div>
 | 
			
		||||
    </template>
 | 
			
		||||
    <el-col :span="24">
 | 
			
		||||
      <el-button type="primary" @click="addRule">添加优惠规则</el-button>
 | 
			
		||||
    </el-col>
 | 
			
		||||
  </el-row>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script lang="ts" setup>
 | 
			
		||||
import { RewardActivityVO } from '@/api/mall/promotion/reward/rewardActivity'
 | 
			
		||||
import { PromotionConditionTypeEnum } from '@/utils/constants'
 | 
			
		||||
import { useVModel } from '@vueuse/core'
 | 
			
		||||
 | 
			
		||||
defineOptions({ name: 'RewardRule' })
 | 
			
		||||
 | 
			
		||||
const props = defineProps<{
 | 
			
		||||
  modelValue: RewardActivityVO
 | 
			
		||||
}>()
 | 
			
		||||
 | 
			
		||||
const emits = defineEmits<{
 | 
			
		||||
  (e: 'update:modelValue', v: any): void
 | 
			
		||||
  (e: 'deleteRule', v: number): void
 | 
			
		||||
}>()
 | 
			
		||||
 | 
			
		||||
const formData = useVModel(props, 'modelValue', emits) // 活动数据
 | 
			
		||||
 | 
			
		||||
/** 删除优惠规则 */
 | 
			
		||||
const deleteRule = (ruleIndex: number) => {
 | 
			
		||||
  formData.value.rules.splice(ruleIndex, 1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 添加优惠规则 */
 | 
			
		||||
const addRule = () => {
 | 
			
		||||
  formData.value.rules.push({
 | 
			
		||||
    limit: 0,
 | 
			
		||||
    discountPrice: 0,
 | 
			
		||||
    freeDelivery: false,
 | 
			
		||||
    givePoint: false,
 | 
			
		||||
    point: 0,
 | 
			
		||||
    giveCoupon: false,
 | 
			
		||||
    couponIds: [],
 | 
			
		||||
    couponCounts: []
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="scss" scoped></style>
 | 
			
		||||
@@ -4,27 +4,27 @@
 | 
			
		||||
  <!-- 搜索工作栏 -->
 | 
			
		||||
  <ContentWrap>
 | 
			
		||||
    <el-form
 | 
			
		||||
      class="-mb-15px"
 | 
			
		||||
      :model="queryParams"
 | 
			
		||||
      ref="queryFormRef"
 | 
			
		||||
      :inline="true"
 | 
			
		||||
      :model="queryParams"
 | 
			
		||||
      class="-mb-15px"
 | 
			
		||||
      label-width="68px"
 | 
			
		||||
    >
 | 
			
		||||
      <el-form-item label="活动名称" prop="name">
 | 
			
		||||
        <el-input
 | 
			
		||||
          v-model="queryParams.name"
 | 
			
		||||
          placeholder="请输入活动名称"
 | 
			
		||||
          clearable
 | 
			
		||||
          @keyup.enter="handleQuery"
 | 
			
		||||
          class="!w-240px"
 | 
			
		||||
          clearable
 | 
			
		||||
          placeholder="请输入活动名称"
 | 
			
		||||
          @keyup.enter="handleQuery"
 | 
			
		||||
        />
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="活动状态" prop="status">
 | 
			
		||||
        <el-select
 | 
			
		||||
          v-model="queryParams.status"
 | 
			
		||||
          placeholder="请选择活动状态"
 | 
			
		||||
          clearable
 | 
			
		||||
          class="!w-240px"
 | 
			
		||||
          clearable
 | 
			
		||||
          placeholder="请选择活动状态"
 | 
			
		||||
        >
 | 
			
		||||
          <el-option
 | 
			
		||||
            v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_ACTIVITY_STATUS)"
 | 
			
		||||
@@ -37,24 +37,31 @@
 | 
			
		||||
      <el-form-item label="活动时间" prop="createTime">
 | 
			
		||||
        <el-date-picker
 | 
			
		||||
          v-model="queryParams.createTime"
 | 
			
		||||
          value-format="YYYY-MM-DD HH:mm:ss"
 | 
			
		||||
          type="daterange"
 | 
			
		||||
          start-placeholder="活动开始日期"
 | 
			
		||||
          end-placeholder="活动结束日期"
 | 
			
		||||
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
 | 
			
		||||
          class="!w-240px"
 | 
			
		||||
          end-placeholder="活动结束日期"
 | 
			
		||||
          start-placeholder="活动开始日期"
 | 
			
		||||
          type="daterange"
 | 
			
		||||
          value-format="YYYY-MM-DD HH:mm:ss"
 | 
			
		||||
        />
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item>
 | 
			
		||||
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
 | 
			
		||||
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
 | 
			
		||||
        <el-button @click="handleQuery">
 | 
			
		||||
          <Icon class="mr-5px" icon="ep:search" />
 | 
			
		||||
          搜索
 | 
			
		||||
        </el-button>
 | 
			
		||||
        <el-button @click="resetQuery">
 | 
			
		||||
          <Icon class="mr-5px" icon="ep:refresh" />
 | 
			
		||||
          重置
 | 
			
		||||
        </el-button>
 | 
			
		||||
        <el-button
 | 
			
		||||
          type="primary"
 | 
			
		||||
          plain
 | 
			
		||||
          @click="openForm('create')"
 | 
			
		||||
          v-hasPermi="['product:brand:create']"
 | 
			
		||||
          plain
 | 
			
		||||
          type="primary"
 | 
			
		||||
          @click="openForm('create')"
 | 
			
		||||
        >
 | 
			
		||||
          <Icon icon="ep:plus" class="mr-5px" /> 新增
 | 
			
		||||
          <Icon class="mr-5px" icon="ep:plus" />
 | 
			
		||||
          新增
 | 
			
		||||
        </el-button>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
    </el-form>
 | 
			
		||||
@@ -62,47 +69,47 @@
 | 
			
		||||
 | 
			
		||||
  <!-- 列表 -->
 | 
			
		||||
  <ContentWrap>
 | 
			
		||||
    <el-table v-loading="loading" :data="list" row-key="id" default-expand-all>
 | 
			
		||||
    <el-table v-loading="loading" :data="list" default-expand-all row-key="id">
 | 
			
		||||
      <el-table-column label="活动名称" prop="name" />
 | 
			
		||||
      <el-table-column
 | 
			
		||||
        label="活动开始时间"
 | 
			
		||||
        align="center"
 | 
			
		||||
        prop="startTime"
 | 
			
		||||
        :formatter="dateFormatter"
 | 
			
		||||
        align="center"
 | 
			
		||||
        label="活动开始时间"
 | 
			
		||||
        prop="startTime"
 | 
			
		||||
      />
 | 
			
		||||
      <el-table-column
 | 
			
		||||
        label="活动结束时间"
 | 
			
		||||
        align="center"
 | 
			
		||||
        prop="endTime"
 | 
			
		||||
        :formatter="dateFormatter"
 | 
			
		||||
        align="center"
 | 
			
		||||
        label="活动结束时间"
 | 
			
		||||
        prop="endTime"
 | 
			
		||||
      />
 | 
			
		||||
      <el-table-column label="状态" align="center" prop="status">
 | 
			
		||||
      <el-table-column align="center" label="状态" prop="status">
 | 
			
		||||
        <template #default="scope">
 | 
			
		||||
          <dict-tag :type="DICT_TYPE.PROMOTION_ACTIVITY_STATUS" :value="scope.row.status" />
 | 
			
		||||
        </template>
 | 
			
		||||
      </el-table-column>
 | 
			
		||||
      <el-table-column
 | 
			
		||||
        label="创建时间"
 | 
			
		||||
        :formatter="dateFormatter"
 | 
			
		||||
        align="center"
 | 
			
		||||
        label="创建时间"
 | 
			
		||||
        prop="createTime"
 | 
			
		||||
        width="180"
 | 
			
		||||
        :formatter="dateFormatter"
 | 
			
		||||
      />
 | 
			
		||||
      <el-table-column label="操作" align="center">
 | 
			
		||||
      <el-table-column align="center" label="操作">
 | 
			
		||||
        <template #default="scope">
 | 
			
		||||
          <el-button
 | 
			
		||||
            v-hasPermi="['product:brand:update']"
 | 
			
		||||
            link
 | 
			
		||||
            type="primary"
 | 
			
		||||
            @click="openForm('update', scope.row.id)"
 | 
			
		||||
            v-hasPermi="['product:brand:update']"
 | 
			
		||||
          >
 | 
			
		||||
            编辑
 | 
			
		||||
          </el-button>
 | 
			
		||||
          <el-button
 | 
			
		||||
            v-hasPermi="['product:brand:delete']"
 | 
			
		||||
            link
 | 
			
		||||
            type="danger"
 | 
			
		||||
            @click="handleDelete(scope.row.id)"
 | 
			
		||||
            v-hasPermi="['product:brand:delete']"
 | 
			
		||||
          >
 | 
			
		||||
            删除
 | 
			
		||||
          </el-button>
 | 
			
		||||
@@ -111,9 +118,9 @@
 | 
			
		||||
    </el-table>
 | 
			
		||||
    <!-- 分页 -->
 | 
			
		||||
    <Pagination
 | 
			
		||||
      :total="total"
 | 
			
		||||
      v-model:page="queryParams.pageNo"
 | 
			
		||||
      v-model:limit="queryParams.pageSize"
 | 
			
		||||
      v-model:page="queryParams.pageNo"
 | 
			
		||||
      :total="total"
 | 
			
		||||
      @pagination="getList"
 | 
			
		||||
    />
 | 
			
		||||
  </ContentWrap>
 | 
			
		||||
@@ -168,9 +175,9 @@ const resetQuery = () => {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 添加/修改操作 */
 | 
			
		||||
const formRef = ref()
 | 
			
		||||
const formRef = ref<InstanceType<typeof RewardForm>>()
 | 
			
		||||
const openForm = (type: string, id?: number) => {
 | 
			
		||||
  formRef.value.open(type, id)
 | 
			
		||||
  formRef.value?.open(type, id)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 删除按钮操作 */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user