RewardRule.vue 3.9 KB

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