gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<script lang="ts" setup>
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
 
import { computed } from 'vue';
 
import { PromotionConditionTypeEnum } from '..\..\..\..\..\packages\constants\src';
 
import { useVModel } from '@vueuse/core';
import {
  Button,
  Card,
  Col,
  Form,
  FormItem,
  Input,
  InputNumber,
  Row,
  Switch,
  Tag,
} from 'ant-design-vue';
 
import RewardRuleCouponSelect from './reward-rule-coupon-select.vue';
 
defineOptions({ name: 'RewardRule' });
 
const props = defineProps<{
  modelValue: Partial<MallRewardActivityApi.RewardActivity>;
}>();
 
const emits = defineEmits<{
  (e: 'update:modelValue', v: any): void;
}>();
 
const formData = useVModel(props, 'modelValue', emits);
 
const isPriceCondition = computed(() => {
  return (
    formData.value?.conditionType === PromotionConditionTypeEnum.PRICE.type
  );
});
 
/** 处理新增 */
function handleAdd() {
  if (!formData.value.rules) {
    formData.value.rules = [];
  }
  formData.value.rules.push({
    limit: 0,
    discountPrice: 0,
    freeDelivery: false,
    point: 0,
  });
}
 
/** 处理删除 */
function handleDelete(ruleIndex: number) {
  formData.value.rules?.splice(ruleIndex, 1);
}
</script>
 
<template>
  <Row :gutter="[16, 16]">
    <template v-if="formData.rules">
      <Col v-for="(rule, index) in formData.rules" :key="index" :span="24">
        <Card size="small" class="rounded-lg">
          <!-- 规则标题 -->
          <template #title>
            <div class="flex items-center">
              <span class="text-base font-medium">
                活动层级 {{ index + 1 }}
              </span>
            </div>
          </template>
          <template v-if="index !== 0" #extra>
            <Button
              type="link"
              danger
              size="small"
              @click="handleDelete(index)"
            >
              删除
            </Button>
          </template>
 
          <Form :model="rule" layout="horizontal">
            <!-- 优惠门槛 -->
            <FormItem label="优惠门槛:" :colon="false" class="mb-3">
              <div
                class="flex items-center gap-2 rounded-md bg-gray-50 px-3 py-2"
              >
                <span>满</span>
                <InputNumber
                  v-if="isPriceCondition"
                  v-model:value="rule.limit"
                  :min="0"
                  :precision="2"
                  :step="0.1"
                  class="!w-40"
                  placeholder="请输入金额"
                />
                <Input
                  v-else
                  v-model:value="rule.limit"
                  :min="0"
                  class="!w-40"
                  placeholder="请输入数量"
                  type="number"
                />
                <span>{{ isPriceCondition ? '元' : '件' }}</span>
              </div>
            </FormItem>
            <!-- 优惠内容 -->
            <FormItem label="优惠内容:" :colon="false" class="!mb-0">
              <div class="flex flex-col gap-3">
                <!-- 订单金额优惠 -->
                <div
                  class="flex items-center gap-2 rounded-md bg-gray-50 px-3 py-2"
                >
                  <span class="!w-21 shrink-0 text-sm text-gray-500">
                    订单金额优惠
                  </span>
                  <span>减</span>
                  <InputNumber
                    v-model:value="rule.discountPrice"
                    :min="0"
                    :precision="2"
                    :step="0.1"
                    class="!w-32"
                    placeholder="请输入金额"
                  />
                  <span>元</span>
                </div>
                <!-- 包邮 -->
                <div
                  class="flex items-center gap-2 rounded-md bg-gray-50 px-3 py-2"
                >
                  <span class="w-20 shrink-0 text-sm text-gray-500">包邮</span>
                  <Switch
                    v-model:checked="rule.freeDelivery"
                    checked-children="是"
                    un-checked-children="否"
                  />
                </div>
                <!-- 送积分 -->
                <div
                  class="flex items-center gap-2 rounded-md bg-gray-50 px-3 py-2"
                >
                  <span class="w-20 shrink-0 text-sm text-gray-500">
                    送积分
                  </span>
                  <span>送</span>
                  <InputNumber
                    v-model:value="rule.point"
                    :min="0"
                    class="!w-32"
                    placeholder="请输入积分"
                  />
                  <span>积分</span>
                </div>
                <!-- 送优惠券 -->
                <div
                  class="flex flex-col items-start gap-2 rounded-md bg-gray-50 px-3 py-2"
                >
                  <span class="w-20 shrink-0 text-sm text-gray-500">
                    送优惠券
                  </span>
                  <RewardRuleCouponSelect
                    :model-value="rule"
                    @update:model-value="
                      (val) => (formData.rules![index] = val)
                    "
                  />
                </div>
              </div>
            </FormItem>
          </Form>
        </Card>
      </Col>
    </template>
 
    <!-- 添加规则按钮 -->
    <Col :span="24" class="mt-2">
      <Button type="primary" @click="handleAdd">+ 添加优惠规则</Button>
    </Col>
 
    <!-- 提示信息 -->
    <Col :span="24" class="mt-2">
      <Tag color="warning">
        提示:赠送积分为 0 时不赠送;未选择优惠券时不赠送。
      </Tag>
    </Col>
  </Row>
</template>