Commit da792376 authored by XieZhiXiong's avatar XieZhiXiong

对接完已有接口

parent 2bffb388
......@@ -82,6 +82,9 @@ export const STATUS_ENUM = [
}
]
// 1是阿里云oss服务器, 2是本地文件服务器
export const UPLOAD_TYPE = isDev ? 2 : 1
// 会员规则类型
export const VIP_RULE_TRANSACTION = 1; // 交易
export const VIP_RULE_LOGIN = 2; // 登录
......
......@@ -172,9 +172,11 @@ const addEquity: React.FC<[]> = () => {
setSubmitLoading(true);
try {
const res = await Promise.all(promises);
message.success('保存成功');
getMemberLevelInfo();
const resArr = await Promise.all(promises);
if (resArr.every(item => item && item.code === 1000)) {
message.success('保存成功');
getMemberLevelInfo();
}
} catch (errInfo) {
}
......
import React, { useState, useEffect, useRef, ReactNode } from 'react';
import { history } from 'umi';
import { Badge, Button, Card, message } from 'antd';
import { history, Prompt } from 'umi';
import { Badge, Button, Card, Spin, message } from 'antd';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { SaveOutlined } from '@ant-design/icons';
import { createFormActions } from '@formily/antd';
import { ColumnType } from 'antd/lib/table/interface';
import { createFormActions, FormEffectHooks, FormPath } from '@formily/antd';
import { Select, Input } from '@formily/antd-components'
import { merge } from 'rxjs';
import { usePageStatus } from '@/hooks/usePageStatus';
import ReutrnEle from '@/components/ReturnEle';
import NiceForm from '@/components/NiceForm';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
import { FORM_FILTER_PATH } from '@/formSchema/const';
import { initDetailSchema } from './schema';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
import { useAsyncInitSelect } from '@/formSchema/effects/useAsyncInitSelect';
import { useLinkageUtils } from '@/utils/formEffectUtils';
import { PublicApi } from '@/services/api';
import { GetMemberAbilitySubGetResponse } from '@/services/MemberApi';
import { initDetailSchema } from './schema';
const formActions = createFormActions();
const {
onFieldValueChange$,
onFieldInputChange$,
onFormInputChange$,
} = FormEffectHooks;
const addMember: React.FC<any> = props => {
const ref = useRef<any>({});
const AddMember: React.FC<any> = props => {
const { id, validateId } = usePageStatus();
const [memberItems, setMemberItems] = useState<any>({});
const [memberInfo, setMemberInfo] = useState<GetMemberAbilitySubGetResponse>(null);
const [submitLoading, setSubmitLoading] = useState(false);
const [infoLoading, setInfoLoading] = useState(false);
const [unsaved, setUnsaved] = useState(false);
const data = [
{
key: '1',
sn: '1',
roleName: '供应商',
status: '1',
operation: '申请注册',
useTime: '2020-05-12 08:08',
result: '无',
},
];
const columns: ColumnType<any>[] = [
{
title: '序号',
dataIndex: 'sn',
align: 'center',
key: 'sn',
},
{
title: '操作角色',
dataIndex: 'roleName',
align: 'center',
key: 'roleName',
},
{
title: '状态',
dataIndex: 'status',
align: 'center',
key: 'status',
render: (text: any, record: any) => {
let component: ReactNode = null;
component = <Badge color="#FFC400" text="待审核" />;
return component;
},
},
{
title: '操作',
dataIndex: 'operation',
align: 'center',
key: 'operation',
},
{
title: '操作时间',
dataIndex: 'useTime',
align: 'center',
key: 'useTime',
},
{
title: '审核意见',
dataIndex: 'result',
align: 'center',
key: 'result',
},
];
const getDetailedInfo = async () => {
if (id && validateId) {
setInfoLoading(true);
const infoRes = await PublicApi.getMemberAbilitySubGet({
memberId: id,
validateId,
});
useEffect(() => {
PublicApi.getMemberMaintenanceAddpageitems().then(res => {
setMemberItems(res.data);
});
}, []);
if (infoRes.code !== 1000) {
return;
}
const {
memberTypeEnum,
groups = [],
areaCodes,
// 模拟请求
const fetchData = (params: any) => {
return new Promise((resolve, reject) => {
const queryResult = data.find(v => v.key === params.keywords);
setTimeout(() => {
resolve({
code: 200,
message: '',
data: queryResult ? [queryResult] : data,
});
}, 1000);
});
account,
channelLevelTag,
channelTypeName,
countryCode,
createTime,
currentStep,
levelTag,
memberId,
memberTypeName,
name,
outerHistory,
outerStatusName,
roleName,
verifySteps,
...rest
}: any = infoRes.data;
// 注册资料处理
const detail = {};
for (let i = 0; i < groups.length; i++) {
const item = groups[i];
if (item.elements) {
for (let j = 0; j < item.elements.length; j++) {
const ele = item.elements[j];
detail[ele.fieldName] = ele.fieldValue;
}
}
}
setMemberInfo({
memberTypeId: memberTypeEnum,
...rest,
areas: areaCodes,
channelLevel: channelLevelTag,
...detail,
});
setInfoLoading(false);
}
};
useEffect(() => {
// getDetailedInfo();
}, []);
const handleSubmit = (values: any) => {
console.log(values);
};
const {
memberTypeId,
roleId,
levelId,
countryCodeId,
phone,
email,
// 会员类型、会员角色、会员等级选项
const fetchSelectOptions = async () => {
const { data } = await PublicApi.getMemberMaintenanceAddpageitems();
return {
memberTypeId: fetchSomeOptions(data.memberTypes),
roleId: fetchSomeOptions(data.memberRoles),
level: fetchSomeOptions(data.memberLevels),
};
};
outerStatus,
status,
statusName,
...rest
} = values;
// 获取手机code
const fetchTelCode = async () => {
const { data } = await PublicApi.getManageGetTelCode();
return data;
if (!id) {
setSubmitLoading(true);
const msg = message.loading({
content: '正在添加,请稍候...',
duration: 0,
});
PublicApi.postMemberMaintenanceAddmember({
memberTypeId,
roleId,
levelId,
countryCodeId,
phone,
email,
detail: rest,
}).then(res => {
if (res.code !== 1000) {
return;
}
setTimeout(() => {
history.goBack();
}, 800);
}).finally(() => {
msg();
setSubmitLoading(false);
});
} else {
setSubmitLoading(true);
const msg = message.loading({
content: '正在保存,请稍候...',
duration: 0,
});
// PublicApi.postMemberAbilitySubUpdate({
// memberId: id,
// validateId,
// memberTypeId,
// roleId,
// levelId,
// countryCodeId,
// phone,
// email,
// channelTypeId,
// remark,
// detail: rest,
// }).then(res => {
// if (res.code !== 1000) {
// return;
// }
// setUnsaved(false);
// setTimeout(() => {
// history.replace('/memberCenter/memberAbility/manage/import');
// }, 800);
// }).finally(() => {
// msg();
// setSubmitLoading(false);
// });
}
};
const fetchSomeOptions = data => {
return data.map(v => ({ label: v.text, value: v.id }));
};
// 会员类型、注册手机下拉框
const getPageitemsBasic = async () => {
const res = await PublicApi.getMemberMaintenanceAddpageitems();
const beforeUpload = (file: any) => {
const isJpgOrPng =
file.type === 'image/jpeg' ||
file.type === 'image/png' ||
file.type === 'image/jpg';
if (!isJpgOrPng) {
message.error('仅支持上传JPEG/JPG/PNG文件!');
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
message.error('上传图片不超过2MB!');
if (res.code === 1000) {
const { data = {} }: any = res;
const {
memberTypes = [],
countryCodes = [],
} = data;
return {
memberTypeId: memberTypes.map(item => ({ label: item.memberTypeName, value: item.memberTypeId })),
countryCodeId: countryCodes.map(item => ({ label: item.text, value: item.id })),
};
}
return isJpgOrPng && isLt2M;
return {};
};
return (
<PageHeaderWrapper
onBack={() => history.goBack()}
backIcon={<ReutrnEle description="返回" />}
title={
props.location.query.type === 'add'
? '新建会员'
: props.location.query.type === 'change'
? '编辑会员'
: '查看会员'
const useAsyncLinkageEffect = () => {
const linkage = useLinkageUtils();
// 间接触发根据会员类型
onFieldValueChange$('memberTypeId').subscribe(fieldState => {
if (!fieldState.value) {
return;
}
// 查询角色下拉
linkage.loading('roleId');
PublicApi.getMemberMaintenanceAddpageitemsRole({
memberTypeId: fieldState.value,
}).then(res => {
if (res.code === 1000) {
const { data = [] } = res;
const options = data.map(item => ({ label: item.roleName, value: item.roleId }));
linkage.enum('roleId', options);
}
}).finally(() => {
linkage.loaded('roleId');
});
});
// 根据会员类型
onFieldInputChange$('memberTypeId').subscribe(fieldState => {
if (!fieldState.value) {
return;
}
extra={[
<Button
key="1"
type="primary"
icon={<SaveOutlined />}
onClick={() => formActions.submit()}
>
保存
</Button>,
]}
>
<Card>
<NiceForm
onSubmit={handleSubmit}
actions={formActions}
effects={($, actions) => {
useStateFilterSearchLinkageEffect(
$,
actions,
'name',
FORM_FILTER_PATH,
);
useAsyncInitSelect(
['memberTypeId', 'roleId', 'level'],
fetchSelectOptions,
);
useAsyncSelect('telCode', fetchTelCode);
}}
schema={initDetailSchema(memberItems)}
/>
</Card>
</PageHeaderWrapper>
linkage.value('roleId', undefined);
linkage.enum('roleId', []);
linkage.value('levelId', undefined);
linkage.enum('levelId', []);
});
// 根据会员角色,查询其他注册资料
onFieldValueChange$('roleId').subscribe(fieldState => {
if (!fieldState.value) {
return;
}
// PublicApi.getMemberAbilitySubPageitemsDetail({
// roleId: fieldState.value,
// }).then(res => {
// if (res.code === 1000) {
// const { data = [] } = res;
// setMemberItems(data);
// }
// });
});
// 手动触发改变的话重置等级下拉框
onFieldInputChange$('*(memberTypeId,roleId)').subscribe(() => {
linkage.value('levelId', undefined);
linkage.enum('levelId', []);
});
// 根据会员类型和角色,查询等级下拉
onFieldValueChange$('*(memberTypeId,roleId)').subscribe(fieldState => {
const selfName = fieldState.name;
const selfValue = fieldState.value;
const otherName = selfName == 'memberTypeId' ? 'roleId' : 'memberTypeId';
const otherValue = formActions.getFieldState(otherName, state => state.value);
if (selfValue && otherValue) {
linkage.loading('levelId');
PublicApi.getMemberMaintenanceAddpageitemsLevel({
memberTypeId: selfName == 'memberTypeId' ? selfValue : otherValue,
roleId: selfName == 'memberTypeId' ? otherValue : selfValue,
}, {
useCache: true,
}).then(res => {
if (res.code === 1000) {
const { data = [] } = res;
const options = data.map(item => ({ label: item.levelTag, value: item.levelId }));
linkage.enum('levelId', options);
}
}).finally(() => {
linkage.loaded('levelId');
});
}
});
}
return (
<Spin spinning={infoLoading}>
<PageHeaderWrapper
onBack={() => history.goBack()}
backIcon={<ReutrnEle description="返回" />}
title={!id ? '新建会员' : '编辑会员'}
extra={[
<Button
key="1"
type="primary"
icon={<SaveOutlined />}
loading={submitLoading}
onClick={() => formActions.submit()}
>
保存
</Button>,
]}
>
<Card>
<NiceForm
onSubmit={handleSubmit}
actions={formActions}
initialValues={memberInfo || {}}
effects={($, actions) => {
useAsyncInitSelect(
['memberTypeId', 'countryCodeId'],
getPageitemsBasic,
);
useAsyncLinkageEffect();
onFormInputChange$().subscribe(() => {
if (!unsaved) {
setUnsaved(true);
}
});
}}
schema={initDetailSchema(memberItems)}
/>
</Card>
</PageHeaderWrapper>
<Prompt when={unsaved} message="您还有未保存的内容,是否确定要离开?" />
</Spin>
);
};
export default addMember;
export default AddMember;
import { ISchema } from '@formily/antd';
import { FORM_FILTER_PATH } from '@/formSchema/const';
import { UPLOAD_TYPE } from '@/constants';
import { PATTERN_MAPS } from '@/constants/regExp';
export const importSchema: ISchema = {
type: 'object',
......@@ -154,44 +156,59 @@ export const auditModalSchema: ISchema = {
},
};
const FIELD_TYPE_MAP = {
'string': 'string',
'long': 'string',
'upload': 'customUpload',
};
const getXComponentProps = (type, item) => {
const MAP = {
'string': {
placeholder: item.fieldRemark,
},
'upload': {
listType: 'card',
action: '/api/file/file/upload',
data: { fileType: UPLOAD_TYPE },
fileList: [],
onChange: file => console.log(file),
},
};
return MAP[type];
};
const getCompnentValue = (elements: any) => {
let components = {};
const components = {};
for (let item of elements) {
let xComponentProps =
item.fieldType === 'string'
? {
placeholder: item.fieldRemark,
}
: {
listType: 'card',
action: '/api/file/file/upload',
data: { fileType: 2 },
fileList: [],
onChange: file => console.log(file),
};
components[item.fieldName] = {
type: item.fieldType,
required: item.fieldEmpty === 0,
title: item.fieldCNName,
'x-component-props': xComponentProps,
};
// 先判断是否存在 type,防止不存在的 type 报错
const realType = FIELD_TYPE_MAP[item.fieldType];
if (realType) {
components[item.fieldName] = {
type: FIELD_TYPE_MAP[item.fieldType],
required: item.fieldEmpty === 0,
title: item.fieldCNName,
'x-component-props': getXComponentProps(realType, item),
};
}
}
return components;
};
export const initDetailSchema = (props: any) => {
let tabSchema = {
let tabSchema: ISchema = {
properties: {
'tab-1': {
type: 'object',
'x-component': 'tabpane',
'x-component': 'TabPane',
'x-component-props': {
tab: '基本信息',
},
properties: {
MEGA_LAYOUT1: {
type: 'object',
'x-component': 'mega-layout',
'x-component': 'Mega-Layout',
'x-component-props': {
labelCol: 4,
wrapperCol: 8,
......@@ -213,10 +230,13 @@ export const initDetailSchema = (props: any) => {
title: '会员角色',
enum: [],
'x-component-props': {
placeholder: '请选择',
placeholder: '请选择',
},
'x-props': {
hasFeedback: true,
},
},
level: {
levelId: {
type: 'string',
required: true,
title: '会员等级',
......@@ -224,69 +244,73 @@ export const initDetailSchema = (props: any) => {
'x-component-props': {
placeholder: '请选择',
},
'x-props': {
hasFeedback: true,
},
},
MEGA_LAYOUT1_1: {
type: 'object',
'x-component': 'mega-layout',
'x-component': 'Mega-Layout',
'x-component-props': {
label: '注册手机',
wrapperCol: 24,
required: true,
},
required: true,
inline: true,
},
properties: {
MEGA_LAYOUT1_1_1: {
type: 'object',
'x-component': 'mega-layout',
countryCodeId: {
type: 'string',
enum: [],
'x-component-props': {
grid: true,
full: true,
},
properties: {
telCode: {
type: 'string',
enum: [],
'x-component-props': {
placeholder: '请选择',
},
required: true,
},
tel: {
type: 'string',
'x-mega-props': { span: 2 },
'x-component-props': {
placeholder: '请输入你的手机号码',
maxLength: 11,
},
required: true,
placeholder: '请选择',
},
required: true,
},
phone: {
type: 'string',
required: true,
'x-component-props': {
placeholder: '请输入你的手机号码',
maxLength: 11,
},
'x-rules': [
{
pattern: PATTERN_MAPS.phone,
message: '请输入正确格式的手机号',
},
},
],
},
},
},
memberEmail: {
email: {
type: 'string',
title: '邮箱',
'x-component-props': {},
'x-rules': [
{
pattern: PATTERN_MAPS.email,
message: '请输入正确格式的邮箱',
},
],
},
},
},
},
},
},
},
};
if (Object.keys(props).length > 0) {
for (let [index, item] of props.groups.entries()) {
tabSchema.properties[`tab-${index + 2}`] = {
if (Array.isArray(props)) {
for (let [index, item] of props.entries()) {
tabSchema.properties![`tab-${index + 2}`] = {
type: 'object',
'x-component': 'tabpane',
'x-component': 'TabPane',
'x-component-props': {
tab: item.groupName,
},
properties: {
[`MEGA_LAYOUT${index + 2}`]: {
type: 'object',
'x-component': 'mega-layout',
'x-component': 'Mega-Layout',
'x-component-props': {
labelCol: 4,
wrapperCol: 8,
......@@ -299,13 +323,15 @@ export const initDetailSchema = (props: any) => {
}
}
let detailSchema = {
let detailSchema: ISchema = {
type: 'object',
properties: {
REPOSIT_TABS: {
tabs: {
type: 'object',
'x-component': 'tab',
'x-component-props': {},
'x-component': 'Tab',
'x-component-props': {
type: 'card',
},
...tabSchema,
},
},
......
......@@ -237,12 +237,14 @@ const AuditPr1: React.FC<QueryProps> = props => {
}),
];
Promise.all(promises).then(res => {
Promise.all(promises).then(resArr => {
if (resArr.every(item => item && item.code === 1000)) {
setTimeout(() => {
history.goBack();
}, 800);
setModalVisible(false);
}
setConfirmLoading(false);
setTimeout(() => {
history.goBack();
}, 800);
setModalVisible(false);
}).catch(() => {
setConfirmLoading(false);
});
......
......@@ -237,12 +237,14 @@ const AuditPr2: React.FC<QueryProps> = props => {
}),
];
Promise.all(promises).then(res => {
Promise.all(promises).then(resArr => {
if (resArr.every(item => item && item.code === 1000)) {
setTimeout(() => {
history.goBack();
}, 800);
setModalVisible(false);
}
setConfirmLoading(false);
setTimeout(() => {
history.goBack();
}, 800);
setModalVisible(false);
}).catch(() => {
setConfirmLoading(false);
});
......
......@@ -237,12 +237,14 @@ const AuditPrComfirm: React.FC<QueryProps> = props => {
}),
];
Promise.all(promises).then(res => {
Promise.all(promises).then(resArr => {
if (resArr.every(item => item && item.code === 1000)) {
setTimeout(() => {
history.goBack();
}, 800);
setModalVisible(false);
}
setConfirmLoading(false);
setTimeout(() => {
history.goBack();
}, 800);
setModalVisible(false);
}).catch(() => {
setConfirmLoading(false);
});
......
......@@ -237,12 +237,14 @@ const AuditPrSubmit: React.FC<QueryProps> = props => {
}),
];
Promise.all(promises).then(res => {
Promise.all(promises).then(resArr => {
if (resArr.every(item => item && item.code === 1000)) {
setTimeout(() => {
history.goBack();
}, 800);
setModalVisible(false);
}
setConfirmLoading(false);
setTimeout(() => {
history.goBack();
}, 800);
setModalVisible(false);
}).catch(() => {
setConfirmLoading(false);
});
......
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