diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index 19f0408..94e655b 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -108,6 +108,14 @@ export const postProductsSaveAction = async (products) => { return { errcode, result, success: errcode === 0 }; } +/** + * 删除产品报价 + */ +export const deleteQuotationAction = async (id) => { + const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/agency_product_quotation_delete`, {id}); + return { errcode, result, success: errcode === 0 }; +} + const initialState = { loading: false, searchValues: {}, // 客服首页: 搜索条件 @@ -181,13 +189,16 @@ export const useProductsStore = create( }, saveOrUpdateQuotation: (formValues) => { - const { quotationList } = get() + const { activeAgency, editingProduct, quotationList } = get() + + formValues.WPI_SN = editingProduct.info.id + formValues.WPP_VEI_SN = activeAgency.travel_agency_id + formValues.use_dates_start = formValues.use_dates[0].format('YYYY-MM-DD') + formValues.use_dates_end = formValues.use_dates[1].format('YYYY-MM-DD') + const prevList = quotationList.filter(q => q.id === formValues.id) if (prevList.length > 0) { - - formValues.use_dates_start = formValues.use_dates[0].format('YYYY-MM-DD') - formValues.use_dates_end = formValues.use_dates[1].format('YYYY-MM-DD') const prevQuotation = prevList[0] console.info('formValues: ', formValues) console.info('prevQuotation: ', prevQuotation) @@ -201,8 +212,22 @@ export const useProductsStore = create( } } - set((state) => ({ - quotationList: [...state.quotationList, ...[formValues]] + const mergedList = [...quotationList,...[formValues]] + set(() => ({ + quotationList: mergedList + })) + + return mergedList + }, + + deleteQuotation: (quotaionId) => { + const { quotationList } = get() + const newList = quotationList.filter(q => { + return q.id != quotaionId + }) + deleteQuotationAction(quotaionId) + set(() => ({ + quotationList: newList })) }, diff --git a/src/views/products/Detail/ProductInfoForm.jsx b/src/views/products/Detail/ProductInfoForm.jsx index 2e9fefe..6579916 100644 --- a/src/views/products/Detail/ProductInfoForm.jsx +++ b/src/views/products/Detail/ProductInfoForm.jsx @@ -393,10 +393,7 @@ const formValuesMapper = (values) => { ], 'quotation_mapped': { key: 'quotation', - transform: (value) => { - console.info(value) - return value.quotationList - }, + transform: value => value }, }; let dest = {}; diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index 960e775..de6737c 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -236,8 +236,7 @@ const defaultDefinitionValue = { const ProductInfoQuotation = ({ editable, ...props }) => { - - const { id, value = {}, onChange } = props + const { onChange } = props const { t } = useTranslation() @@ -246,17 +245,15 @@ const ProductInfoQuotation = ({ editable, ...props }) => { const [quotationForm] = Form.useForm() const [batchSetupForm] = Form.useForm() - // console.info('value: ', value) - const datePresets = useDatePresets() - const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation] = - useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation]) + const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotation] = + useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotation]) const triggerChange = (changedValue) => { - onChange?.({ - quotationList - }) + onChange?.( + changedValue + ) } const onQuotationSeleted = async (quotation) => { @@ -273,20 +270,9 @@ const ProductInfoQuotation = ({ editable, ...props }) => { } const onQuotationFinish = (values) => { - saveOrUpdateQuotation(values) - triggerChange(quotationList) + const newList = saveOrUpdateQuotation(values) + triggerChange(newList) setQuotationModalOpen(false) - // .then(() => { - // setQuotationModalOpen(false) - // }) - // .catch(ex => { - // notification.error({ - // message: 'Notification', - // description: ex.message, - // placement: 'top', - // duration: 4, - // }) - // }) } const onBatchSetupFinish = () => { @@ -356,7 +342,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => { icon: , content: '你要删除这条价格吗?', onOk() { - console.log('OK'); + deleteQuotation(quotation.id) }, onCancel() { console.log('Cancel');