diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index cfbffdd..7f173c6 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -275,7 +275,7 @@ export const useProductsStore = create( } }, - newEmptyQuotation: () => ({ + newEmptyQuotation: (useDates) => ({ id: null, adult_cost: 0, child_cost: 0, @@ -283,10 +283,7 @@ export const useProductsStore = create( unit_id: '0', group_size_min: 1, group_size_max: 10, - use_dates: [ - dayjs().startOf('M'), - dayjs().endOf('M') - ], + use_dates: useDates, weekdayList: [], fresh: true // 标识是否是新记录,新记录才用添加列表 }), diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index b76936c..5fe6a89 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -133,12 +133,21 @@ const defaultDefinitionValue = { 'priceList': [defaultPriceValue] } +const getYearRange = (year) => [dayjs().year(year).startOf('y'), dayjs().year(year).endOf('y')] + const ProductInfoQuotation = ({ editable, ...props }) => { const { onChange } = props 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 [defaultUseDates, setDefaultUseDates] = useState(getYearRange(switchParams.use_year)) const [isQuotationModalOpen, setQuotationModalOpen] = useState(false) const [isBatchSetupModalOpen, setBatchSetupModalOpen] = useState(false) const [groupSizeUnlimit, setGroupSizeUnlimit] = useState(false) @@ -149,16 +158,11 @@ const ProductInfoQuotation = ({ editable, ...props }) => { const datePresets = useDatePresets() - const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotation, switchParams] = - useProductsStore((state) => [ - state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotation, - state.switchParams - ]) - useEffect(() => { - console.info('switchParams: ', switchParams) + setDefaultUseDates(getYearRange(switchParams.use_year)) }, [switchParams]) + const triggerChange = (changedValue) => { onChange?.( changedValue @@ -174,14 +178,13 @@ const ProductInfoQuotation = ({ editable, ...props }) => { } const onNewQuotation = () => { - const emptyQuotation = newEmptyQuotation() + const emptyQuotation = newEmptyQuotation(defaultUseDates) quotationForm.setFieldsValue(emptyQuotation) setQuotationModalOpen(true) } const onQuotationFinish = (values) => { const newList = saveOrUpdateQuotation(values) - console.info('newList', newList) triggerChange(newList) setQuotationModalOpen(false) }