diff --git a/src/views/account/Management.jsx b/src/views/account/Management.jsx index 7e51825..e6030c4 100644 --- a/src/views/account/Management.jsx +++ b/src/views/account/Management.jsx @@ -231,7 +231,7 @@ function Management() { }} title={t('account:detail')} open={isAccountModalOpen} onCancel={() => setAccountModalOpen(false)} - destroyOnClose + destroyOnHidden forceRender modalRender={(dom) => (
setRoleModalOpen(false)} - destroyOnClose + destroyOnHidden forceRender modalRender={(dom) => ( { open={isRemarksModalOpen} onOk={() => onRemarksFinish()} onCancel={() => setRemarksModalOpen(false)} - destroyOnClose + destroyOnHidden forceRender > [dayjs().year(year).startOf('y'), dayjs().year(year).endOf('y')] +const getYearRange = (year) => [ + dayjs().year(year).startOf("y"), + dayjs().year(year).endOf("y"), +]; const generateDefinitionValue = (year) => ({ - 'useDateList': [{'useDate': getYearRange(year)}], - 'unitId': '0', - 'currency': 'RMB', - 'weekend': [], - 'priceList': [defaultPriceValue] - }) + useDateList: [{ useDate: getYearRange(year) }], + unitId: "0", + currency: "RMB", + weekend: [], + priceList: [defaultPriceValue], +}); const ProductInfoQuotation = ({ editable, ...props }) => { + const { onChange } = props; - const { onChange } = props + const { t } = useTranslation(); - const { t } = useTranslation() - - const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotation, switchParams] = - useProductsStore((state) => [ - state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotation, - state.switchParams - ]) + const [ + quotationList, + newEmptyQuotation, + appendQuotationList, + saveOrUpdateQuotation, + deleteQuotation, + switchParams, + ] = useProductsStore((state) => [ + state.quotationList, + state.newEmptyQuotation, + state.appendQuotationList, + state.saveOrUpdateQuotation, + state.deleteQuotation, + state.switchParams, + ]); const batchSetupInitialValues = { - 'defList': [ + defList: [ // 全年 { - 'useDateList': [{'useDate': getYearRange(switchParams.use_year)}], - 'unitId': '0', - 'currency': 'RMB', - 'weekend': [], - 'priceList': [ + useDateList: [{ useDate: getYearRange(switchParams.use_year) }], + unitId: "0", + currency: "RMB", + weekend: [], + priceList: [ { - 'priceInput': { - 'numberStart': 1, - 'numberEnd': 2, - 'audultPrice': 0, - 'childrenPrice': 0 - } + priceInput: { + numberStart: 1, + numberEnd: 2, + audultPrice: 0, + childrenPrice: 0, + }, }, { - 'priceInput': { - 'numberStart': 3, - 'numberEnd': 4, - 'audultPrice': 0, - 'childrenPrice': 0 - } + priceInput: { + numberStart: 3, + numberEnd: 4, + audultPrice: 0, + childrenPrice: 0, + }, }, { - 'priceInput': { - 'numberStart': 5, - 'numberEnd': 6, - 'audultPrice': 0, - 'childrenPrice': 0 - } + priceInput: { + numberStart: 5, + numberEnd: 6, + audultPrice: 0, + childrenPrice: 0, + }, }, { - 'priceInput': { - 'numberStart': 7, - 'numberEnd': 9, - 'audultPrice': 0, - 'childrenPrice': 0 - } - } - ] + priceInput: { + numberStart: 7, + numberEnd: 9, + audultPrice: 0, + childrenPrice: 0, + }, + }, + ], }, // 特殊时间段 { - 'useDateList': [ + useDateList: [ { - 'useDate': [ - dayjs().year(switchParams.use_year).subtract(2, 'M').startOf('M'), dayjs().year(switchParams.use_year).endOf('M') - ] - } + useDate: [ + dayjs().year(switchParams.use_year).subtract(2, "M").startOf("M"), + dayjs().year(switchParams.use_year).endOf("M"), + ], + }, ], - 'unitId': '0', - 'currency': 'RMB', - 'weekend': [], - 'priceList': [ + unitId: "0", + currency: "RMB", + weekend: [], + priceList: [ { - 'priceInput': { - 'numberStart': 1, - 'numberEnd': 2, - 'audultPrice': 0, - 'childrenPrice': 0 - } + priceInput: { + numberStart: 1, + numberEnd: 2, + audultPrice: 0, + childrenPrice: 0, + }, }, { - 'priceInput': { - 'numberStart': 3, - 'numberEnd': 4, - 'audultPrice': 0, - 'childrenPrice': 0 - } + priceInput: { + numberStart: 3, + numberEnd: 4, + audultPrice: 0, + childrenPrice: 0, + }, }, { - 'priceInput': { - 'numberStart': 5, - 'numberEnd': 6, - 'audultPrice': 0, - 'childrenPrice': 0 - } + priceInput: { + numberStart: 5, + numberEnd: 6, + audultPrice: 0, + childrenPrice: 0, + }, }, { - 'priceInput': { - 'numberStart': 7, - 'numberEnd': 9, - 'audultPrice': 0, - 'childrenPrice': 0 - } - } - ] - } - ] - } + priceInput: { + numberStart: 7, + numberEnd: 9, + audultPrice: 0, + childrenPrice: 0, + }, + }, + ], + }, + ], + }; - const [defaultUseDates, setDefaultUseDates] = useState(getYearRange(switchParams.use_year)) - const [defaultDefinitionValue, setDefaultDefinitionValue] = useState(generateDefinitionValue(switchParams.use_year)) - const [isQuotationModalOpen, setQuotationModalOpen] = useState(false) - const [isBatchSetupModalOpen, setBatchSetupModalOpen] = useState(false) - const [groupSizeUnlimit, setGroupSizeUnlimit] = useState(false) - const [groupMaxUnlimit, setGroupMaxUnlimit] = useState(false) - const { modal, notification } = App.useApp() - const [quotationForm] = Form.useForm() - const [batchSetupForm] = Form.useForm() + const [defaultUseDates, setDefaultUseDates] = useState( + getYearRange(switchParams.use_year) + ); + const [defaultDefinitionValue, setDefaultDefinitionValue] = useState( + generateDefinitionValue(switchParams.use_year) + ); + const [isQuotationModalOpen, setQuotationModalOpen] = useState(false); + const [isBatchSetupModalOpen, setBatchSetupModalOpen] = useState(false); + const [groupAllSize, setGroupAllSize] = useState(false); + const [groupMaxUnlimit, setGroupMaxUnlimit] = useState(false); + const { modal, notification } = App.useApp(); + const [quotationForm] = Form.useForm(); + const [batchSetupForm] = Form.useForm(); - const datePresets = useDatePresets() + const datePresets = useDatePresets(); useEffect(() => { - setDefaultUseDates(getYearRange(switchParams.use_year)) - setDefaultDefinitionValue(generateDefinitionValue(switchParams.use_year)) - }, [switchParams]) - + setDefaultUseDates(getYearRange(switchParams.use_year)); + setDefaultDefinitionValue(generateDefinitionValue(switchParams.use_year)); + }, [switchParams]); const triggerChange = (changedValue) => { - onChange?.( - 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) - } + 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(defaultUseDates) - quotationForm.setFieldsValue(emptyQuotation) - setQuotationModalOpen(true) - } + const emptyQuotation = newEmptyQuotation(defaultUseDates); + quotationForm.setFieldsValue(emptyQuotation); + setQuotationModalOpen(true); + }; const onQuotationFinish = (values) => { - const newList = saveOrUpdateQuotation(values) - triggerChange(newList) - setQuotationModalOpen(false) - } + const newList = saveOrUpdateQuotation(values); + triggerChange(newList); + setQuotationModalOpen(false); + }; const onBatchSetupFinish = () => { - const defList = batchSetupForm.getFieldsValue().defList - const newList = appendQuotationList(defList) - triggerChange(newList) - setBatchSetupModalOpen(false) - } + const defList = batchSetupForm.getFieldsValue().defList; + const newList = appendQuotationList(defList); + triggerChange(newList); + setBatchSetupModalOpen(false); + }; const onDeleteQuotation = (quotation) => { modal.confirm({ - title: '请确认', + title: "请确认", icon: , - content: '你要删除这条价格吗?', + content: "你要删除这条价格吗?", onOk() { - deleteQuotation(quotation) - .catch(ex => { - notification.error({ - message: 'Notification', - description: ex.message, - placement: 'top', - duration: 4, - }) - }) + 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: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: '6rem', + title: ( + <> + {t("products:unit_name")}{" "} + + + {" "} + + ), + dataIndex: "unit_id", + width: "6rem", render: (text) => t(`products:PriceUnit.${text}`), // (text === '0' ? '每人' : text === '1' ? '每团' : text), }, { - title: t('products:group_size'), - dataIndex: 'group_size', - width: '6rem', - render: (_, record) => formatGroupSize(record.group_size_min,record.group_size_max), + title: t("products:group_size"), + dataIndex: "group_size", + width: "6rem", + render: (_, record) => + formatGroupSize(record.group_size_min, record.group_size_max), }, { - title: (<>{t('products:use_dates')} ), - dataIndex: 'use_dates', + title: ( + <> + {t("products:use_dates")}{" "} + + + {" "} + + ), + dataIndex: "use_dates", // width: '6rem', - render: (_, record) => `${record.use_dates_start}-${record.use_dates_end}`, + render: (_, record) => + `${record.use_dates_start}-${record.use_dates_end}`, }, - { title: t('products:Weekdays'), dataIndex: 'weekdays', width: '4rem' }, + { title: t("products:Weekdays"), dataIndex: "weekdays", width: "4rem" }, { - title: t('products:operation'), - dataIndex: 'operation', - width: '10rem', + 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')}

- {t("products:EditComponents.Quotation")} +
- { - editable && + {editable && ( - - - } + )} onBatchSetupFinish()} onCancel={() => setBatchSetupModalOpen(false)} - destroyOnClose + destroyOnHidden forceRender > - + {(fields, { add, remove }) => ( - + {fields.map((field, index) => ( : { - remove(field.name) - }} />} + extra={ + index == 0 ? ( + + ) : ( + { + remove(field.name); + }} + /> + ) + } > - + - RMB - USD - THB - JPY + RMB + USD + THB + JPY - + - 每人 - 每团 + 每人 + 每团 - - + + - - + + {(useDateFieldList, useDateOptList) => ( - + {useDateFieldList.map((useDateField, index) => ( - - + + - {index == 0 ? : useDateOptList.remove(useDateField.name)} />} + {index == 0 ? ( + + ) : ( + + useDateOptList.remove(useDateField.name) + } + /> + )} ))} - )} - - + + {(priceFieldList, priceOptList) => ( - + {priceFieldList.map((priceField, index) => ( - + - {index == 0 ? : priceOptList.remove(priceField.name)} />} + {index == 0 ? ( + + ) : ( + + priceOptList.remove(priceField.name) + } + /> + )} ))} - @@ -358,7 +496,12 @@ const ProductInfoQuotation = ({ editable, ...props }) => { ))} - @@ -371,152 +514,180 @@ const ProductInfoQuotation = ({ editable, ...props }) => { centered okButtonProps={{ autoFocus: true, - htmlType: 'submit', + htmlType: "submit", }} - title={t('account:detail')} - open={isQuotationModalOpen} onCancel={() => setQuotationModalOpen(false)} - destroyOnClose + title={t("products:EditComponents.Quotation")} + open={isQuotationModalOpen} + onCancel={() => setQuotationModalOpen(false)} + destroyOnHidden forceRender modalRender={(dom) => ( {dom} )} > - - - + + + + + + + + + - + - + - RMB - USD - THB - JPY + RMB + USD + THB + JPY - 每人 - 每团 + 每人 + 每团 - { + { if (e.target.checked) { - quotationForm.setFieldValue('group_size_min', 0) - quotationForm.setFieldValue('group_size_max', 1000) - setGroupSizeUnlimit(true) - + quotationForm.setFieldValue("group_size_min", 1); + quotationForm.setFieldValue("group_size_max", 1000); + setGroupAllSize(true); } else { - quotationForm.setFieldValue('group_size_min', 1) - if (!groupMaxUnlimit) quotationForm.setFieldValue('group_size_max', 999) - setGroupSizeUnlimit(false) + setGroupAllSize(false); } - }}>不分人等(0~1000) + }} + > + 不分人等(1~1000) + { + if (value > 1000 || value < 1) { + return Promise.reject("人等必须在 1~1000 之间"); + } + return Promise.resolve(); + }, }, ]} > - + - { + { if (e.target.checked) { - quotationForm.setFieldValue('group_size_max', 1000) - setGroupMaxUnlimit(true) + quotationForm.setFieldValue("group_size_max", 1000); + setGroupMaxUnlimit(true); } else { - quotationForm.setFieldValue('group_size_max', 999) - setGroupMaxUnlimit(false) + setGroupMaxUnlimit(false); } - }}>不限(1000) + }} + > + 不限(1000) + { + if (value > 1000 || value < 1) { + return Promise.reject("人等必须在 1~1000 之间"); + } + return Promise.resolve(); + }, }, ]} > - + - + - - + + - ) -} + ); +}; -export default ProductInfoQuotation +export default ProductInfoQuotation;