Blame view

src/pages/coupon/CouponConfig/components/FullReduce.tsx 9.57 KB
a0630c77   赵凤   活动流程保存
1
  import React, { useState, useEffect } from "react";
e1c34910   莫红玲   优惠券别名配置示例
2
  import { Form, Input, InputNumber, Select, Divider, Radio, Row, Image, Modal, Button } from "antd";
a0630c77   赵凤   活动流程保存
3
4
5
6
7
8
  import { formItemLayout } from "../entity";
  import { FormInstance } from "antd/lib/form";
  import * as api from "../api";
  import WareLimitType from "./WareLimitType";
  import ShopLimit from "./ShopLimit";
  import useInitail from "@/hooks/useInitail";
032c0c6d   莫红玲   兑换券类型选择 展示字符方式
9
  import { PaymentTypeEnum } from '@/pages/coupon/CashChange/api';
e1c34910   莫红玲   优惠券别名配置示例
10
  import { RightOutlined } from '@ant-design/icons';
77d91ab9   莫红玲   实物兑换券整合办公用品模块“市场物...
11
  import RenderSelectGoos from '@/pages/capital/ReceiveRules/subPages/GoodsDimension/components/RenderSelectGoos';
0295a53a   莫红玲   优惠券基本信息form
12
  
0295a53a   莫红玲   优惠券基本信息form
13
  const Option = Select.Option;
0295a53a   莫红玲   优惠券基本信息form
14
  interface Props {
33c04117   莫红玲   优惠券接口联调
15
16
17
18
    // brandId: number,
    info: MktConponSpace.ConListParams;
    form: FormInstance;
    readonly: boolean;
a0630c77   赵凤   活动流程保存
19
    getCouponType?: Function;
627b689d   赵凤   无奖占位
20
    confNo?: string;
999737f1   莫红玲   车辆优惠券自定义- 活动授权品牌车系车型
21
22
    limitCoupon?: string[]; // 优惠券类型限制
    carSelectApi?: Function
22aa629c   莫红玲   评价有礼配置
23
    expires?: boolean;
7a7deed4   莫红玲   活动优惠券支持变更,接口联调
24
    changeEditKeys?: string[];
0295a53a   莫红玲   优惠券基本信息form
25
26
  }
  
627b689d   赵凤   无奖占位
27
28
29
30
31
32
  export default function FullReduce({
    info,
    readonly,
    form,
    getCouponType,
    confNo,
999737f1   莫红玲   车辆优惠券自定义- 活动授权品牌车系车型
33
    limitCoupon,
22aa629c   莫红玲   评价有礼配置
34
    carSelectApi,
7a7deed4   莫红玲   活动优惠券支持变更,接口联调
35
36
    expires,
    changeEditKeys,
627b689d   赵凤   无奖占位
37
38
  }: Props) {
    const [classifyInfo, setClassifyInfo] = useState({ code: "" });
5cd03352   莫红玲   优惠券场景限制
39
    const { data: ClassifyList } = useInitail(api.fetchClassifyList, [], {});
0eb298e6   莫红玲   优惠券配置,add选择兑换券类型
40
    const { data: cashChangeTypes } = useInitail(api.fetchExchangeList, [], {});
e1c34910   莫红玲   优惠券别名配置示例
41
    const [visible, setVisible] = useState(false);
0295a53a   莫红玲   优惠券基本信息form
42
  
6d69f557   莫红玲   优惠券作业项回显
43
44
    useEffect(() => {
      setClassifyInfo({ code: info.classifyCode });
627b689d   赵凤   无奖占位
45
46
47
48
49
50
      const currentItem = ClassifyList.filter(
        (i) => i.code === info.classifyCode
      );
      if (currentItem.length) {
        getCouponType && getCouponType(currentItem[0].type);
      }
6d69f557   莫红玲   优惠券作业项回显
51
52
    }, [info.classifyCode]);
  
5cd03352   莫红玲   优惠券场景限制
53
    function changeScene(v: any) {
627b689d   赵凤   无奖占位
54
55
56
      const currentItems = ClassifyList.filter((i) => i.code === v.value)[0];
      form.setFieldsValue({
        aliasName: currentItems.type == 1 ? currentItems.name : undefined,
8500dd4f   莫红玲   优惠券分期校验
57
        settlementType: 1,
66bd5f77   莫红玲   现金兑换券调整
58
        settlementCalType: v.value === "xjdhq" ? 1 : undefined,
627b689d   赵凤   无奖占位
59
      });
a412fc45   莫红玲   优惠券编辑bug修改
60
61
      getCouponType && getCouponType(currentItems.type);
      setClassifyInfo({ code: v.value });
1ea7601c   莫红玲   add购车方式
62
      let limitItem = currentItems.schemes
627b689d   赵凤   无奖占位
63
        .split(",")
affa8e1e   莫红玲   车辆条件限制bugfix
64
65
66
67
68
69
70
        .map((i: string) => {
          if (i === "1") {
            return ({
              externalRely: true,
              limitScheme: true,
              schemeType: i
            });
1ea7601c   莫红玲   add购车方式
71
          } else { return ({ schemeType: i, limitScheme: false }); }
affa8e1e   莫红玲   车辆条件限制bugfix
72
        });
1ea7601c   莫红玲   add购车方式
73
74
75
76
77
      if (currentItems.schemes.split(",").includes('7')) {
        const item = limitItem[1];
        limitItem[1] = limitItem[2];
        limitItem[2] = item;
      }
62167325   莫红玲   兑换券条件限制优化
78
79
      // form.setFieldsValue({ schemeList: currentItems.schemes !== "0" ? limitItem : [] });
      form.setFieldsValue({ schemeList: limitItem });
0295a53a   莫红玲   优惠券基本信息form
80
81
    }
  
c3d41664   舒述军   买车即送优惠券调整
82
83
84
85
86
87
    // 优惠券类型限制
    function screenCouponType() {
      const list = limitCoupon && limitCoupon.length ? ClassifyList.filter(v => limitCoupon.includes(v.code)) : ClassifyList;
      return list || [];
    }
  
0295a53a   莫红玲   优惠券基本信息form
88
89
    return (
      <div>
627b689d   赵凤   无奖占位
90
        <Form form={form} {...formItemLayout}>
a1d3c474   赵凤   新增发券参数限制类型参数
91
92
93
94
95
96
97
98
          <Form.Item
            label="优惠券类型"
            name="classifyCode"
            rules={[{ required: true, message: "请选择优惠券类型" }]}
          >
            <Select
              optionFilterProp="children"
              showSearch
e25af5e3   赵凤   活动流程本地删除优惠券
99
              disabled={readonly || !!confNo}
a1d3c474   赵凤   新增发券参数限制类型参数
100
101
102
103
104
              labelInValue
              placeholder="请选择优惠券类型"
              style={{ width: "100%" }}
              onChange={(value, option) => changeScene(option)}
            >
c3d41664   舒述军   买车即送优惠券调整
105
              {screenCouponType().map((item) => (
a412fc45   莫红玲   优惠券编辑bug修改
106
                <Option key={item.code} value={item.code}>
a0630c77   赵凤   活动流程保存
107
108
109
                  {item.name}
                </Option>
              ))}
0295a53a   莫红玲   优惠券基本信息form
110
111
            </Select>
          </Form.Item>
0eb298e6   莫红玲   优惠券配置,add选择兑换券类型
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
          {classifyInfo.code === "xjdhq" && (
            <Form.Item
              label="现金兑换券类型"
              name="exchangeTypeId"
              rules={[{ required: true, message: "请选择优惠券类型" }]}
            >
              <Select
                optionFilterProp="children"
                showSearch
                disabled={readonly || !!confNo}
                labelInValue
                placeholder="请选择兑换券类型"
                style={{ width: "100%" }}
              >
                {cashChangeTypes.map((item) => (
                  <Option key={item.id} value={item.id}>
032c0c6d   莫红玲   兑换券类型选择 展示字符方式
128
                    {`${item.name} [${PaymentTypeEnum[item.paymentType]}]`}
0eb298e6   莫红玲   优惠券配置,add选择兑换券类型
129
130
131
132
133
                  </Option>
                ))}
              </Select>
            </Form.Item>
          )}
a1d3c474   赵凤   新增发券参数限制类型参数
134
135
136
137
          <Form.Item
            label="优惠券别名"
            name="aliasName"
            rules={[{ required: true, message: "请输入优惠券名称" }]}
e1c34910   莫红玲   优惠券别名配置示例
138
139
140
            extra={
              <Row style={{ marginTop: 10 }}>
                <span style={{ color: 'red', fontSize: 12 }}>示例:至高6500元鲸喜基金;</span>
7a7deed4   莫红玲   活动优惠券支持变更,接口联调
141
                <div
e1c34910   莫红玲   优惠券别名配置示例
142
143
144
145
146
147
148
                  style={{ color: '#4189FD', fontSize: 12 }}
                  onClick={() => setVisible(true)}
                >
                  预览<RightOutlined />
                </div>
              </Row>
            }
a1d3c474   赵凤   新增发券参数限制类型参数
149
150
          >
            <Input
7a7deed4   莫红玲   活动优惠券支持变更,接口联调
151
              disabled={changeEditKeys ? !changeEditKeys.includes("aliasName") : (readonly || !!confNo)}
a1d3c474   赵凤   新增发券参数限制类型参数
152
              placeholder="请输入优惠券名称"
4867e2e5   莫红玲   优惠券别名长度限制调整
153
              maxLength={20}
a1d3c474   赵凤   新增发券参数限制类型参数
154
            />
0295a53a   莫红玲   优惠券基本信息form
155
          </Form.Item>
7a7deed4   莫红玲   活动优惠券支持变更,接口联调
156
  
22aa629c   莫红玲   评价有礼配置
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
          {!!expires && (
            <Form.Item
              label="优惠券有效期"
              name="expires"
              extra={<span style={{ fontSize: 12, color: '#999' }}>固定天数为0的时候,即有效期为当天23:59:59</span>}
              rules={[{ required: true, message: "请输入优惠券固定天数有效期时间" }]}
            >
              <InputNumber
                disabled={readonly || !!confNo}
                style={{ width: "100%" }}
                placeholder="请输入"
                addonAfter="天"
                precision={0}
                min={0}
              />
            </Form.Item>
          )}
77d91ab9   莫红玲   实物兑换券整合办公用品模块“市场物...
174
175
176
177
178
179
          {/* 实物兑换券选择兑换物品 */}
          {classifyInfo.code === "dhyhq" && (
            <Form.Item label="兑换物品" name="amsCode" extra={<span style={{ fontSize: 12 }}>*兑换物品仅限一个</span>} rules={[{ required: true, message: '请选择' }]}>
              <RenderSelectGoos multiple={false} disabled={readonly} />
            </Form.Item>
          )}
a1d3c474   赵凤   新增发券参数限制类型参数
180
181
182
183
184
185
          <Form.Item
            label="优惠券券面金额"
            name="amount"
            rules={[{ required: true, message: "请输入优惠券销售价格" }]}
          >
            <InputNumber
e25af5e3   赵凤   活动流程本地删除优惠券
186
              disabled={readonly || !!confNo}
a1d3c474   赵凤   新增发券参数限制类型参数
187
188
189
              style={{ width: "100%" }}
              placeholder="请输入"
            />
0295a53a   莫红玲   优惠券基本信息form
190
          </Form.Item>
a1d3c474   赵凤   新增发券参数限制类型参数
191
192
193
194
195
          <Form.Item
            label="结算方式"
            name="settlementType"
            rules={[{ required: true, message: "请选择结算方式" }]}
          >
0295a53a   莫红玲   优惠券基本信息form
196
            <Radio.Group disabled={readonly}>
a0630c77   赵凤   活动流程保存
197
198
199
              <Radio key={1} value={1}>
                商家结算给三方
              </Radio>
66bd5f77   莫红玲   现金兑换券调整
200
              {!["dhyhq"].includes(classifyInfo.code) && (
8500dd4f   莫红玲   优惠券分期校验
201
202
203
204
                <Radio key={2} value={2}>
                  厂家结算给商家
                </Radio>
              )}
0295a53a   莫红玲   优惠券基本信息form
205
206
207
            </Radio.Group>
          </Form.Item>
  
a1d3c474   赵凤   新增发券参数限制类型参数
208
209
210
211
212
          <Form.Item
            label="结算金额计算方式"
            name="settlementCalType"
            rules={[{ required: true, message: "请输入金额" }]}
          >
0295a53a   莫红玲   优惠券基本信息form
213
            <Radio.Group disabled={readonly}>
a0630c77   赵凤   活动流程保存
214
215
216
              <Radio key={1} value={1}>
                系数
              </Radio>
66bd5f77   莫红玲   现金兑换券调整
217
218
219
220
221
              {!["xjdhq"].includes(classifyInfo.code) && (
                <Radio key={2} value={2}>
                  金额
                </Radio>
              )}
0295a53a   莫红玲   优惠券基本信息form
222
223
            </Radio.Group>
          </Form.Item>
a1d3c474   赵凤   新增发券参数限制类型参数
224
225
          <Form.Item
            noStyle
affa8e1e   莫红玲   车辆条件限制bugfix
226
            shouldUpdate={(prevValues, currentValues) => prevValues.settlementCalType != currentValues.settlementCalType}
a1d3c474   赵凤   新增发券参数限制类型参数
227
          >
0295a53a   莫红玲   优惠券基本信息form
228
229
            {({ getFieldValue }): any => {
              const calType = getFieldValue("settlementCalType");
5cd03352   莫红玲   优惠券场景限制
230
              const max = calType == 1 ? 1 : undefined;
0295a53a   莫红玲   优惠券基本信息form
231
              return (
5cd03352   莫红玲   优惠券场景限制
232
233
234
235
                <Form.Item
                  label={calType == 1 ? "结算系数" : "结算金额(元)"}
                  name="settlementCalValue"
                  rules={[
a0630c77   赵凤   活动流程保存
236
                    { required: true, message: "请输入" },
5cd03352   莫红玲   优惠券场景限制
237
238
                    ({ getFieldValue }) => ({
                      validator(_, value) {
a0630c77   赵凤   活动流程保存
239
                        if (calType === 2 && value > getFieldValue("amount")) {
a1d3c474   赵凤   新增发券参数限制类型参数
240
241
242
                          return Promise.reject(
                            new Error("结算金额不能大于优惠券券面金额")
                          );
5cd03352   莫红玲   优惠券场景限制
243
244
245
246
247
248
                        }
                        return Promise.resolve();
                      },
                    }),
                  ]}
                >
a1d3c474   赵凤   新增发券参数限制类型参数
249
250
251
252
253
254
255
256
                  <InputNumber
                    style={{ width: "100%" }}
                    disabled={readonly}
                    placeholder="请输入"
                    min={0}
                    max={max}
                    precision={2}
                  />
0295a53a   莫红玲   优惠券基本信息form
257
258
259
260
                </Form.Item>
              );
            }}
          </Form.Item>
a1d3c474   赵凤   新增发券参数限制类型参数
261
262
263
264
265
          <ShopLimit
            form={form}
            readonly={readonly}
            formItemLayout={formItemLayout}
          />
5cd03352   莫红玲   优惠券场景限制
266
          <Divider orientation="center">场景限制条件</Divider>
a1d3c474   赵凤   新增发券参数限制类型参数
267
268
269
270
271
272
          <WareLimitType
            readonly={readonly}
            info={info}
            form={form}
            formItemLayout={formItemLayout}
            schemes={classifyInfo}
999737f1   莫红玲   车辆优惠券自定义- 活动授权品牌车系车型
273
            carSelectApi={carSelectApi}
7a7deed4   莫红玲   活动优惠券支持变更,接口联调
274
            changeEditKeys={changeEditKeys}
a1d3c474   赵凤   新增发券参数限制类型参数
275
          />
0295a53a   莫红玲   优惠券基本信息form
276
        </Form>
e1c34910   莫红玲   优惠券别名配置示例
277
278
279
280
281
282
283
284
285
286
287
        <Modal
          visible={visible}
          centered
          onCancel={() => setVisible(false)}
          footer={false}
        >
          <Image
            width={300}
            src="https://feewee-1255997270.cos.ap-chengdu.myqcloud.com/static/mkt/coupon/aliasName/example?"
          />
        </Modal>
0295a53a   莫红玲   优惠券基本信息form
288
289
290
      </div>
    );
  }