From 60be7b7457778716a27b0d73ed8ab0e2c9c3a7fe Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 6 Aug 2024 10:35:29 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=E5=AE=8C=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Products/Index.js | 68 ++++++++++++++----- src/views/products/Detail/ProductInfo.jsx | 5 +- .../products/Detail/ProductInfoQuotation.jsx | 3 +- 3 files changed, 55 insertions(+), 21 deletions(-) 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) } From 0f655407334e828d99a4cdc7236f610276c30693 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 6 Aug 2024 11:30:18 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E5=8F=98=E5=8C=96=E5=AF=B9=E8=B1=A1=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Auth.js | 2 +- src/stores/Products/Index.js | 43 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/stores/Auth.js b/src/stores/Auth.js index 0c48ce6..7fc81b8 100644 --- a/src/stores/Auth.js +++ b/src/stores/Auth.js @@ -43,7 +43,7 @@ async function fetchLastRequet() { const initialState = { tokenInterval: null, - tokenTimeout: false,// 开发时候用false,正式环境true, + tokenTimeout: import.meta.env.PROD ? true : false, loginStatus: 0, defaltRoute: '', currentUser: { diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index 9375042..ea0da01 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -210,13 +210,29 @@ export const useProductsStore = create( formValues.use_dates_end = formValues.use_dates[1].format('YYYY-MM-DD') if (isEmpty(formValues.id)) { + formValues.lastedit_changed = '' + formValues.audit_state_id = -1 // 新增 mergedList = [...quotationList,...[formValues]] } else { - mergedList = quotationList.map(q => { - if (q.id === formValues.id) { + mergedList = quotationList.map(prevQuotation => { + if (prevQuotation.id === formValues.id) { + const changedList = [] + for (const [key, value] of Object.entries(formValues)) { + if (key === 'use_dates' || key === 'id') continue + + const preValue = prevQuotation[key] + const hasChanged = preValue !== value + + if (hasChanged) { + changedList.push({ + [key]: preValue, + }) + } + } + return { - ...q, + ...prevQuotation, adult_cost: formValues.adult_cost, child_cost: formValues.child_cost, currency: formValues.currency, @@ -225,28 +241,13 @@ export const useProductsStore = create( group_size_max: formValues.group_size_max, use_dates_start: formValues.use_dates_start, use_dates_end: formValues.use_dates_end, - weekdays: formValues.weekdays + weekdays: formValues.weekdays, + lastedit_changed: JSON.stringify(changedList, null, 2) } } else { - return q + return prevQuotation } }) - - 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' || key === 'id') continue - - const prevValue = prevQuotation[key] - const hasChanged = prevValue === value - console.log(`${key}: ${prevValue} - ${value} (${hasChanged})`) - } - } } set(() => ({ From 7fb85e308d76850c402413576d2920684b1e9dca Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 6 Aug 2024 11:39:25 +0800 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E8=B0=83=E8=AF=95=20JSON=EF=BC=9B=E4=BF=AE=E5=A4=8D=E5=91=A8?= =?UTF-8?q?=E6=9C=AB=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Products/Index.js | 2 ++ src/views/products/Detail/ProductInfoQuotation.jsx | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index ea0da01..8f2bb12 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -201,6 +201,7 @@ export const useProductsStore = create( }, saveOrUpdateQuotation: (formValues) => { + const { activeAgency, editingProduct, quotationList } = get() let mergedList = [] @@ -208,6 +209,7 @@ export const useProductsStore = create( 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') + formValues.weekdays = formValues.weekdays.join(',') if (isEmpty(formValues.id)) { formValues.lastedit_changed = '' diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index 31cf003..0305607 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -454,13 +454,6 @@ const ProductInfoQuotation = ({ editable, ...props }) => { )} - - {() => ( - -
{JSON.stringify(batchSetupForm.getFieldsValue(), null, 2)}
-
- )} -
From 8970be0c10cb9e0d82089084c69c660a4d2904ff Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 6 Aug 2024 14:27:48 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=20Key=20=E7=9A=84=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Products/Index.js | 11 ++++++++--- .../products/Detail/ProductInfoQuotation.jsx | 17 ++++++++--------- src/views/reservation/Newest.jsx | 2 -- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index 8f2bb12..fffa4d2 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, isEmpty } from '@/utils/commons'; +import { groupBy, isEmpty, generateId } from '@/utils/commons'; export const searchAgencyAction = async (param) => { const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/products_search`, param); @@ -140,11 +140,16 @@ export const useProductsStore = create( setActiveAgency: (activeAgency) => set({ activeAgency }), setActiveAgencyState: (activeAgencyState) => set({ activeAgencyState }), setAgencyProducts: (agencyProducts) => set({ agencyProducts }), - // TODO:产品和价格会分开查询编辑, + setEditingProduct: (product) => { set(() => ({ editingProduct: product, - quotationList: product?.quotation + quotationList: (product?.quotation??[]).map(q => { + return { + ...q, + key: generateId() + } + }) })) }, setEditing: (editing) => set({ editing }), diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index 0305607..e0abc17 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -1,7 +1,7 @@ -import { useEffect, useState } from 'react' -import { Table, Form, Modal, Button, Radio, Input, Flex, Card, Select, Typography, InputNumber, Checkbox, DatePicker, Space } from 'antd' +import { useState } from 'react' +import { Table, Form, Modal, Button, Radio, Input, Flex, Card, Select, InputNumber, Checkbox, DatePicker, Space } from 'antd' import { useTranslation } from 'react-i18next' -import { CloseOutlined, StarTwoTone, PlusOutlined, ExclamationCircleFilled } from '@ant-design/icons'; +import { CloseOutlined, StarTwoTone, PlusOutlined, ExclamationCircleFilled } from '@ant-design/icons' import { useDatePresets } from '@/hooks/useDatePresets' import dayjs from 'dayjs' import useProductsStore from '@/stores/Products/Index' @@ -30,7 +30,7 @@ const PriceInput = (props) => { return } if (!('numberStart' in value)) { - setNumberStart(newNumber); + setNumberStart(newNumber) } triggerChange({ numberStart: newNumber, @@ -46,8 +46,8 @@ const PriceInput = (props) => { } triggerChange({ numberEnd: newNumber, - }); - }; + }) + } const onAudultPriceChange = (e) => { const newNumber = parseInt(e.target.value || '0', 10) if (Number.isNaN(audultPrice)) { @@ -71,7 +71,7 @@ const PriceInput = (props) => { triggerChange({ childrenPrice: newNumber, }) - }; + } return ( { deleteQuotation(quotation.id) }, onCancel() { - console.log('Cancel'); + console.log('Cancel') }, }) }}>{t('Delete')} @@ -360,7 +360,6 @@ const ProductInfoQuotation = ({ editable, ...props }) => { <>

{t('products:EditComponents.Quotation')}

{ setDataLoading(true) - console.info('onSearchClick') - console.info(submitValues) fetchReservationList(submitValues, current) .catch(ex => { notification.error({ From 41b32aaff4da96b232af41cd8f2618f0901bbc3f Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 6 Aug 2024 14:36:30 +0800 Subject: [PATCH 5/7] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=20confirm=20=20?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/commons.js | 15 --------------- .../products/Detail/ProductInfoQuotation.jsx | 8 +++----- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/utils/commons.js b/src/utils/commons.js index 51b7cc8..98a0ef6 100644 --- a/src/utils/commons.js +++ b/src/utils/commons.js @@ -82,25 +82,10 @@ export function isNotEmpty(val) { return val !== undefined && val !== null && val !== ""; } -// export function isEmpty(val) { -// return val === undefined || val === null || val === ""; -// } - export function prepareUrl(url) { return new UrlBuilder(url); } -// export function debounce(fn, delay = 500) { -// let timer; -// return e => { -// e.persist(); -// clearTimeout(timer); -// timer = setTimeout(() => { -// fn(e); -// }, delay); -// }; -// } - export function throttle(fn, delay, atleast) { let timeout = null, startTime = new Date(); diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index e0abc17..1233d7f 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { Table, Form, Modal, Button, Radio, Input, Flex, Card, Select, InputNumber, Checkbox, DatePicker, Space } from 'antd' +import { Table, Form, Modal, Button, Radio, Input, Flex, Card, Select, InputNumber, Checkbox, DatePicker, Space, App } from 'antd' import { useTranslation } from 'react-i18next' import { CloseOutlined, StarTwoTone, PlusOutlined, ExclamationCircleFilled } from '@ant-design/icons' import { useDatePresets } from '@/hooks/useDatePresets' @@ -242,6 +242,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => { const [isQuotationModalOpen, setQuotationModalOpen] = useState(false) const [isBatchSetupModalOpen, setBatchSetupModalOpen] = useState(false) + const { modal } = App.useApp(); const [quotationForm] = Form.useForm() const [batchSetupForm] = Form.useForm() @@ -338,16 +339,13 @@ const ProductInfoQuotation = ({ editable, ...props }) => { From b1ddfc9bda7638f21b9640b9175c65ac2c66f8dc Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 6 Aug 2024 15:38:13 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix:=20CNY=20->=20RMB;=20=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=AE=BE=E7=BD=AE=E4=BB=B7=E6=A0=BC=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Products/Index.js | 55 +++++++++++++------ .../products/Detail/ProductInfoQuotation.jsx | 38 ++++--------- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index fffa4d2..e868754 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -147,7 +147,8 @@ export const useProductsStore = create( quotationList: (product?.quotation??[]).map(q => { return { ...q, - key: generateId() + key: generateId(), + fresh: false } }) })) @@ -183,21 +184,41 @@ export const useProductsStore = create( dayjs().startOf('M'), dayjs().endOf('M') ], - weekdays: '5, 6' + weekdayList: ['5', '6'], + fresh: true // 标识是否是新记录,新记录才用添加列表 }), - appendQuotationList: (newList) => { + appendQuotationList: (defList) => { const { activeAgency, editingProduct, quotationList } = get() + const generatedList = [] - const mapList = newList.map(q => { - return { - ...q, - WPI_SN: editingProduct.info.id, - WPP_VEI_SN: activeAgency.travel_agency_id - } + defList.forEach(definition => { + const mappedPriceList = definition?.priceList.map(price => { + return { + id: null, + adult_cost: price.priceInput.audultPrice, + child_cost: price.priceInput.childrenPrice, + group_size_min: price.priceInput.numberStart, + group_size_max: price.priceInput.numberEnd, + + currency: definition.currency, + unit_id: definition.unitId, + // 保持和 API 返回格式一致,日期要转换为字符串 + use_dates_start: definition.useDate[0].format('YYYY-MM-DD'), + use_dates_end: definition.useDate[1].format('YYYY-MM-DD'), + weekdays: definition.weekend.join(','), + WPI_SN: editingProduct.info.id, + WPP_VEI_SN: activeAgency.travel_agency_id, + lastedit_changed: '', + audit_state_id: -1, + key: generateId(), + fresh: false + } + }) + generatedList.push(...mappedPriceList) }) - const mergedList = [...quotationList,...mapList] + const mergedList = [...quotationList,...generatedList] set(() => ({ quotationList: mergedList })) @@ -214,19 +235,20 @@ export const useProductsStore = create( 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') - formValues.weekdays = formValues.weekdays.join(',') + formValues.weekdays = formValues.weekdayList.join(',') - if (isEmpty(formValues.id)) { + if (formValues.fresh) { + formValues.key = generateId() formValues.lastedit_changed = '' - formValues.audit_state_id = -1 // 新增 + formValues.audit_state_id = -1 // 新增, + formValues.fresh = false // 添加到列表后就不是新纪录,保存要修改原来记录 mergedList = [...quotationList,...[formValues]] } else { - mergedList = quotationList.map(prevQuotation => { - if (prevQuotation.id === formValues.id) { + if (prevQuotation.key === formValues.key) { const changedList = [] for (const [key, value] of Object.entries(formValues)) { - if (key === 'use_dates' || key === 'id') continue + if (key === 'use_dates' || key === 'id' || key === 'key') continue const preValue = prevQuotation[key] const hasChanged = preValue !== value @@ -271,6 +293,7 @@ export const useProductsStore = create( }) deleteQuotationAction(quotaionId) set(() => ({ + // 还要设置回 product.quotaion 对象 quotationList: newList })) }, diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index 1233d7f..bf59a0a 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -5,6 +5,7 @@ import { CloseOutlined, StarTwoTone, PlusOutlined, ExclamationCircleFilled } fro import { useDatePresets } from '@/hooks/useDatePresets' import dayjs from 'dayjs' import useProductsStore from '@/stores/Products/Index' +import { generateId } from '@/utils/commons' const { RangePicker } = DatePicker @@ -121,7 +122,7 @@ const batchSetupInitialValues = { dayjs().add(1, 'year').startOf('y'), dayjs().add(1, 'year').endOf('y') ], 'unitId': '0', - 'currency': 'CNY', + 'currency': 'RMB', 'weekend': [ '5', '6' @@ -167,7 +168,7 @@ const batchSetupInitialValues = { dayjs().add(1, 'year').subtract(2, 'M').startOf('M'), dayjs().add(1, 'year').endOf('M') ], 'unitId': '0', - 'currency': 'CNY', + 'currency': 'RMB', 'weekend': [ '5', '6' @@ -224,7 +225,7 @@ const defaultDefinitionValue = { dayjs().add(1, 'year').subtract(2, 'M').startOf('M'), dayjs().add(1, 'year').endOf('M') ], 'unitId': '0', - 'currency': 'CNY', + 'currency': 'RMB', 'weekend': [ '5', '6' @@ -260,6 +261,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => { const onQuotationSeleted = async (quotation) => { // 把 start, end 转换为 RangePicker 数组格式 quotation.use_dates = [dayjs(quotation.use_dates_start), dayjs(quotation.use_dates_end)] + quotation.weekdayList = quotation.weekdays.split(',') quotationForm.setFieldsValue(quotation) setQuotationModalOpen(true) } @@ -277,30 +279,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => { } const onBatchSetupFinish = () => { - let priceList = [] const defList = batchSetupForm.getFieldsValue().defList - - defList.forEach(definition => { - const mappedPriceList = definition?.priceList.map(price => { - return { - id: null, - adult_cost: price.priceInput.audultPrice, - child_cost: price.priceInput.childrenPrice, - group_size_min: price.priceInput.numberStart, - group_size_max: price.priceInput.numberEnd, - - currency: definition.currency, - unit_id: definition.unitId, - // 保持和 API 返回格式一致,日期要转换为字符串 - use_dates_start: definition.useDate[0].format('YYYY-MM-DD'), - use_dates_end: definition.useDate[1].format('YYYY-MM-DD'), - weekdays: definition.weekend.join(','), - } - }) - priceList.push(...mappedPriceList) - }) - - const newList = appendQuotationList(priceList) + const newList = appendQuotationList(defList) triggerChange(newList) setBatchSetupModalOpen(false) } @@ -406,7 +386,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => { > @@ -479,6 +459,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => { )} > + + { From 8dbedbcf38c3da5b72c6ec3c558030d9cb22a568 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Wed, 7 Aug 2024 09:38:49 +0800 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=90=8C=E6=97=B6=E6=9B=B4=E6=96=B0=20State?= =?UTF-8?q?=20=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Products/Index.js | 18 +++++++++++++----- .../products/Detail/ProductInfoQuotation.jsx | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index e868754..b22dd87 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, isEmpty, generateId } from '@/utils/commons'; +import { groupBy, generateId } from '@/utils/commons'; export const searchAgencyAction = async (param) => { const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/products_search`, param); @@ -287,15 +287,23 @@ export const useProductsStore = create( }, deleteQuotation: (quotaionId) => { - const { quotationList } = get() + const { editingProduct, quotationList, agencyProducts } = get() + const productTypeId = editingProduct.info.product_type_id; const newList = quotationList.filter(q => { return q.id != quotaionId }) deleteQuotationAction(quotaionId) - set(() => ({ - // 还要设置回 product.quotaion 对象 + + set({ + agencyProducts: { + ...agencyProducts, + [productTypeId]: [{ + ...editingProduct, + quotation: newList + }] + }, quotationList: newList - })) + }) }, // side effects diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index bf59a0a..c21b744 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -5,7 +5,6 @@ import { CloseOutlined, StarTwoTone, PlusOutlined, ExclamationCircleFilled } fro import { useDatePresets } from '@/hooks/useDatePresets' import dayjs from 'dayjs' import useProductsStore from '@/stores/Products/Index' -import { generateId } from '@/utils/commons' const { RangePicker } = DatePicker