Commit 976fab19 authored by XieZhiXiong's avatar XieZhiXiong

feat: 对接优惠券修改相关

parent c1c49121
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: XieZhiXiong * @Author: XieZhiXiong
* @Date: 2021-06-24 14:04:16 * @Date: 2021-06-24 14:04:16
* @LastEditors: XieZhiXiong * @LastEditors: XieZhiXiong
* @LastEditTime: 2021-07-19 17:26:55 * @LastEditTime: 2021-07-23 17:36:48
* @Description: * @Description:
*/ */
import { FormEffectHooks, FormPath, IFormActions } from '@formily/antd'; import { FormEffectHooks, FormPath, IFormActions } from '@formily/antd';
...@@ -29,6 +29,23 @@ export const useBusinessEffects = (context, actions: IFormActions) => { ...@@ -29,6 +29,23 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
const linkage = useLinkageUtils(); const linkage = useLinkageUtils();
// 优惠券类型 // 优惠券类型
onFieldInputChange$('type').subscribe(state => {
const { value } = state;
const denominationValue = getFieldValue('denomination'); // 券面额
const useConditionMoneyValue = getFieldValue('useConditionMoney'); // 使用条件
// 0元抵扣券
if (value === MERCHANT_COUPON_TYPE_VOUCHER) {
} else {
setFieldState('getWay', fieldState => {
FormPath.setIn(fieldState, 'value', undefined);
FormPath.setIn(fieldState, 'props.x-component-props.disabled', false);
});
}
});
// 优惠券类型
onFieldValueChange$('type').subscribe(state => { onFieldValueChange$('type').subscribe(state => {
const { value } = state; const { value } = state;
const denominationValue = getFieldValue('denomination'); // 券面额 const denominationValue = getFieldValue('denomination'); // 券面额
...@@ -55,11 +72,6 @@ export const useBusinessEffects = (context, actions: IFormActions) => { ...@@ -55,11 +72,6 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
}); });
} }
setFieldState('getWay', fieldState => {
FormPath.setIn(fieldState, 'value', undefined);
FormPath.setIn(fieldState, 'props.x-component-props.disabled', false);
});
// 非0元抵扣券,使用条件 必须大于 0 // 非0元抵扣券,使用条件 必须大于 0
if (useConditionMoneyValue && +useConditionMoneyValue === 0) { if (useConditionMoneyValue && +useConditionMoneyValue === 0) {
setFieldState('useConditionMoney', fieldState => { setFieldState('useConditionMoney', fieldState => {
...@@ -159,6 +171,15 @@ export const useBusinessEffects = (context, actions: IFormActions) => { ...@@ -159,6 +171,15 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
}); });
// 领券方式 // 领券方式
onFieldInputChange$('getWay').subscribe(() => {
setFieldState('suitableMemberTypes', state => {
if (state.value && state.value.length) {
FormPath.setIn(state, 'value', []);
}
});
});
// 领券方式
onFieldValueChange$('getWay').subscribe(state => { onFieldValueChange$('getWay').subscribe(state => {
const { value } = state; const { value } = state;
...@@ -181,9 +202,6 @@ export const useBusinessEffects = (context, actions: IFormActions) => { ...@@ -181,9 +202,6 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
}); });
setFieldState('suitableMemberTypes', state => { setFieldState('suitableMemberTypes', state => {
if (state.value && state.value.length) {
FormPath.setIn(state, 'value', []);
}
FormPath.setIn(state, 'props.enum', newData); FormPath.setIn(state, 'props.enum', newData);
}); });
}); });
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
* @Author: XieZhiXiong * @Author: XieZhiXiong
* @Date: 2021-06-24 13:47:47 * @Date: 2021-06-24 13:47:47
* @LastEditors: XieZhiXiong * @LastEditors: XieZhiXiong
* @LastEditTime: 2021-07-23 14:42:48 * @LastEditTime: 2021-07-23 18:03:47
* @Description: 新增/修改 优惠券表单 * @Description: 新增/修改 优惠券表单
*/ */
import React, { useState, useMemo } from 'react'; import React, { useState, useMemo, useEffect } from 'react';
import { Spin, Button, message } from 'antd'; import { Spin, Button, message } from 'antd';
import { PlusOutlined, DeleteOutlined, SaveOutlined } from '@ant-design/icons'; import { DeleteOutlined, SaveOutlined } from '@ant-design/icons';
import { createFormActions, FormEffectHooks } from '@formily/antd'; import { createFormActions, FormEffectHooks } from '@formily/antd';
import { Radio, DatePicker, ArrayTable } from '@formily/antd-components'; import { Radio, DatePicker, ArrayTable } from '@formily/antd-components';
import { history, Prompt } from 'umi'; import { history, Prompt } from 'umi';
...@@ -50,7 +50,7 @@ export type SubmitValueType = { ...@@ -50,7 +50,7 @@ export type SubmitValueType = {
*/ */
name: string, name: string,
/** /**
* 优惠券名称 * 券面额
*/ */
denomination: string, denomination: string,
/** /**
...@@ -105,28 +105,24 @@ export type SubmitValueType = { ...@@ -105,28 +105,24 @@ export type SubmitValueType = {
/** /**
* 使用说明 * 使用说明
*/ */
userConditionDesc: string, useConditionDesc: string,
/** /**
* 适用商品 * 适用商品
*/ */
goodsList: ProductItemType[], goodsList?: ProductItemType[],
/** /**
* 适用品类 * 适用品类
*/ */
applicableCategories?: { applicableCategories?: {
category: string[][], category: number[][],
}[], }[],
/** /**
* 适用品牌 * 适用品牌
*/ */
applicableBrands: { applicableBrands?: {
brand: string[], brand: number,
}[], }[],
/** /**
* 适用用户
*/
applicationUser: any[],
/**
* 适用用户角色 * 适用用户角色
*/ */
applicationUserRole: any[], applicationUserRole: any[],
...@@ -140,6 +136,8 @@ export type SubmitValueType = { ...@@ -140,6 +136,8 @@ export type SubmitValueType = {
suitableMallTypes: number[], suitableMallTypes: number[],
} }
export type CouponInfoType = SubmitValueType & {}
interface IProps { interface IProps {
/** /**
* 数据id * 数据id
...@@ -156,10 +154,76 @@ const CouponForm: React.FC<IProps> = (props) => { ...@@ -156,10 +154,76 @@ const CouponForm: React.FC<IProps> = (props) => {
id, id,
editable = true, editable = true,
} = props; } = props;
const [couponInfo, setCouponInfo] = useState<CouponInfoType>();
const [infoLoading, setInfoLoading] = useState(false);
const [submitLoading, setSubmitLoading] = useState(false); const [submitLoading, setSubmitLoading] = useState(false);
const [typeValue, setTypeValue] = useState<undefined | number>(undefined); const [typeValue, setTypeValue] = useState<undefined | number>(undefined);
const [unsaved, setUnsaved] = useState(false); const [unsaved, setUnsaved] = useState(false);
const getCouponDetail = () => {
if (!id) {
return;
}
setInfoLoading(true);
PublicApi.getMarketingCouponWaitAuditGet({
id: `${id}`,
}).then((res) => {
if (res.code === 1000) {
const {
id,
status,
statusName,
suitableCommoditySkuList,
suitableCategoryList,
suitableBrandList,
suitableMallTypes,
suitableMemberLevelTypes,
denomination,
quantity,
releaseTimeStart,
releaseTimeEnd,
effectiveTimeStart,
effectiveTimeEnd,
invalidDay,
useConditionMoney,
conditionGetTotal,
conditionGetDay,
createTime,
taskSteps,
history,
...rest
} = res.data;
setCouponInfo({
goodsList: suitableCommoditySkuList as any,
applicableCategories: (suitableCategoryList as any)?.map((item) => ({ category: item.map((category) => `${category.id}`)})),
applicableBrands: suitableBrandList?.map((item) => ({ brand: item.id })),
applicationUserRole: [],
applicationMemberLevel: suitableMemberLevelTypes,
suitableMallTypes: suitableMallTypes?.map((item) => item.id),
denomination: `${denomination}`,
quantity: `${quantity}`,
releaseTimeStart: releaseTimeStart ? moment(releaseTimeStart).format('YYYY-MM-DD HH:mm:ss') : '',
releaseTimeEnd: releaseTimeEnd ? moment(releaseTimeEnd).format('YYYY-MM-DD HH:mm:ss') : '',
effectiveTimeStart: effectiveTimeStart ? moment(effectiveTimeStart).format('YYYY-MM-DD HH:mm:ss') : '',
effectiveTimeEnd: effectiveTimeEnd ? moment(effectiveTimeEnd).format('YYYY-MM-DD HH:mm:ss') : '',
invalidDay: invalidDay !== null ? `${invalidDay}` : undefined,
useConditionMoney: `${useConditionMoney}`,
receiveCondition: {
conditionGetTotal: `${conditionGetTotal}`,
conditionGetDay: `${conditionGetDay}`,
},
...rest,
});
}
}).finally(() => {
setInfoLoading(false);
});
};
useEffect(() => {
getCouponDetail();
}, []);
const anchorsArr = [ const anchorsArr = [
{ {
key: 'basicInfo', key: 'basicInfo',
...@@ -169,6 +233,10 @@ const CouponForm: React.FC<IProps> = (props) => { ...@@ -169,6 +233,10 @@ const CouponForm: React.FC<IProps> = (props) => {
key: 'couponRules', key: 'couponRules',
name: '优惠券规则', name: '优惠券规则',
}, },
{
key: 'applicableShopList',
name: '适用商城',
},
( (
typeValue === MERCHANT_COUPON_TYPE_PRODUCT typeValue === MERCHANT_COUPON_TYPE_PRODUCT
|| typeValue === MERCHANT_COUPON_TYPE_VOUCHER || typeValue === MERCHANT_COUPON_TYPE_VOUCHER
...@@ -198,10 +266,6 @@ const CouponForm: React.FC<IProps> = (props) => { ...@@ -198,10 +266,6 @@ const CouponForm: React.FC<IProps> = (props) => {
key: 'applicableMember', key: 'applicableMember',
name: '适用用户', name: '适用用户',
}, },
{
key: 'applicableShopList',
name: '适用商城',
},
].filter(Boolean); ].filter(Boolean);
// 删除商品项 // 删除商品项
...@@ -293,6 +357,29 @@ const CouponForm: React.FC<IProps> = (props) => { ...@@ -293,6 +357,29 @@ const CouponForm: React.FC<IProps> = (props) => {
msg(); msg();
setSubmitLoading(false); setSubmitLoading(false);
}); });
} else {
setSubmitLoading(true);
const msg = message.loading({
content: '正在修改,请稍候...',
duration: 0,
});
PublicApi.postMarketingCouponWaitAuditUpdate({
id,
...payload,
}, {
timeout: 0,
}).then((res) => {
if (res.code !== 1000) {
return;
}
setUnsaved(false);
setTimeout(() => {
history.goBack();
}, 800);
}).finally(() => {
msg();
setSubmitLoading(false);
});
} }
}; };
...@@ -305,7 +392,7 @@ const CouponForm: React.FC<IProps> = (props) => { ...@@ -305,7 +392,7 @@ const CouponForm: React.FC<IProps> = (props) => {
); );
return ( return (
<Spin spinning={false}> <Spin spinning={infoLoading}>
<AnchorPage <AnchorPage
title="新增商家优惠券" title="新增商家优惠券"
anchors={anchorsArr} anchors={anchorsArr}
...@@ -325,7 +412,7 @@ const CouponForm: React.FC<IProps> = (props) => { ...@@ -325,7 +412,7 @@ const CouponForm: React.FC<IProps> = (props) => {
previewPlaceholder=" " previewPlaceholder=" "
onSubmit={handleSubmit} onSubmit={handleSubmit}
actions={formActions} actions={formActions}
initialValues={{}} initialValues={couponInfo}
components={{ components={{
RadioGroup: Radio.Group, RadioGroup: Radio.Group,
RangePicker: DatePicker.RangePicker, RangePicker: DatePicker.RangePicker,
......
...@@ -2,15 +2,17 @@ ...@@ -2,15 +2,17 @@
* @Author: XieZhiXiong * @Author: XieZhiXiong
* @Date: 2021-06-25 17:00:46 * @Date: 2021-06-25 17:00:46
* @LastEditors: XieZhiXiong * @LastEditors: XieZhiXiong
* @LastEditTime: 2021-06-25 17:00:47 * @LastEditTime: 2021-07-23 17:09:45
* @Description: 编辑商家优惠券 * @Description: 编辑商家优惠券
*/ */
import React from 'react'; import React from 'react';
import { usePageStatus } from '@/hooks/usePageStatus';
import CouponForm from './components/CouponForm'; import CouponForm from './components/CouponForm';
const MerchantCouponEdit: React.FC = () => { const MerchantCouponEdit: React.FC = () => {
const { id } = usePageStatus();
return ( return (
<CouponForm /> <CouponForm id={+id} />
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment