Commit 327f7c95 authored by XieZhiXiong's avatar XieZhiXiong

feat: 添加适用会员类型

parent 6abb7e58
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-06-24 14:03:34
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-03 15:52:33
* @LastEditTime: 2021-09-23 16:17:02
* @Description:
*/
import { FormPath, FormEffectHooks } from '@formily/antd';
......@@ -88,8 +88,24 @@ const fetchSuitableUser = async () => {
};
};
// 初始化 适用会员类型
const fetchMemberTypes = async () => {
const res = await PublicApi.getMarketingCouponPlatformMemberTypeList();
if (res.code === 1000) {
const { data = [] } = res;
return {
memberTypes: data.map(item => ({ label: item.name, value: item.value })),
};
}
return {
data: [],
totalCount: 0,
};
};
// 获取 实用会员选项
const fetchMemberOptions: (params: { current: string, pageSize: string, levelConfigIds: string, roleIds: string }) => Promise<ResponseType> = async (params) => {
const fetchMemberOptions: (params: { current: string, pageSize: string, levelConfigIds: string, roleIds: string, memberTypes: string }) => Promise<ResponseType> = async (params) => {
const res = await PublicApi.getMemberManageMarketingSuitableLevelConfigPage(params);
if (res.code === 1000) {
const options = res.data.data.map(item => ({
......@@ -124,6 +140,8 @@ export const createEffects = (context, actions) => {
useAsyncInitSelect(['suitableMemberTypes'], fetchSuitableUser);
useAsyncInitSelect(['memberTypes'], fetchMemberTypes);
// 初始化 适用商城数据
onFieldMount$('suitableMallTypes').subscribe(() => {
PublicApi.getManageShopAllByShopType({
......
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-06-24 14:04:16
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-07-30 17:48:32
* @LastEditTime: 2021-09-23 16:14:31
* @Description:
*/
import { FormEffectHooks, FormPath, IFormActions } from '@formily/antd';
......@@ -19,8 +19,6 @@ import {
MERCHANT_COUPON_RECEIVE_OPERATE,
SUITABLE_TYPE_NEW_USER,
SUITABLE_TYPE_OLD_USER,
SUITABLE_TYPE_NEW_MEMBER,
SUITABLE_TYPE_OLD_MEMBER,
} from '@/constants/const/marketing';
const {
......@@ -232,18 +230,6 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
});
});
// 适用用户
onFieldValueChange$('suitableMemberTypes').subscribe(state => {
const { value } = state;
// 包含新会员(仅会员用户) 或者 老会员(仅会员用户),展示 适用用户角色 与 会员等级列表
if (value && (value.includes(SUITABLE_TYPE_NEW_MEMBER) || value.includes(SUITABLE_TYPE_OLD_MEMBER))) {
linkage.show('*(applicationUserRole,applicationMemberLevel)');
} else {
linkage.hide('*(applicationUserRole,applicationMemberLevel)');
}
});
// 券有效期类型,展示对应的 FieldItem
onFieldValueChange$('effectiveType').subscribe(state => {
const { value } = state;
......@@ -255,4 +241,30 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
linkage.show('invalidDay');
}
});
// 每日可领取量
onFieldInputChange$('receiveCondition.conditionGetDay').subscribe(state => {
const { value } = state;
const conditionGetTotalValue = getFieldValue('receiveCondition.conditionGetTotal'); // 每会员ID总共可领取;
if (+value > +conditionGetTotalValue) {
setFieldState('receiveCondition.conditionGetDay', fieldState => {
FormPath.setIn(fieldState, 'errors', '每日可领取必须小于或等于总可领取量');
});
} else {
actions.clearErrors('receiveCondition.conditionGetDay');
}
});
// 每会员ID总共可领取
onFieldInputChange$('receiveCondition.conditionGetTotal').subscribe(state => {
const { value } = state;
const conditionGetDayValue = getFieldValue('receiveCondition.conditionGetDay'); // 每会员ID总共可领取;
if (+value < +conditionGetDayValue) {
setFieldState('receiveCondition.conditionGetTotal', fieldState => {
FormPath.setIn(fieldState, 'errors', '每会员ID总共可领取必须大于每日可领取');
});
} else {
actions.clearErrors('receiveCondition.conditionGetTotal');
}
});
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-06-24 13:47:47
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-13 15:14:24
* @LastEditTime: 2021-09-23 16:55:22
* @Description: 新增/修改 优惠券表单
*/
import React, { useState, useMemo, useEffect } from 'react';
......@@ -122,6 +122,10 @@ export type SubmitValueType = {
* 适用商城
*/
suitableMallTypes: number[],
/**
* 实用会员类型
*/
memberTypes: number[],
}
export type CouponInfoType = SubmitValueType & {}
......@@ -188,7 +192,7 @@ const CouponForm: React.FC<IProps> = (props) => {
goodsList: suitableCommoditySkuList as any,
applicationUserRole,
applicationMemberLevel: suitableMemberLevelTypes?.map((item) => item.id),
suitableMemberTypes: suitableMemberTypes?.map((item) => item.value),
suitableMemberTypes: suitableMemberTypes,
suitableMallTypes: suitableMallTypes?.map((item) => item.id),
denomination: `${denomination}`,
quantity: `${quantity}`,
......@@ -355,7 +359,7 @@ const CouponForm: React.FC<IProps> = (props) => {
return (
<Spin spinning={infoLoading}>
<AnchorPage
title="新增平台优惠券"
title={`${!id ? '新增' : '编辑'}平台优惠券`}
anchors={anchorsArr}
extra={[
<Button
......
......@@ -2,13 +2,22 @@
* @Author: XieZhiXiong
* @Date: 2021-06-24 14:05:57
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-02 17:38:26
* @LastEditTime: 2021-09-22 14:02:44
* @Description:
*/
import { ISchema } from '@formily/antd';
import moment from 'moment';
import themeConfig from '@/../config/theme.config';
import { PATTERN_MAPS } from '@/constants/regExp';
function range(start, end) {
const result = [];
for (let i = start; i < end; i++) {
result.push(i);
}
return result;
}
const schema: ISchema = {
type: 'object',
properties: {
......@@ -51,6 +60,12 @@ const schema: ISchema = {
'x-component-props': {
allowClear: false,
},
'x-rules': [
{
limitByte: true, // 自定义校验规则
maxByte: 60,
}
],
},
denomination: {
title: '券面额',
......@@ -89,6 +104,17 @@ const schema: ISchema = {
'x-component-props': {
placeholder: ['领(发)劵起始时间', '领(发)劵截止时间'],
showTime: true,
disabledDate: (current) => current && current < moment().startOf('day'),
disabledTime: (_, type) => {
if (type === 'start') {
return {
disabledHours: () => range(0, 24).splice(0, moment().get('hour')),
disabledMinutes: () => range(0, 60).splice(0, moment().get('minute')),
disabledSeconds: () => range(0, 60).splice(0, moment().get('second')),
};
}
return {};
},
},
},
},
......@@ -276,6 +302,17 @@ const schema: ISchema = {
'x-component-props': {
placeholder: ['劵有效期起始时间', '劵有效期截止时间'],
showTime: true,
disabledDate: (current) => current && current < moment().startOf('day'),
disabledTime: (_, type) => {
if (type === 'start') {
return {
disabledHours: () => range(0, 24).splice(0, moment().get('hour')),
disabledMinutes: () => range(0, 60).splice(0, moment().get('minute')),
disabledSeconds: () => range(0, 60).splice(0, moment().get('second')),
};
}
return {};
},
},
},
invalidDay: {
......@@ -388,6 +425,16 @@ const schema: ISchema = {
'x-component-props': {
},
},
memberTypes: {
title: '适用会员类型',
type: 'string',
enum: [],
default: [],
required: true,
'x-component': 'TofuCheckGroup',
'x-component-props': {
},
},
applicationUserRole: {
title: '适用用户角色',
type: 'string',
......
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