fix: CNY -> RMB; 迁移批量设置价格代码

perf/export-docx
Jimmy Liow 11 months ago
parent 41b32aaff4
commit b1ddfc9bda

@ -147,7 +147,8 @@ export const useProductsStore = create(
quotationList: (product?.quotation??[]).map(q => { quotationList: (product?.quotation??[]).map(q => {
return { return {
...q, ...q,
key: generateId() key: generateId(),
fresh: false
} }
}) })
})) }))
@ -183,21 +184,41 @@ export const useProductsStore = create(
dayjs().startOf('M'), dayjs().startOf('M'),
dayjs().endOf('M') dayjs().endOf('M')
], ],
weekdays: '5, 6' weekdayList: ['5', '6'],
fresh: true // 标识是否是新记录,新记录才用添加列表
}), }),
appendQuotationList: (newList) => { appendQuotationList: (defList) => {
const { activeAgency, editingProduct, quotationList } = get() const { activeAgency, editingProduct, quotationList } = get()
const generatedList = []
const mapList = newList.map(q => { defList.forEach(definition => {
const mappedPriceList = definition?.priceList.map(price => {
return { return {
...q, 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, WPI_SN: editingProduct.info.id,
WPP_VEI_SN: activeAgency.travel_agency_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(() => ({ set(() => ({
quotationList: mergedList quotationList: mergedList
})) }))
@ -214,19 +235,20 @@ export const useProductsStore = create(
formValues.WPP_VEI_SN = activeAgency.travel_agency_id formValues.WPP_VEI_SN = activeAgency.travel_agency_id
formValues.use_dates_start = formValues.use_dates[0].format('YYYY-MM-DD') 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.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.lastedit_changed = ''
formValues.audit_state_id = -1 // 新增 formValues.audit_state_id = -1 // 新增,
formValues.fresh = false // 添加到列表后就不是新纪录,保存要修改原来记录
mergedList = [...quotationList,...[formValues]] mergedList = [...quotationList,...[formValues]]
} else { } else {
mergedList = quotationList.map(prevQuotation => { mergedList = quotationList.map(prevQuotation => {
if (prevQuotation.id === formValues.id) { if (prevQuotation.key === formValues.key) {
const changedList = [] const changedList = []
for (const [key, value] of Object.entries(formValues)) { 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 preValue = prevQuotation[key]
const hasChanged = preValue !== value const hasChanged = preValue !== value
@ -271,6 +293,7 @@ export const useProductsStore = create(
}) })
deleteQuotationAction(quotaionId) deleteQuotationAction(quotaionId)
set(() => ({ set(() => ({
// 还要设置回 product.quotaion 对象
quotationList: newList quotationList: newList
})) }))
}, },

@ -5,6 +5,7 @@ import { CloseOutlined, StarTwoTone, PlusOutlined, ExclamationCircleFilled } fro
import { useDatePresets } from '@/hooks/useDatePresets' import { useDatePresets } from '@/hooks/useDatePresets'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import useProductsStore from '@/stores/Products/Index' import useProductsStore from '@/stores/Products/Index'
import { generateId } from '@/utils/commons'
const { RangePicker } = DatePicker const { RangePicker } = DatePicker
@ -121,7 +122,7 @@ const batchSetupInitialValues = {
dayjs().add(1, 'year').startOf('y'), dayjs().add(1, 'year').endOf('y') dayjs().add(1, 'year').startOf('y'), dayjs().add(1, 'year').endOf('y')
], ],
'unitId': '0', 'unitId': '0',
'currency': 'CNY', 'currency': 'RMB',
'weekend': [ 'weekend': [
'5', '5',
'6' '6'
@ -167,7 +168,7 @@ const batchSetupInitialValues = {
dayjs().add(1, 'year').subtract(2, 'M').startOf('M'), dayjs().add(1, 'year').endOf('M') dayjs().add(1, 'year').subtract(2, 'M').startOf('M'), dayjs().add(1, 'year').endOf('M')
], ],
'unitId': '0', 'unitId': '0',
'currency': 'CNY', 'currency': 'RMB',
'weekend': [ 'weekend': [
'5', '5',
'6' '6'
@ -224,7 +225,7 @@ const defaultDefinitionValue = {
dayjs().add(1, 'year').subtract(2, 'M').startOf('M'), dayjs().add(1, 'year').endOf('M') dayjs().add(1, 'year').subtract(2, 'M').startOf('M'), dayjs().add(1, 'year').endOf('M')
], ],
'unitId': '0', 'unitId': '0',
'currency': 'CNY', 'currency': 'RMB',
'weekend': [ 'weekend': [
'5', '5',
'6' '6'
@ -260,6 +261,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
const onQuotationSeleted = async (quotation) => { const onQuotationSeleted = async (quotation) => {
// start, end RangePicker // start, end RangePicker
quotation.use_dates = [dayjs(quotation.use_dates_start), dayjs(quotation.use_dates_end)] quotation.use_dates = [dayjs(quotation.use_dates_start), dayjs(quotation.use_dates_end)]
quotation.weekdayList = quotation.weekdays.split(',')
quotationForm.setFieldsValue(quotation) quotationForm.setFieldsValue(quotation)
setQuotationModalOpen(true) setQuotationModalOpen(true)
} }
@ -277,30 +279,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
} }
const onBatchSetupFinish = () => { const onBatchSetupFinish = () => {
let priceList = []
const defList = batchSetupForm.getFieldsValue().defList const defList = batchSetupForm.getFieldsValue().defList
const newList = appendQuotationList(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)
triggerChange(newList) triggerChange(newList)
setBatchSetupModalOpen(false) setBatchSetupModalOpen(false)
} }
@ -406,7 +386,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
> >
<Form.Item label='币种' name={[field.name, 'currency']}> <Form.Item label='币种' name={[field.name, 'currency']}>
<Select placeholder='选择币种'> <Select placeholder='选择币种'>
<Select.Option value='CNY'>CNY</Select.Option> <Select.Option value='RMB'>RMB</Select.Option>
<Select.Option value='USD'>USD</Select.Option> <Select.Option value='USD'>USD</Select.Option>
</Select> </Select>
</Form.Item> </Form.Item>
@ -479,6 +459,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
)} )}
> >
<Form.Item name='id' className='hidden' ><Input /></Form.Item> <Form.Item name='id' className='hidden' ><Input /></Form.Item>
<Form.Item name='key' className='hidden' ><Input /></Form.Item>
<Form.Item name='fresh' className='hidden' ><Input /></Form.Item>
<Form.Item <Form.Item
label={t('products:adultPrice')} label={t('products:adultPrice')}
name='adult_cost' name='adult_cost'
@ -571,7 +553,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t('products:Weekdays')} label={t('products:Weekdays')}
name='weekdays' name='weekdayList'
> >
<Checkbox.Group options={['5', '6', '7']} /> <Checkbox.Group options={['5', '6', '7']} />
</Form.Item> </Form.Item>

Loading…
Cancel
Save