master
parent
49bf6382bf
commit
61815bef45
@ -0,0 +1,252 @@
|
||||
import Constants from '@/constants';
|
||||
import { addOrUpdateProductForAdminUsingPost } from '@/services/pop-b2b2c/pbcProductController';
|
||||
import { getCities } from '@/utils/cities';
|
||||
import {
|
||||
ProCard,
|
||||
ProForm,
|
||||
ProFormCascader,
|
||||
ProFormInstance,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
ProFormTextArea,
|
||||
ProFormUploadButton,
|
||||
} from '@ant-design/pro-components';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { Button, Col, message, Row } from 'antd';
|
||||
import Upload, { RcFile } from 'antd/es/upload';
|
||||
import moment from 'moment';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
const Detail: React.FC<any> = () => {
|
||||
const [cities] = useState(() => getCities())
|
||||
|
||||
const formRef = useRef<ProFormInstance>();
|
||||
|
||||
const onSave = () => {
|
||||
formRef.current?.submit()
|
||||
}
|
||||
|
||||
const onSubmit = async (values: any) => {
|
||||
const [pbcBusinessProvince, pbcBusinessCity, pbcBusinessArea] = values.pbcZone;
|
||||
const params: API.PbcProductDTO = {
|
||||
...values,
|
||||
pbcState: values.pbcState ? 1 : 0,
|
||||
pbcBusinessProvince,
|
||||
pbcBusinessCity,
|
||||
pbcBusinessArea,
|
||||
pbcBusinessStartDate: moment(values.pbcBusinessStartDate, 'YYYY-MM-DD'),
|
||||
pbcBusinessLogo: values.pbcBusinessLogo.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','),
|
||||
pbcBusinessImage: values.pbcBusinessImage.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','),
|
||||
pbcBusinessPosterUrl: values.pbcBusinessPosterUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','),
|
||||
pbcBusinessHeadUserNoBackUrl: values.pbcBusinessHeadUserNoBackUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','),
|
||||
pbcBusinessHeadUserNoFrontUrl: values.pbcBusinessHeadUserNoFrontUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','),
|
||||
pbcBusinessLicenseUrl: values.pbcBusinessLicenseUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','),
|
||||
pbcZone: undefined
|
||||
}
|
||||
const msg = await addOrUpdateProductForAdminUsingPost(params)
|
||||
if (msg.retcode) {
|
||||
message.success("创建成功!")
|
||||
history.back();
|
||||
return true
|
||||
} else {
|
||||
message.error(msg.retmsg)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<PageContainer
|
||||
header={{
|
||||
title: '',
|
||||
}}
|
||||
footer={[
|
||||
<Button
|
||||
key="back"
|
||||
onClick={() => {
|
||||
history.back();
|
||||
}}
|
||||
>
|
||||
返回
|
||||
</Button>,
|
||||
<Button type="primary" key="submit" onClick={onSave}>
|
||||
保存
|
||||
</Button>
|
||||
]}
|
||||
>
|
||||
<ProForm layout="horizontal" labelAlign="left" formRef={formRef} onFinish={onSubmit} submitter={false}>
|
||||
<ProCard title="基本信息" style={{ marginBottom: 12 }}>
|
||||
<Row gutter={20}>
|
||||
<Col span={8}>
|
||||
<ProFormText label="名称" name="pbcProductTitle" rules={[
|
||||
{ required: true, message: '请输入商品名称' },
|
||||
]} />
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<ProFormSelect label="商户类别" name="pbcBusinessType" valueEnum={Constants.pbcBusinessType} rules={[
|
||||
{ required: true, message: '请选择商户类别' },
|
||||
]} />
|
||||
</Col>
|
||||
{/* <Col span={8}>
|
||||
<ProFormSwitch label="商户状态" name="pbcState" fieldProps={{ checkedChildren: '启用', unCheckedChildren: '禁用' }} />
|
||||
</Col> */}
|
||||
</Row>
|
||||
<Row gutter={20}>
|
||||
<Col span={8}>
|
||||
<ProFormText label="联系人" name="pbcBusinessContact" rules={[
|
||||
{ required: true, message: '请输入联系人' },
|
||||
]} />
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<ProFormText label="手机号" name="pbcBusinessContactMobile" rules={[
|
||||
{ required: true, message: '请输入手机号' },
|
||||
{ pattern: Constants.PHONE_PATTERN, message: '请输入正确的手机号' },
|
||||
]} />
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<ProFormSelect label="商户等级" name="pbcBusinessLevel" options={['1级', '2级', '3级', '4级', '5级']} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={20}>
|
||||
<Col span={8}>
|
||||
<ProFormText label="邮箱" name="pbcBusinessEmail" rules={[
|
||||
{ required: true, message: '请输入邮箱' },
|
||||
{ pattern: Constants.EMAIL_PATTERN, message: '请输入正确的邮箱' },
|
||||
]} />
|
||||
</Col>
|
||||
<Col span={16}>
|
||||
<ProFormTextArea label="商户简介" name="pbcBusinessIntroduction" rules={[
|
||||
{ required: true, message: '请输入简介' },
|
||||
]} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={20}>
|
||||
<Col span={8}>
|
||||
<ProFormCascader label="省市区" name="pbcZone" fieldProps={{ options: cities }} rules={[
|
||||
{ required: true, message: '请选择省市区' },
|
||||
]} />
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<ProFormTextArea label="详细地址" name="pbcBusinessAddress" rules={[
|
||||
{ required: true, message: '请输入详细地址' },
|
||||
]} />
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<ProFormText label="门牌号" name="pbcBusinessDoorLabel" />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={20}>
|
||||
<Col span={24}>
|
||||
<ProFormUploadButton
|
||||
label="商户LOGO"
|
||||
name="pbcBusinessLogo"
|
||||
fieldProps={{
|
||||
name: 'file',
|
||||
accept: 'image/*',
|
||||
headers: {
|
||||
authorization: localStorage.getItem('token') ?? '',
|
||||
},
|
||||
action: '/oss/imgUpload',
|
||||
beforeUpload(file: RcFile) {
|
||||
const isLt2M = file.size / 1024 / 1024 < 10;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过10MB!');
|
||||
}
|
||||
return isLt2M || Upload.LIST_IGNORE;
|
||||
},
|
||||
onPreview: async (file) => {
|
||||
|
||||
if (file.uid === '-1') {
|
||||
window.open(file.url);
|
||||
}
|
||||
if (file.response && file.response.retcode) {
|
||||
window.open(file.response.data);
|
||||
}
|
||||
},
|
||||
listType: 'picture-card',
|
||||
}}
|
||||
rules={[
|
||||
{ required: true, message: '请上传商户LOGO' },
|
||||
]}
|
||||
max={1}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={20}>
|
||||
<Col span={24}>
|
||||
<ProFormUploadButton
|
||||
label="商户图片"
|
||||
name="pbcBusinessImage"
|
||||
fieldProps={{
|
||||
name: 'file',
|
||||
accept: 'image/*',
|
||||
headers: {
|
||||
authorization: localStorage.getItem('token') ?? '',
|
||||
},
|
||||
action: '/oss/imgUpload',
|
||||
beforeUpload(file: RcFile) {
|
||||
const isLt2M = file.size / 1024 / 1024 < 10;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过10MB!');
|
||||
}
|
||||
return isLt2M || Upload.LIST_IGNORE;
|
||||
},
|
||||
onPreview: async (file) => {
|
||||
|
||||
if (file.uid === '-1') {
|
||||
window.open(file.url);
|
||||
}
|
||||
if (file.response && file.response.retcode) {
|
||||
window.open(file.response.data);
|
||||
}
|
||||
},
|
||||
listType: 'picture-card',
|
||||
}}
|
||||
rules={[
|
||||
{ required: true, message: '请上传商户图片' },
|
||||
]}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={20}>
|
||||
<Col span={24}>
|
||||
<ProFormUploadButton
|
||||
label="商户海报"
|
||||
name="pbcBusinessPosterUrl"
|
||||
fieldProps={{
|
||||
name: 'file',
|
||||
accept: 'image/*',
|
||||
headers: {
|
||||
authorization: localStorage.getItem('token') ?? '',
|
||||
},
|
||||
action: '/oss/imgUpload',
|
||||
beforeUpload(file: RcFile) {
|
||||
const isLt2M = file.size / 1024 / 1024 < 10;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过10MB!');
|
||||
}
|
||||
return isLt2M || Upload.LIST_IGNORE;
|
||||
},
|
||||
onPreview: async (file) => {
|
||||
|
||||
if (file.uid === '-1') {
|
||||
window.open(file.url);
|
||||
}
|
||||
if (file.response && file.response.retcode) {
|
||||
window.open(file.response.data);
|
||||
}
|
||||
},
|
||||
listType: 'picture-card',
|
||||
}}
|
||||
rules={[
|
||||
{ required: true, message: '请上传商户海报' },
|
||||
]}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</ProCard>
|
||||
</ProForm>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Detail;
|
Loading…
Reference in New Issue