diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index 94e655b..9375042 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -3,7 +3,7 @@ import { devtools } from 'zustand/middleware'; import dayjs from 'dayjs' import { fetchJSON, postForm, postJSON } from '@/utils/request'; import { HT_HOST } from '@/config'; -import { groupBy } from '@/utils/commons'; +import { groupBy, isEmpty } from '@/utils/commons'; export const searchAgencyAction = async (param) => { const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/products_search`, param); @@ -181,38 +181,74 @@ export const useProductsStore = create( weekdays: '5, 6' }), - // TODO:添加价格后,重新读取列表 appendQuotationList: (newList) => { - set((state) => ({ - quotationList: [...state.quotationList, ...newList] + const { activeAgency, editingProduct, quotationList } = get() + + const mapList = newList.map(q => { + return { + ...q, + WPI_SN: editingProduct.info.id, + WPP_VEI_SN: activeAgency.travel_agency_id + } + }) + + const mergedList = [...quotationList,...mapList] + set(() => ({ + quotationList: mergedList })) + + return mergedList }, saveOrUpdateQuotation: (formValues) => { const { activeAgency, editingProduct, quotationList } = get() + let mergedList = [] 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 (isEmpty(formValues.id)) { + mergedList = [...quotationList,...[formValues]] + } else { + + mergedList = quotationList.map(q => { + if (q.id === formValues.id) { + return { + ...q, + adult_cost: formValues.adult_cost, + child_cost: formValues.child_cost, + currency: formValues.currency, + unit_id: formValues.unit_id, + group_size_min: formValues.group_size_min, + group_size_max: formValues.group_size_max, + use_dates_start: formValues.use_dates_start, + use_dates_end: formValues.use_dates_end, + weekdays: formValues.weekdays + } + } else { + return q + } + }) + + const prevList = quotationList.filter(q => q.id === formValues.id) - if (prevList.length > 0) { - const prevQuotation = prevList[0] - console.info('formValues: ', formValues) - console.info('prevQuotation: ', prevQuotation) - // 对比报价前后是否有改动 - for (const [key, value] of Object.entries(formValues)) { - if (key === 'use_dates') continue + if (prevList.length > 0) { + const prevQuotation = prevList[0] + console.info('formValues: ', formValues) + console.info('prevQuotation: ', prevQuotation) + // 对比报价前后是否有改动 + for (const [key, value] of Object.entries(formValues)) { + if (key === 'use_dates' || key === 'id') continue - const prevValue = prevQuotation[key] - const hasChanged = prevValue === value - console.log(`${key}: ${prevValue} - ${value} (${hasChanged})`) + const prevValue = prevQuotation[key] + const hasChanged = prevValue === value + console.log(`${key}: ${prevValue} - ${value} (${hasChanged})`) + } } } - const mergedList = [...quotationList,...[formValues]] set(() => ({ quotationList: mergedList })) diff --git a/src/views/products/Detail/ProductInfo.jsx b/src/views/products/Detail/ProductInfo.jsx index 56f493a..99806fc 100644 --- a/src/views/products/Detail/ProductInfo.jsx +++ b/src/views/products/Detail/ProductInfo.jsx @@ -56,9 +56,6 @@ const ProductInfo = ({ ...props }) => { const prevLgcDetailsMapped = editingProduct.lgc_details.reduce((r, c) => ({ ...r, [c.lgc]: { ...c, description: c.descriptions } }), {}); // todo: description字段不一致 const mergedLgc = { ...prevLgcDetailsMapped, ...values.lgc_details_mapped }; - /** quotation */ - const prevQuotationMapped = editingProduct.quotation.reduce((r, c) => ({ ...r, [c.id]: { ...c, unit: c.unit_id, audit_state: c.audit_state_id } }), {}); - const mergedQ = { ...prevQuotationMapped, ...(values.quotation || []) }; // console.log(values); // return false; // debug: 0 /** 提交保存 */ @@ -67,7 +64,7 @@ const ProductInfo = ({ ...props }) => { travel_agency_id: activeAgency.travel_agency_id, info: readyToSubInfo, lgc_details: Object.values(mergedLgc), - quotation: Object.values(mergedQ), + quotation: values.quotation, }).catch(ex => { setLoading(false); notification.error({ diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index de6737c..31cf003 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -299,7 +299,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => { priceList.push(...mappedPriceList) }) - appendQuotationList(priceList) + const newList = appendQuotationList(priceList) + triggerChange(newList) setBatchSetupModalOpen(false) }