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
<script setup lang="ts">
import type { CouponCardProperty } from './config';
 
import type { MallCouponTemplateApi } from '#/api/mall/promotion/coupon/couponTemplate';
 
import { ref, watch } from 'vue';
 
import { useVbenModal } from '..\..\..\..\..\..\..\..\packages\effects\common-ui\src';
import {
  CouponTemplateTakeTypeEnum,
  PromotionDiscountTypeEnum,
} from '..\..\..\..\..\..\..\..\packages\constants\src';
import { IconifyIcon } from '..\..\..\..\..\..\..\..\packages\icons\src';
import { floatToFixed2 } from '..\..\..\..\..\..\..\..\packages\utils\src';
 
import { useVModel } from '@vueuse/core';
import {
  Button,
  Form,
  FormItem,
  RadioButton,
  RadioGroup,
  Slider,
  Tooltip,
  Typography,
} from 'ant-design-vue';
 
import { getCouponTemplateList } from '#/api/mall/promotion/coupon/couponTemplate';
import UploadImg from '#/components/upload/image-upload.vue';
import { ColorInput } from '#/views/mall/promotion/components';
import CouponSelect from '#/views/mall/promotion/coupon/components/select.vue';
 
import ComponentContainerProperty from '../../component-container-property.vue';
 
/** 优惠券卡片属性面板 */
defineOptions({ name: 'CouponCardProperty' });
 
const props = defineProps<{ modelValue: CouponCardProperty }>();
 
const emit = defineEmits(['update:modelValue']);
 
const formData = useVModel(props, 'modelValue', emit);
 
const couponList = ref<MallCouponTemplateApi.CouponTemplate[]>([]); // 已选择的优惠券列表
 
const [CouponSelectModal, couponSelectModalApi] = useVbenModal({
  connectedComponent: CouponSelect,
  destroyOnClose: true,
});
 
/** 添加优惠劵 */
const handleAddCoupon = () => {
  couponSelectModalApi.open();
};
 
/** 处理优惠劵选择 */
const handleCouponSelect = (
  selectedCoupons: MallCouponTemplateApi.CouponTemplate[],
) => {
  couponList.value = selectedCoupons;
  formData.value.couponIds = selectedCoupons.map((coupon) => coupon.id);
};
 
/** 监听优惠券 ID 变化,加载优惠券列表 */
watch(
  () => formData.value.couponIds,
  async () => {
    if (formData.value.couponIds?.length > 0) {
      couponList.value = await getCouponTemplateList(formData.value.couponIds);
    }
  },
  {
    immediate: true,
    deep: true,
  },
);
</script>
 
<template>
  <ComponentContainerProperty v-model="formData.style">
    <Form :model="formData">
      <p class="text-base font-bold">优惠券列表:</p>
      <div class="flex flex-col gap-2 rounded-md p-4 shadow-lg">
        <div
          v-for="(coupon, index) in couponList"
          :key="index"
          class="flex items-center justify-between"
        >
          <Typography>
            <Typography.Title :level="5">
              {{ coupon.name }}
            </Typography.Title>
            <Typography.Text type="secondary">
              <span v-if="coupon.usePrice > 0">
                满{{ floatToFixed2(coupon.usePrice) }}元,
              </span>
              <span
                v-if="
                  coupon.discountType === PromotionDiscountTypeEnum.PRICE.type
                "
              >
                减{{ floatToFixed2(coupon.discountPrice) }}元
              </span>
              <span v-else> 打{{ coupon.discountPercent }}折 </span>
            </Typography.Text>
          </Typography>
        </div>
        <FormItem>
          <Button
            @click="handleAddCoupon"
            type="primary"
            ghost
            class="mt-2 w-full"
          >
            <IconifyIcon icon="lucide:plus" />
            添加
          </Button>
        </FormItem>
      </div>
      <p class="text-base font-bold">优惠券样式:</p>
      <div class="flex flex-col gap-2 rounded-md p-4 shadow-lg">
        <FormItem label="列数" name="type">
          <RadioGroup v-model:value="formData.columns">
            <Tooltip title="一列" placement="bottom">
              <RadioButton :value="1">
                <IconifyIcon
                  icon="fluent:text-column-one-24-filled"
                  class="inset-0 size-6 items-center"
                />
              </RadioButton>
            </Tooltip>
            <Tooltip title="二列" placement="bottom">
              <RadioButton :value="2">
                <IconifyIcon
                  icon="fluent:text-column-two-24-filled"
                  class="size-6"
                />
              </RadioButton>
            </Tooltip>
            <Tooltip title="三列" placement="bottom">
              <RadioButton :value="3">
                <IconifyIcon
                  icon="fluent:text-column-three-24-filled"
                  class="size-6"
                />
              </RadioButton>
            </Tooltip>
          </RadioGroup>
        </FormItem>
        <FormItem label="背景图片" name="bgImg">
          <UploadImg
            v-model="formData.bgImg"
            height="80px"
            width="100%"
            class="min-w-[160px]"
            :show-description="false"
          />
        </FormItem>
        <FormItem label="文字颜色" name="textColor">
          <ColorInput v-model="formData.textColor" />
        </FormItem>
        <FormItem label="按钮背景" name="button.bgColor">
          <ColorInput v-model="formData.button.bgColor" />
        </FormItem>
        <FormItem label="按钮文字" name="button.color">
          <ColorInput v-model="formData.button.color" />
        </FormItem>
        <FormItem label="间隔" name="space">
          <Slider v-model:value="formData.space" :max="100" :min="0" />
        </FormItem>
      </div>
    </Form>
  </ComponentContainerProperty>
 
  <!-- 优惠券选择 -->
  <CouponSelectModal
    :take-type="CouponTemplateTakeTypeEnum.USER.type"
    @success="handleCouponSelect"
  />
</template>