feat: 价格使用 Form 管理

perf/export-docx
Jimmy Liow 11 months ago
parent b3faf7453e
commit a186142cc0

@ -180,9 +180,8 @@ export const useProductsStore = create(
saveOrUpdateQuotation: (formValues) => { saveOrUpdateQuotation: (formValues) => {
const { quotationList } = get() const { quotationList } = get()
console.info('formValues: ', formValues)
const prevList = quotationList.filter(q => q.id === formValues.id) const prevList = quotationList.filter(q => q.id === formValues.id)
console.info(prevList)
if (prevList.length > 0) { if (prevList.length > 0) {
formValues.use_dates_start = formValues.use_dates[0].format('YYYY-MM-DD') formValues.use_dates_start = formValues.use_dates[0].format('YYYY-MM-DD')
@ -199,6 +198,10 @@ export const useProductsStore = create(
console.log(`${key}: ${prevValue} - ${value} (${hasChanged})`) console.log(`${key}: ${prevValue} - ${value} (${hasChanged})`)
} }
} }
set((state) => ({
quotationList: [...state.quotationList, ...[formValues]]
}))
}, },
// side effects // side effects

@ -134,8 +134,10 @@ const InfoForm = ({ onSubmit, onReset, onValuesChange, editable: _editable, show
</div> </div>
</Form.Item> </Form.Item>
)} )}
<Form.Item name='quotation_mapped'>
<ProductInfoQuotation editable={editable} />
</Form.Item>
</Form> </Form>
<ProductInfoQuotation editable={editable} />
</> </>
); );
}; };
@ -380,6 +382,13 @@ const formValuesMapper = (values) => {
}, },
}, },
], ],
'quotation_mapped': {
key: 'quotation',
transform: (value) => {
console.info(value)
return value.quotationList
},
},
}; };
let dest = {}; let dest = {};
const { city, ...omittedValue } = values; const { city, ...omittedValue } = values;

@ -236,6 +236,9 @@ const defaultDefinitionValue = {
const ProductInfoQuotation = ({ editable, ...props }) => { const ProductInfoQuotation = ({ editable, ...props }) => {
const { id, value = {}, onChange } = props
const { t } = useTranslation() const { t } = useTranslation()
const [isQuotationModalOpen, setQuotationModalOpen] = useState(false) const [isQuotationModalOpen, setQuotationModalOpen] = useState(false)
@ -243,14 +246,18 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
const [quotationForm] = Form.useForm() const [quotationForm] = Form.useForm()
const [batchSetupForm] = Form.useForm() const [batchSetupForm] = Form.useForm()
// console.info('value: ', value)
const datePresets = useDatePresets() const datePresets = useDatePresets()
const [newEmptyQuotation, appendQuotationList, quotationList, saveOrUpdateQuotation] = const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation] =
useProductsStore((state) => [state.newEmptyQuotation, state.appendQuotationList, state.quotationList, state.saveOrUpdateQuotation]) useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation])
useEffect(() => { const triggerChange = (changedValue) => {
console.info('quotationList: ', quotationList) onChange?.({
}, [quotationList]) quotationList
})
}
const onQuotationSeleted = async (quotation) => { const onQuotationSeleted = async (quotation) => {
// start, end RangePicker // start, end RangePicker
@ -267,6 +274,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
const onQuotationFinish = (values) => { const onQuotationFinish = (values) => {
saveOrUpdateQuotation(values) saveOrUpdateQuotation(values)
triggerChange(quotationList)
setQuotationModalOpen(false) setQuotationModalOpen(false)
// .then(() => { // .then(() => {
// setQuotationModalOpen(false) // setQuotationModalOpen(false)

Loading…
Cancel
Save