|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { Button, Card, Checkbox, Col, DatePicker, Form, Input, Row, Select, Space, Tag, Table, InputNumber } from 'antd';
|
|
|
|
|
import { CloseOutlined } from '@ant-design/icons';
|
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
|
|
|
|
@ -13,6 +14,11 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
const [tableData, setTableData] = useState([]);
|
|
|
|
|
const [sendData, setSendData] = useState(null);
|
|
|
|
|
|
|
|
|
|
// 获取当前年份
|
|
|
|
|
const currentYear = new Date().getFullYear();
|
|
|
|
|
const startOfYear = dayjs(new Date(currentYear, 0, 1));
|
|
|
|
|
const endOfYear = dayjs(new Date(currentYear, 11, 31));
|
|
|
|
|
|
|
|
|
|
const handleTagClose = (removedTag) => {
|
|
|
|
|
setTags(tags.filter(tag => tag !== removedTag));
|
|
|
|
|
};
|
|
|
|
@ -33,22 +39,21 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const generateTableData = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const values = form.getFieldsValue();
|
|
|
|
|
const weekdays = checkedDays.join(',');
|
|
|
|
|
let tempSendData = [];
|
|
|
|
|
|
|
|
|
|
console.log("values",values)
|
|
|
|
|
// 遍历 items
|
|
|
|
|
values.items.forEach((item) => {
|
|
|
|
|
values.items.forEach((item, index) => {
|
|
|
|
|
// 遍历 validPeriods
|
|
|
|
|
let tempValidPeriods = []
|
|
|
|
|
item.validPeriods?.forEach((period) => {
|
|
|
|
|
console.log("period",period)
|
|
|
|
|
const validPeriod = period.validPeriod.map(date => date.format('YYYY-MM-DD')).join('~');
|
|
|
|
|
tempValidPeriods.push(validPeriod)
|
|
|
|
|
// 更新 tempSendData 中每一个 tag 的值
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const priceType = `批量设置价格 ${index + 1} ${item.currency}/${item.type}`
|
|
|
|
|
let tempData = []
|
|
|
|
|
const unit_name = item.type
|
|
|
|
|
const currency = item.currency
|
|
|
|
@ -59,14 +64,15 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
let unit_id = null
|
|
|
|
|
const use_dates_start = validPeriod.split('~')[0]
|
|
|
|
|
const use_dates_end = validPeriod.split('~')[1]
|
|
|
|
|
if(unit_name === "每人"){
|
|
|
|
|
if (unit_name === "每人") {
|
|
|
|
|
unit_id = 0
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
unit_id = 1
|
|
|
|
|
}
|
|
|
|
|
tempData.push({group_size_min, group_size_max,validPeriod, unit_id,unit_name,use_dates_start,use_dates_end, currency, weekdays,tag})
|
|
|
|
|
tempData.push({ group_size_min, group_size_max, validPeriod, unit_id, unit_name, use_dates_start, use_dates_end, currency, weekdays, tag, priceType })
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
console.log("tempData", tempData)
|
|
|
|
|
tempSendData.push(...tempData)
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
@ -90,15 +96,21 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
data.push(row);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
// setSendData([...tempSendData,data]);
|
|
|
|
|
setTableData(data);
|
|
|
|
|
onBatchImportData(data); // 将生成的初始表格数据传递回父组件
|
|
|
|
|
// onBatchImportData(data); // 将生成的初始表格数据传递回父组件
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleTableChange = (age_type, value, tag, validPeriod) => {
|
|
|
|
|
|
|
|
|
|
const handleTableChange = (age_type, value, tag, priceType) => {
|
|
|
|
|
if (age_type === 'adult_cost') {
|
|
|
|
|
console.log("sendData", sendData)
|
|
|
|
|
const updatedSendData = sendData.map((item) => {
|
|
|
|
|
if (item.validPeriod === validPeriod && item.tag === tag) {
|
|
|
|
|
console.log("item.priceType === priceType", item.priceType === priceType)
|
|
|
|
|
console.log("item.priceType", item.priceType)
|
|
|
|
|
console.log("priceType", priceType)
|
|
|
|
|
if (item.priceType === priceType && item.tag === tag) {
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
adult_cost: value, // 更新对应的 adult_cost 属性
|
|
|
|
@ -106,12 +118,13 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
}
|
|
|
|
|
return item; // 对于不匹配的项,保持不变
|
|
|
|
|
});
|
|
|
|
|
// 更新 sendDataole
|
|
|
|
|
// 更新 sendData
|
|
|
|
|
console.log("updatedSendData", updatedSendData)
|
|
|
|
|
onBatchImportData(updatedSendData);
|
|
|
|
|
setSendData(updatedSendData);
|
|
|
|
|
} else {
|
|
|
|
|
const updatedSendData = sendData.map((item) => {
|
|
|
|
|
if (item.validPeriod === validPeriod && item.tag === tag) {
|
|
|
|
|
if (item.priceType === priceType && item.tag === tag) {
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
child_cost: value, // 更新对应的 child_cost 属性
|
|
|
|
@ -123,9 +136,9 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
onBatchImportData(updatedSendData);
|
|
|
|
|
setSendData(updatedSendData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const generatePeopleColumns = () => {
|
|
|
|
|
const columns = [];
|
|
|
|
|
tags.forEach((tag, index) => {
|
|
|
|
@ -136,25 +149,61 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
title: '成人价',
|
|
|
|
|
dataIndex: `adultPrice${index + 1}`,
|
|
|
|
|
key: `adultPrice${index + 1}`,
|
|
|
|
|
render: (text, record) => (
|
|
|
|
|
render: (text, record, rowIndex) => {
|
|
|
|
|
const sameTagRecords = tableData.filter(item => item.priceType === record.priceType);
|
|
|
|
|
const firstTagIndex = tableData.findIndex(item => item.priceType === record.priceType && item.validPeriod === sameTagRecords[0].validPeriod);
|
|
|
|
|
|
|
|
|
|
if (rowIndex === firstTagIndex) {
|
|
|
|
|
return {
|
|
|
|
|
children: (
|
|
|
|
|
<InputNumber
|
|
|
|
|
formatter={value => `${value}`}
|
|
|
|
|
parser={value => value.replace(/[^\d]/g, '')}
|
|
|
|
|
onChange={(value) => handleTableChange('adult_cost', value, tag, record.validPeriod)}
|
|
|
|
|
onChange={(value) => handleTableChange('adult_cost', value, tag, record.priceType)}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
props: {
|
|
|
|
|
rowSpan: sameTagRecords.length,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
props: {
|
|
|
|
|
rowSpan: 0,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '儿童价',
|
|
|
|
|
dataIndex: `childrenPrice${index + 1}`,
|
|
|
|
|
key: `childrenPrice${index + 1}`,
|
|
|
|
|
render: (text, record) => (
|
|
|
|
|
render: (text, record, rowIndex) => {
|
|
|
|
|
const sameTagRecords = tableData.filter(item => item.priceType === record.priceType);
|
|
|
|
|
const firstTagIndex = tableData.findIndex(item => item.priceType === record.priceType && item.validPeriod === sameTagRecords[0].validPeriod);
|
|
|
|
|
|
|
|
|
|
if (rowIndex === firstTagIndex) {
|
|
|
|
|
return {
|
|
|
|
|
children: (
|
|
|
|
|
<InputNumber
|
|
|
|
|
formatter={value => `${value}`}
|
|
|
|
|
parser={value => value.replace(/[^\d]/g, '')}
|
|
|
|
|
onChange={(value) => handleTableChange('child_cost', value, tag, record.validPeriod)}
|
|
|
|
|
onChange={(value) => handleTableChange('child_cost', value, tag, record.priceType)}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
props: {
|
|
|
|
|
rowSpan: sameTagRecords.length,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
props: {
|
|
|
|
|
rowSpan: 0,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
@ -162,6 +211,7 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
return columns;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
{
|
|
|
|
|
title: ' ',
|
|
|
|
@ -280,8 +330,10 @@ const BatchImportPrice = ({ onBatchImportData }) => {
|
|
|
|
|
<div style={{ display: 'flex', flexDirection: 'column', rowGap: 16 }}>
|
|
|
|
|
{periodFields.map((periodField, idx) => (
|
|
|
|
|
<Space key={periodField.key}>
|
|
|
|
|
<Form.Item noStyle name={[periodField.name, 'validPeriod']}>
|
|
|
|
|
<RangePicker />
|
|
|
|
|
<Form.Item noStyle name={[periodField.name, 'validPeriod']} initialValue={[startOfYear, endOfYear]}>
|
|
|
|
|
<RangePicker
|
|
|
|
|
defaultValue={[startOfYear, endOfYear]}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<CloseOutlined onClick={() => periodOpt.remove(periodField.name)} />
|
|
|
|
|
</Space>
|
|
|
|
|