import { useState } from 'react' import { Table, Form, Modal, Typography, Button, Radio, Input, Flex, Card, InputNumber, Checkbox, DatePicker, Space, App, Tooltip } from 'antd' import { useTranslation } from 'react-i18next' import { CloseOutlined, StarTwoTone, PlusOutlined, ExclamationCircleFilled, QuestionCircleOutlined, QuestionOutlined } from '@ant-design/icons' import { useDatePresets } from '@/hooks/useDatePresets' import dayjs from 'dayjs' import useProductsStore from '@/stores/Products/Index' import PriceCompactInput from '@/views/products/Detail/PriceCompactInput' const { RangePicker } = DatePicker const batchSetupInitialValues = { 'defList': [ // 旺季 { 'useDateList': [ { 'useDate': [ dayjs().add(1, 'year').startOf('y'), dayjs().add(1, 'year').endOf('y') ] } ], 'unitId': '0', 'currency': 'RMB', 'weekend': [ ], 'priceList': [ { 'priceInput': { 'numberStart': 1, 'numberEnd': 2, 'audultPrice': 0, 'childrenPrice': 0 } }, { 'priceInput': { 'numberStart': 3, 'numberEnd': 4, 'audultPrice': 0, 'childrenPrice': 0 } }, { 'priceInput': { 'numberStart': 5, 'numberEnd': 6, 'audultPrice': 0, 'childrenPrice': 0 } }, { 'priceInput': { 'numberStart': 7, 'numberEnd': 9, 'audultPrice': 0, 'childrenPrice': 0 } } ] }, // 淡季 { 'useDateList': [ { 'useDate': [ dayjs().add(1, 'year').subtract(2, 'M').startOf('M'), dayjs().add(1, 'year').endOf('M') ] } ], 'unitId': '0', 'currency': 'RMB', 'weekend': [ ], 'priceList': [ { 'priceInput': { 'numberStart': 1, 'numberEnd': 2, 'audultPrice': 0, 'childrenPrice': 0 } }, { 'priceInput': { 'numberStart': 3, 'numberEnd': 4, 'audultPrice': 0, 'childrenPrice': 0 } }, { 'priceInput': { 'numberStart': 5, 'numberEnd': 6, 'audultPrice': 0, 'childrenPrice': 0 } }, { 'priceInput': { 'numberStart': 7, 'numberEnd': 9, 'audultPrice': 0, 'childrenPrice': 0 } } ] } ] } const defaultPriceValue = { 'priceInput': { 'numberStart': 1, 'numberEnd': 2, 'audultPrice': 0, 'childrenPrice': 0 } } const defaultUseDate = { 'useDate': [dayjs().add(1, 'year').startOf('y'), dayjs().add(1, 'year').endOf('y')] } const defaultDefinitionValue = { 'useDateList': [defaultUseDate], 'unitId': '0', 'currency': 'RMB', 'weekend': [], 'priceList': [defaultPriceValue] } const ProductInfoQuotation = ({ editable, ...props }) => { const { onChange } = props const { t } = useTranslation() const [isQuotationModalOpen, setQuotationModalOpen] = useState(false) const [isBatchSetupModalOpen, setBatchSetupModalOpen] = useState(false) const { modal, notification } = App.useApp(); const [quotationForm] = Form.useForm() const [batchSetupForm] = Form.useForm() const datePresets = useDatePresets() const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotation] = useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotation]) const triggerChange = (changedValue) => { onChange?.( changedValue ) } const onQuotationSeleted = async (quotation) => { // 把 start, end 转换为 RangePicker 数组格式 quotation.use_dates = [dayjs(quotation.use_dates_start), dayjs(quotation.use_dates_end)] quotation.weekdayList = quotation.weekdays.split(',') quotationForm.setFieldsValue(quotation) setQuotationModalOpen(true) } const onNewQuotation = () => { const emptyQuotation = newEmptyQuotation() quotationForm.setFieldsValue(emptyQuotation) setQuotationModalOpen(true) } const onQuotationFinish = (values) => { const newList = saveOrUpdateQuotation(values) triggerChange(newList) setQuotationModalOpen(false) } const onBatchSetupFinish = () => { const defList = batchSetupForm.getFieldsValue().defList const newList = appendQuotationList(defList) triggerChange(newList) setBatchSetupModalOpen(false) } const onDeleteQuotation = (quotation) => { modal.confirm({ title: '请确认', icon: , content: '你要删除这条价格吗?', onOk() { deleteQuotation(quotation) .catch(ex => { notification.error({ message: 'Notification', description: ex.message, placement: 'top', duration: 4, }) }) }, }) } const quotationColumns = [ { title: 'id', dataIndex: 'id', width: 40, className: 'italic text-gray-400' }, // test: 0 { title: 'WPI_SN', dataIndex: 'WPI_SN', width: 40, className: 'italic text-gray-400' }, // test: 0 { title: t('products:adultPrice'), dataIndex: 'adult_cost', width: '5rem' }, { title: t('products:childrenPrice'), dataIndex: 'child_cost', width: '5rem' }, { title: t('products:currency'), dataIndex: 'currency', width: '4rem' }, { title: t('products:unit_name'), dataIndex: 'unit_id', width: '4rem', render: (text) => t(`products:PriceUnit.${text}`), // (text === '0' ? '每人' : text === '1' ? '每团' : text), }, { title: t('products:group_size'), dataIndex: 'group_size', width: '4rem', render: (_, record) => `${record.group_size_min}-${record.group_size_max}`, }, { title: (<>{t('products:use_dates')} ), dataIndex: 'use_dates', // width: '6rem', render: (_, record) => `${record.use_dates_start}-${record.use_dates_end}`, }, { title: t('products:Weekdays'), dataIndex: 'weekdays', width: '4rem' }, { title: t('products:operation'), dataIndex: 'operation', width: '10rem', render: (_, quotation) => { // const _rowEditable = [-1,3].includes(quotation.audit_state_id); const _rowEditable = true; // test: 0 return ( ) }, }, ] return ( <>

{t('products:EditComponents.Quotation')}

{ editable && } onBatchSetupFinish()} onCancel={() => setBatchSetupModalOpen(false)} destroyOnClose forceRender >
{(fields, { add, remove }) => ( {fields.map((field, index) => ( : { remove(field.name) }} />} > RMB USD THB JPY 每人 每团 {(useDateFieldList, useDateOptList) => ( {useDateFieldList.map((useDateField, index) => ( {index == 0 ? : useDateOptList.remove(useDateField.name)} />} ))} )} {(priceFieldList, priceOptList) => ( {priceFieldList.map((priceField, index) => ( {index == 0 ? : priceOptList.remove(priceField.name)} />} ))} )} ))} )} {() => (
{JSON.stringify(batchSetupForm.getFieldsValue(), null, 2)}
)}
setQuotationModalOpen(false)} destroyOnClose forceRender modalRender={(dom) => (
{dom} )} > RMB USD THB JPY 每人 每团
) } export default ProductInfoQuotation