Commit eb046247 authored by XieZhiXiong's avatar XieZhiXiong

chore: 完善联动逻辑

parent 0c3df8f7
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-06-24 14:03:34
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-06-30 17:57:05
* @LastEditTime: 2021-07-02 10:32:13
* @Description:
*/
import { FormPath, FormEffectHooks } from '@formily/antd';
......@@ -40,6 +40,28 @@ const fetchCouponGetWay = async () => {
return {};
};
// 初始化 适用用户角色
const fetchApplicationUserRole = async () => {
const res = await PublicApi.getMemberAbilityLevelRoleList();
const allItem = {
label: '全部',
value: 0,
};
if (res.code === 1000) {
const { data = [] } = res;
const options = [
allItem,
...(data.map(item => ({ label: item.roleName, value: item.roleId })))
];
return {
applicationUserRole: options,
};
}
return {};
};
export const createEffects = (context, actions) => {
const { setFieldState } = actions;
......@@ -49,19 +71,22 @@ export const createEffects = (context, actions) => {
useAsyncInitSelect(['getWay'], fetchCouponGetWay);
useAsyncInitSelect(['applicationUserRole'], fetchApplicationUserRole);
// 初始化 品牌数据
onFieldMount$('applicableBrands').subscribe(() => {
PublicApi.getProductSelectGetSelectBrand().then((res) => {
if (res.code === 1000) {
const { data = [] } = res;
setFieldState('applicableBrands.*.brand', state => {
FormPath.setIn(state, 'props.enum', data.map(item => ({ label: item.name, value: item.id })));
FormPath.setIn(state, 'props.enum', data.map(item => ({ label: item.name, value: `${item.id}` })));
});
}
});
});
// 初始化 品类数据
onFieldMount$('applicableCategories').subscribe(() => {
// 初始化 品类数据
PublicApi.getProductCustomerGetCustomerCategoryTree().then((res) => {
if (res.code === 1000) {
const { data = [] } = res;
......@@ -71,4 +96,15 @@ export const createEffects = (context, actions) => {
}
});
});
onFieldMount$('suitableMallTypes').subscribe(() => {
PublicApi.getManageShopFindByMemberType().then((res) => {
if (res.code === 1000) {
const { data = [] } = res;
setFieldState('suitableMallTypes', state => {
FormPath.setIn(state, 'props.enum', data.map(item => ({ label: item.name, value: item.id, logo: item.logoUrl })));
});
}
});
});
};
\ No newline at end of file
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-06-24 14:04:16
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-07-01 14:21:31
* @LastEditTime: 2021-07-02 14:14:20
* @Description:
*/
import { FormEffectHooks, FormPath, IFormActions } from '@formily/antd';
......@@ -17,6 +17,7 @@ import {
MERCHANT_COUPON_RECEIVE_ACTIVITY,
MERCHANT_COUPON_RECEIVE_OPERATE,
} from '@/constants/marketing';
import { PublicApi } from '@/services/api';
const {
onFieldInputChange$,
......@@ -121,6 +122,7 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
});
} else {
actions.clearErrors('denomination');
actions.clearErrors('useConditionMoney');
}
});
......@@ -153,6 +155,7 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
});
} else {
actions.clearErrors('useConditionMoney');
actions.clearErrors('denomination');
}
});
......@@ -160,8 +163,8 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
onFieldValueChange$('getWay').subscribe(state => {
const { value } = state;
const applicationUserEnum = [...getFieldState('applicationUser', state => state.props.enum)];
const newData = applicationUserEnum.map((item) => {
const suitableMemberTypesEnum = [...getFieldState('suitableMemberTypes', state => state.props.enum)];
const newData = suitableMemberTypesEnum.map((item) => {
const newItem = {...item};
newItem.disabled = false;
if (
......@@ -178,17 +181,50 @@ export const useBusinessEffects = (context, actions: IFormActions) => {
return newItem;
});
setFieldState('applicationUser', state => {
FormPath.setIn(state, 'value', []);
setFieldState('suitableMemberTypes', state => {
if (state.value && state.value.length) {
FormPath.setIn(state, 'value', []);
}
FormPath.setIn(state, 'props.enum', newData);
});
});
// 适用用户角色
onFieldValueChange$('applicationUserRole').subscribe(state => {
const { value } = state;
const filtered = (value || []).filter((item) => item !== 0); // 过滤掉 0全选元素
// 查询会员列表,0 表示全部
PublicApi.getMemberAbilityLevelTagPage({
roleIds: filtered.join(','),
current: `${1}`,
pageSize: `${9999}`,
levelConfigIds: '',
}).then(res => {
if (res.code === 1000) {
const options = res.data.data.map(item => ({
label: item.roleName,
value: item.id,
level: item.level,
roleName: item.roleName,
levelTypeName: item.levelTypeName,
memberTypeName: item.memberTypeName,
}));
linkage.enum('applicationMemberLevel', options);
}
});
});
// 适用用户
onFieldValueChange$('applicationUser').subscribe(state => {
onFieldValueChange$('suitableMemberTypes').subscribe(state => {
const { value } = state;
console.log('value', value)
// 包含新会员(仅会员用户) 或者 老会员(仅会员用户),展示 适用用户角色 与 会员等级列表
if (value && (value.includes(3) || value.includes(4))) {
linkage.show('*(applicationUserRole,applicationMemberLevel)');
} else {
linkage.hide('*(applicationUserRole,applicationMemberLevel)');
}
});
// 券有效期类型,展示对应的 FieldItem
......
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