|
|
@@ -1,9 +1,8 @@ |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import { Form, Input, InputNumber, Radio, Modal, Select, DatePicker } from 'antd'; |
|
|
|
import tenantService from '@/request/service/tenant'; |
|
|
|
import tenantPkgService from '@/request/service/tenant-package'; |
|
|
|
import React, { useEffect, useState } from 'react'; |
|
|
|
import { Form, Input, InputNumber, Radio, Modal, Steps, DatePicker, Button } from 'antd'; |
|
|
|
import platformShopService from '@/request/service/platform-shop'; |
|
|
|
import { useRequest } from '@/hooks/use-request'; |
|
|
|
import type { TenantVO } from '@/models' |
|
|
|
import type { PlatformShop } from '@/models' |
|
|
|
import { antdUtils } from '@/utils/antd'; |
|
|
|
import customParseFormat from 'dayjs/plugin/customParseFormat'; |
|
|
|
|
|
|
@@ -19,45 +18,56 @@ const layout = { |
|
|
|
interface EditorProps { |
|
|
|
visible: boolean; |
|
|
|
onCancel: (flag?: boolean) => void; |
|
|
|
onSave: (role: TenantVO) => void; |
|
|
|
data?: TenantVO | null; |
|
|
|
onSave: (role: PlatformShop) => void; |
|
|
|
data?: PlatformShop | null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const TenantEditor: React.FC<EditorProps> = (props) => { |
|
|
|
|
|
|
|
const { visible, onCancel, onSave, data } = props; |
|
|
|
|
|
|
|
const { runAsync: updateApi } = useRequest(tenantService.updateTenantApi, { manual: true }); |
|
|
|
const { runAsync: createApi } = useRequest(tenantService.createTenantApi, { manual: true }); |
|
|
|
const { data: tenanPackages, run: getTenantPackageList } = useRequest(tenantPkgService.getTenantPackageList, { manual: true }); |
|
|
|
const { runAsync: updateApi } = useRequest(platformShopService.updatePlatformShop, { manual: true }); |
|
|
|
const { runAsync: createApi } = useRequest(platformShopService.createPlatformShop, { manual: true }); |
|
|
|
|
|
|
|
const isEdit = !!data; |
|
|
|
|
|
|
|
const [current, setCurrent] = useState(0); |
|
|
|
|
|
|
|
const next = async () => { |
|
|
|
const isValidate = await form.validateFields(); |
|
|
|
console.log(isValidate) |
|
|
|
setCurrent(current + 1); |
|
|
|
}; |
|
|
|
|
|
|
|
const prev = () => { |
|
|
|
setCurrent(current - 1); |
|
|
|
}; |
|
|
|
const [saveLoading, setSaveLoading] = useState(false); |
|
|
|
const [form] = Form.useForm(); |
|
|
|
const [shopForm] = Form.useForm(); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (visible) { |
|
|
|
if (data) { |
|
|
|
form.setFieldsValue(data); |
|
|
|
form.setFieldValue('expireTime', dayjs(data.expireTime)) |
|
|
|
form.setFieldValue('expiresTime', dayjs(data.expiresTime)); |
|
|
|
shopForm.setFieldsValue(data.shopConfig); |
|
|
|
} else { |
|
|
|
form.setFieldValue("shopStatus", 0); |
|
|
|
} |
|
|
|
} else { |
|
|
|
form.resetFields(); |
|
|
|
shopForm.resetFields(); |
|
|
|
} |
|
|
|
}, [visible]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
getTenantPackageList() |
|
|
|
}, [getTenantPackageList]) |
|
|
|
|
|
|
|
const save = async () => { |
|
|
|
await shopForm.validateFields(); |
|
|
|
setSaveLoading(true); |
|
|
|
const fieldValues = form.getFieldsValue(); |
|
|
|
const expireTime = dayjs(form.getFieldValue('expireTime')).toDate().getTime() |
|
|
|
const newValue = isEdit ? { ...data, ...fieldValues, expireTime } : {...fieldValues, expireTime}; |
|
|
|
const expireTime = dayjs(form.getFieldValue('expiresTime')).toDate().getTime(); |
|
|
|
const shopFieldValues = shopForm.getFieldsValue(); |
|
|
|
const newValue = isEdit ? { ...data, ...fieldValues, expireTime, shopConfig: { ...shopFieldValues } } : { ...fieldValues, expireTime, shopConfig: { ...shopFieldValues } }; |
|
|
|
const [error, { msg, code }] = isEdit ? await updateApi(newValue) : await createApi(newValue); |
|
|
|
if (!error && code === 0) { |
|
|
|
onSave(newValue); |
|
|
@@ -74,85 +84,63 @@ const TenantEditor: React.FC<EditorProps> = (props) => { |
|
|
|
<> |
|
|
|
<Modal |
|
|
|
open={visible} |
|
|
|
title="新建" |
|
|
|
title={isEdit ? "编辑" : "新建"} |
|
|
|
width={640} |
|
|
|
onOk={save} |
|
|
|
onCancel={() => onCancel()} |
|
|
|
confirmLoading= {saveLoading} |
|
|
|
footer={null} |
|
|
|
confirmLoading={saveLoading} |
|
|
|
destroyOnClose |
|
|
|
> |
|
|
|
<Steps className="my-5" current={current} items={[ |
|
|
|
{ |
|
|
|
title: '商户设置' |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '平台店铺配置', |
|
|
|
} |
|
|
|
]} /> |
|
|
|
|
|
|
|
<Form |
|
|
|
form={form} |
|
|
|
{...layout} |
|
|
|
onFinish={save} |
|
|
|
labelCol={{ flex: '0 0 100px' }} |
|
|
|
wrapperCol={{ span: 16 }} |
|
|
|
> |
|
|
|
<Form.Item name="name" label="租户名称" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请输入租户名称', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item name="packageId" label="租户套餐" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请选择租户套餐', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Select placeholder="请选择租户套餐" options={tenanPackages?.data.map(item => { |
|
|
|
return { |
|
|
|
label: item.name, |
|
|
|
value: item.id, |
|
|
|
} |
|
|
|
})}> |
|
|
|
</Select> |
|
|
|
</Form.Item> |
|
|
|
hidden={current === 1} |
|
|
|
|
|
|
|
|
|
|
|
<Form.Item name="contactName" label="联系人" |
|
|
|
> |
|
|
|
<Form.Item name="shopName" label="店铺名称" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请输入联系人', |
|
|
|
message: '请输入店铺名称', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
|
|
|
<Form.Item name="contactMobile" label="联系电话" |
|
|
|
<Form.Item name="platformId" label="平台" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请输入电话号码', |
|
|
|
message: '请选择', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item name="username" label="用户名称"> |
|
|
|
<Form.Item name="userName" label="账号"> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item name="password" label="用户密码"> |
|
|
|
<Form.Item name="password" label="密码"> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item name="accountCount" label="账号额度" > |
|
|
|
<InputNumber min={0} /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item name="expireTime" label="过期时间" |
|
|
|
<Form.Item name="expiresTime" label="过期时间" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
@@ -162,30 +150,62 @@ const TenantEditor: React.FC<EditorProps> = (props) => { |
|
|
|
<DatePicker showTime format="YYYY-MM-DD HH:mm:ss" /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item name="domain" label="绑定域名" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请输入绑定域名', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input /> |
|
|
|
<Form.Item name="shopStatus" label="状态" rules={[{ |
|
|
|
required: true, |
|
|
|
message: '请设置状态', |
|
|
|
},]}> |
|
|
|
<Radio.Group options={[ |
|
|
|
{ value: 0, label: "开启" }, |
|
|
|
{ value: 1, label: "关闭" } |
|
|
|
]} optionType="default"> |
|
|
|
</Radio.Group> |
|
|
|
</Form.Item> |
|
|
|
</Form> |
|
|
|
|
|
|
|
<Form.Item name="status" label="租户状态" rules={[ |
|
|
|
<Form |
|
|
|
form={shopForm} |
|
|
|
{...layout} |
|
|
|
onFinish={save} |
|
|
|
labelCol={{ flex: '0 0 100px' }} |
|
|
|
wrapperCol={{ span: 16 }} |
|
|
|
hidden={current === 0} |
|
|
|
> |
|
|
|
<Form.Item name="shopId" label="店铺" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请选择租户状态', |
|
|
|
message: '请设置店铺', |
|
|
|
}, |
|
|
|
]}> |
|
|
|
<Radio.Group options={[ |
|
|
|
{ value: 0, label: "开启" }, |
|
|
|
{ value: 1, label: "关闭" } |
|
|
|
]} optionType="default"> |
|
|
|
</Radio.Group> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="iossNo" label="欧盟税号"> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="vat" label="vat税号"> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="language" label="语言"> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="dayMaxPublishNumber" label="最大刊登量"> |
|
|
|
<InputNumber min={0} /> |
|
|
|
</Form.Item> |
|
|
|
</Form> |
|
|
|
|
|
|
|
<div className='flex justify-end'> |
|
|
|
{ |
|
|
|
(current === 0 ? |
|
|
|
(<Button type='primary' size='large' onClick={next}> 下一步 </Button>) : |
|
|
|
( |
|
|
|
<> |
|
|
|
<Button size='large' onClick={prev} disabled={saveLoading}> 上一步 </Button> |
|
|
|
<Button type='primary' size='large' className='ml-2' onClick={save}> 提交 </Button> |
|
|
|
</> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
</div> |
|
|
|
</Modal> |
|
|
|
</> |
|
|
|
) |
|
|
|