完成批量价格生成和预览

perf/export-docx
Jimmy Liow 1 year ago
parent cae1a8774a
commit 2b9a365c45

@ -1217,7 +1217,7 @@ function Detail() {
open={batchImportPriceVisible} open={batchImportPriceVisible}
onOk={handleBatchImportOK} onOk={handleBatchImportOK}
onCancel={() => setBatchImportPriceVisible(false)} onCancel={() => setBatchImportPriceVisible(false)}
width={620} width={'90%'}
> >
<BatchImportPrice onBatchImportData={handleBatchImportData} /> <BatchImportPrice onBatchImportData={handleBatchImportData} />
</Modal> </Modal>

@ -1,14 +1,70 @@
import { useState } from 'react'; import { useState } from 'react';
import { Button, Card, Checkbox, Col, Flex, DatePicker, Typography, Form, Input, Row, Select, Space } from 'antd'; import { Button, Card, Checkbox, Table, Col, Flex, DatePicker, Typography, Form, Input, Row, Select, Space } from 'antd';
import dayjs from "dayjs"; import dayjs from "dayjs";
import { CloseOutlined } from '@ant-design/icons'; import { useTranslation } from 'react-i18next';
import { CloseOutlined, StarOutlined } from '@ant-design/icons';
import { useDatePresets } from '@/hooks/useDatePresets'; import { useDatePresets } from '@/hooks/useDatePresets';
const { Option } = Select; const { Option } = Select;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const BatchImportPrice = ({ onBatchImportData }) => { const BatchImportPrice = ({ onBatchImportData }) => {
const [priceForm] = Form.useForm(); const { t } = useTranslation()
const presets = useDatePresets();
const previewTableColumns = [
{ title: t('products:adultPrice'), dataIndex: 'adult_cost', width: '10%' },
{ title: t('products:childrenPrice'), dataIndex: 'child_cost', width: '10%' },
{ title: t('products:currency'), dataIndex: 'currency', width: '10%' },
{
title: t('products:Types'),
dataIndex: 'unit',
width: '10%',
editable: true,
render: (text) => (text === '0' ? '每人' : text === '1' ? '每团' : text),
},
{
title: t('products:number'),
dataIndex: 'group_size',
width: '10%',
editable: true,
render: (_, record) => `${record.group_size_min}-${record.group_size_max}`
},
{
title: t('products:validityPeriod'),
dataIndex: 'validityPeriod',
width: '20%',
editable: true,
render: (_, record) => dayjs(record.use_dates_start).format('YYYY-MM-DD') + '~' + dayjs(record.use_dates_end).format('YYYY-MM-DD')
},
{ title: t('products:Weekdays'), dataIndex: 'weekdays', width: '10%' },
]
const [priceForm] = Form.useForm()
const [previewData, setPreviewData] = useState([])
const presets = useDatePresets()
const previewSetupPrice = () => {
let previewList = []
const defList = priceForm.getFieldsValue().defList
defList.forEach(definition => {
const previewPrice = definition?.priceList.map(price => {
return {
adult_cost: price.priceInput.audultPrice,
child_cost: price.priceInput.childrenPrice,
group_size_min: price.priceInput.numberStart,
group_size_max: price.priceInput.numberEnd,
currency: definition.currency,
unit: definition.unitName,
use_dates_start: definition.useDate[0],
use_dates_end: definition.useDate[1],
weekdays: definition.weekend.join(','),
}
})
previewList.push(...previewPrice)
})
setPreviewData(previewList)
}
const PriceInput = (props) => { const PriceInput = (props) => {
const { id, value = {}, onChange } = props const { id, value = {}, onChange } = props
@ -116,7 +172,7 @@ const BatchImportPrice = ({ onBatchImportData }) => {
} }
const priceInitialValues = { const priceInitialValues = {
"items": [ "defList": [
// //
{ {
"useDate": [ "useDate": [
@ -128,7 +184,7 @@ const BatchImportPrice = ({ onBatchImportData }) => {
"5", "5",
"6" "6"
], ],
"prieceList": [ "priceList": [
{ {
"priceInput": { "priceInput": {
"numberStart": 1, "numberStart": 1,
@ -170,13 +226,11 @@ const BatchImportPrice = ({ onBatchImportData }) => {
], ],
"unitName": "每人", "unitName": "每人",
"currency": "CNY", "currency": "CNY",
"weekend": [ "weekend": [
"5", "5",
"6" "6"
], ],
"priceList": [
"prieceList": [
{ {
"priceInput": { "priceInput": {
"numberStart": 1, "numberStart": 1,
@ -216,7 +270,7 @@ const BatchImportPrice = ({ onBatchImportData }) => {
return ( return (
<Row gutter={16} justify="center"> <Row gutter={16} justify="center">
<Col span={24}> <Col span={12}>
<Form <Form
labelCol={{ span: 3 }} labelCol={{ span: 3 }}
wrapperCol={{ span: 20 }} wrapperCol={{ span: 20 }}
@ -225,7 +279,7 @@ const BatchImportPrice = ({ onBatchImportData }) => {
autoComplete="off" autoComplete="off"
initialValues={priceInitialValues} initialValues={priceInitialValues}
> >
<Form.List name="items"> <Form.List name="defList">
{(fields, { add, remove }) => ( {(fields, { add, remove }) => (
<Flex gap="middle" vertical> <Flex gap="middle" vertical>
{fields.map((field, index) => ( {fields.map((field, index) => (
@ -259,15 +313,15 @@ const BatchImportPrice = ({ onBatchImportData }) => {
/> />
</Form.Item> </Form.Item>
<Form.Item label="人等"> <Form.Item label="人等">
<Form.List name={[field.name, 'prieceList']}> <Form.List name={[field.name, 'priceList']}>
{(prieceFieldList, priceOptList) => ( {(priceFieldList, priceOptList) => (
<Flex gap="middle" vertical> <Flex gap="middle" vertical>
{prieceFieldList.map((priceField) => ( {priceFieldList.map((priceField, index) => (
<Space key={priceField.key}> <Space key={priceField.key}>
<Form.Item noStyle name={[priceField.name, 'priceInput']}> <Form.Item noStyle name={[priceField.name, 'priceInput']}>
<PriceInput /> <PriceInput />
</Form.Item> </Form.Item>
<CloseOutlined onClick={() => priceOptList.remove(priceField.name)} /> {index==0?<StarOutlined />:<CloseOutlined onClick={() => priceOptList.remove(priceField.name)} />}
</Space> </Space>
))} ))}
<Button type="dashed" onClick={() => priceOptList.add()} block> <Button type="dashed" onClick={() => priceOptList.add()} block>
@ -294,6 +348,17 @@ const BatchImportPrice = ({ onBatchImportData }) => {
</Form.Item> </Form.Item>
</Form> </Form>
</Col> </Col>
<Col span={12}>
<Button type="dashed" onClick={() => previewSetupPrice()} block>
预览
</Button>
<Table
bordered
pagination={false}
dataSource={previewData}
columns={previewTableColumns}
/>
</Col>
</Row> </Row>
); );
}; };

Loading…
Cancel
Save