Commit 7fb3a840 authored by GuanHua's avatar GuanHua
parents 4307b1ff 8c51fa80
...@@ -8,26 +8,30 @@ const { onFormInit$ } = FormEffectHooks ...@@ -8,26 +8,30 @@ const { onFormInit$ } = FormEffectHooks
* @param service 触发的异步函数, 需返回一个{label: any, value: any}形式的数组 * @param service 触发的异步函数, 需返回一个{label: any, value: any}形式的数组
*/ */
export const useAsyncInitSelect = (name: string[], service: () => Promise<any>) => { export const useAsyncInitSelect = (name: string[], service: () => Promise<any>) => {
const { dispatch, setFieldState } = createFormActions() const { dispatch, setFieldState } = createFormActions();
const linkage = useLinkageUtils() const linkage = useLinkageUtils();
onFormInit$().subscribe(() => { onFormInit$().subscribe(() => {
setFieldState(name, state => { const nameStr: string = name.toString();
FormPath.setIn(state, 'props.x-props.hasFeedback', true) const formPath: string = `*(${nameStr})`;
})
name.forEach(v => linkage.loaded(v)) setFieldState(formPath, state => {
FormPath.setIn(state, 'props.x-props.hasFeedback', true);
});
linkage.loading(formPath);
service().then(res => { service().then(res => {
name.forEach(v => { name.forEach(v => {
linkage.loaded(v) linkage.enum(v, res[v] || []);
linkage.enum(v, res[v]) });
}) // 请求结束可以dispatch一个自定义事件收尾,方便后续针对该事件做联动
//请求结束可以dispatch一个自定义事件收尾,方便后续针对该事件做联动 dispatch?.('requestAsyncSelect', {
dispatch && dispatch('requestAsyncSelect', {
name, name,
payload: res payload: res,
}) });
}).catch(err => { }).finally(() => {
// linkage.loaded(name) linkage.loaded(formPath);
// linkage.enum(name, []) });
})
}) })
} }
\ No newline at end of file
...@@ -298,17 +298,16 @@ const DeliverCoupon: React.FC<IProps> = (props) => { ...@@ -298,17 +298,16 @@ const DeliverCoupon: React.FC<IProps> = (props) => {
}); });
if (res.code === 1000) { if (res.code === 1000) {
const { data = {} }: any = res;
const { const {
memberTypes = [], memberTypes = [],
levels = [], levels = [],
suitableMemberTypes = [], suitableMemberTypes = [],
} = data; } = res.data;
return { return {
memberType: memberTypes.map(item => ({ label: item.memberTypeName, value: item.memberTypeId })), memberTypeEnum: memberTypes.map(item => ({ label: item.name, value: item.value })),
level: levels.map(item => ({ label: item.levelTag, value: item.level })), level: levels.map(item => ({ label: item.levelTag, value: item.level })),
suitableMemberType: suitableMemberTypes.map(item => ({ label: item.name, value: item.value })), suitableMemberType: suitableMemberTypes?.map(item => ({ label: item.name, value: item.value })),
}; };
} }
return {}; return {};
...@@ -400,7 +399,7 @@ const DeliverCoupon: React.FC<IProps> = (props) => { ...@@ -400,7 +399,7 @@ const DeliverCoupon: React.FC<IProps> = (props) => {
FORM_FILTER_PATH, FORM_FILTER_PATH,
); );
useAsyncInitSelect( useAsyncInitSelect(
['memberType', 'level', 'suitableMemberType'], ['memberTypeEnum', 'level', 'suitableMemberType'],
fetchSelectOptions, fetchSelectOptions,
); );
}, },
......
...@@ -69,6 +69,7 @@ export const drawerSchema: ISchema = { ...@@ -69,6 +69,7 @@ export const drawerSchema: ISchema = {
'x-component': 'NumberPicker', 'x-component': 'NumberPicker',
'x-component-props': { 'x-component-props': {
placeholder: '会员ID', placeholder: '会员ID',
min: 0,
}, },
}, },
memberTypeEnum: { memberTypeEnum: {
......
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