RewardRule.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <!-- 满减送活动规则组件 -->
  3. <el-row>
  4. <template v-if="formData.rules">
  5. <el-col v-for="(rule, index) in formData.rules" :key="index" :span="24">
  6. <span class="font-bold">活动层级{{ index + 1 }}</span>
  7. <el-button v-if="index !== 0" link type="danger" @click="deleteRule(index)">
  8. 删除
  9. </el-button>
  10. <el-form ref="formRef" :model="rule">
  11. <el-form-item label="优惠门槛:" label-width="100px" prop="limit">
  12. <el-input-number
  13. v-if="PromotionConditionTypeEnum.PRICE.type === formData.conditionType"
  14. v-model="rule.limit"
  15. :min="0"
  16. :precision="2"
  17. :step="0.1"
  18. class="w-150px! p-x-20px!"
  19. placeholder=""
  20. type="number"
  21. controls-position="right"
  22. />
  23. <el-input
  24. v-else
  25. v-model="rule.limit"
  26. :min="0"
  27. class="w-150px! p-x-20px!"
  28. placeholder=""
  29. type="number"
  30. />
  31. {{ PromotionConditionTypeEnum.PRICE.type === formData.conditionType ? '元' : '件' }}
  32. </el-form-item>
  33. <el-form-item label="优惠内容:" label-width="100px">
  34. <el-col :span="24">
  35. 订单金额优惠
  36. <el-form-item>
  37. <el-input-number
  38. v-model="rule.discountPrice"
  39. :min="0"
  40. :precision="2"
  41. :step="0.1"
  42. class="w-150px! p-x-20px!"
  43. controls-position="right"
  44. />
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="24">
  48. <span>包邮:</span>
  49. <el-switch
  50. v-model="rule.freeDelivery"
  51. active-text="是"
  52. inactive-text="否"
  53. inline-prompt
  54. />
  55. </el-col>
  56. <el-col :span="24">
  57. <span>送积分:</span>
  58. <el-form-item>
  59. <el-input
  60. v-model="rule.point"
  61. class="w-150px! p-x-20px!"
  62. placeholder=""
  63. type="number"
  64. />
  65. 积分
  66. </el-form-item>
  67. </el-col>
  68. <el-col :span="24">
  69. <span>送优惠券:</span>
  70. <RewardRuleCouponSelect ref="rewardRuleCouponSelectRef" v-model="rule!" />
  71. </el-col>
  72. </el-form-item>
  73. </el-form>
  74. </el-col>
  75. </template>
  76. <el-col :span="24" class="mt-10px">
  77. <el-button type="primary" @click="addRule">添加优惠规则</el-button>
  78. </el-col>
  79. <el-col :span="24">
  80. <el-tag type="warning"> 赠送积分为 0 时不赠送。未选优惠券时不赠送。</el-tag>
  81. </el-col>
  82. </el-row>
  83. </template>
  84. <script lang="ts" setup>
  85. import RewardRuleCouponSelect from './RewardRuleCouponSelect.vue'
  86. import { RewardActivityVO } from '@/api/mall/promotion/reward/rewardActivity'
  87. import { PromotionConditionTypeEnum } from '@/utils/constants'
  88. import { useVModel } from '@vueuse/core'
  89. import { isEmpty } from '@/utils/is'
  90. defineOptions({ name: 'RewardRule' })
  91. const props = defineProps<{
  92. modelValue: RewardActivityVO
  93. }>()
  94. const emits = defineEmits<{
  95. (e: 'update:modelValue', v: any): void
  96. (e: 'deleteRule', v: number): void
  97. }>()
  98. const formData = useVModel(props, 'modelValue', emits) // 活动数据
  99. const rewardRuleCouponSelectRef = ref<InstanceType<typeof RewardRuleCouponSelect>[]>() // 活动规则优惠券 Ref
  100. /** 删除优惠规则 */
  101. const deleteRule = (ruleIndex: number) => {
  102. formData.value.rules.splice(ruleIndex, 1)
  103. }
  104. /** 添加优惠规则 */
  105. const addRule = () => {
  106. if (isEmpty(formData.value.rules)) {
  107. formData.value.rules = []
  108. }
  109. formData.value.rules.push({
  110. limit: 0,
  111. discountPrice: 0,
  112. freeDelivery: false,
  113. point: 0
  114. })
  115. }
  116. /** 设置规则优惠券-提交时 */
  117. const setRuleCoupon = () => {
  118. if (isEmpty(rewardRuleCouponSelectRef.value)) {
  119. return
  120. }
  121. rewardRuleCouponSelectRef.value?.forEach((item) => item.setGiveCouponList())
  122. }
  123. defineExpose({ setRuleCoupon })
  124. </script>