feat: 完编辑价格保存

perf/export-docx
Jimmy Liow 11 months ago
parent 9b0427bc00
commit 60be7b7457

@ -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
}))

@ -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({

@ -299,7 +299,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
priceList.push(...mappedPriceList)
})
appendQuotationList(priceList)
const newList = appendQuotationList(priceList)
triggerChange(newList)
setBatchSetupModalOpen(false)
}

Loading…
Cancel
Save