diff --git a/src/config.js b/src/config.js index c095d1c..d8623ef 100644 --- a/src/config.js +++ b/src/config.js @@ -1,11 +1,9 @@ -import dayjs from "dayjs"; - export const PROJECT_NAME = "GHHub"; -// export const HT_HOST = import.meta.env.PROD ? "https://p9axztuwd7x8a7.mycht.cn" :"http://202.103.68.144:890"; //"http://202.103.68.231:889"; +export const HT_HOST = import.meta.env.PROD ? "https://p9axztuwd7x8a7.mycht.cn" :"http://202.103.68.144:890"; //"http://202.103.68.231:889"; // 内部测试使用,正式环境要切换到上面的配置⬆️ -export const HT_HOST = "http://202.103.68.144:890"; +// export const HT_HOST = "http://202.103.68.144:890"; export const DATE_FORMAT = "YYYY-MM-DD"; export const DATE_FORMAT_MONTH = "YYYY-MM"; diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index aa1e3ce..ed31239 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -130,6 +130,7 @@ export const useProductsStore = create( setAgencyList: (agencyList) => set({ agencyList }), setActiveAgency: (activeAgency) => set({ activeAgency }), setAgencyProducts: (agencyProducts) => set({ agencyProducts }), + // TODO:产品和价格会分开查询编辑, setEditingProduct: (product) => { set(() => ({ editingProduct: product, @@ -170,12 +171,30 @@ export const useProductsStore = create( weekdays: '5, 6' }), + // TODO:添加价格后,重新读取列表 appendQuotationList: (newList) => { set((state) => ({ quotationList: [...state.quotationList, ...newList] })) }, + saveOrUpdateQuotation: (formValues) => { + const { quotationList } = get() + console.info('formValues: ', formValues) + const prevList = quotationList.filter(q => q.id === formValues.id) + console.info(prevList) + if (prevList.length > 0) { + const prevQuotation = prevList[0] + console.info('formValues: ', formValues) + console.info('prevQuotation: ', prevQuotation) + for (const [key, value] of Object.entries(formValues)) { + const prevValue = prevQuotation[key] + const hasChanged = prevValue === value + console.log(`${key}: ${prevValue} - ${value} (${hasChanged})`) + } + } + }, + // side effects searchAgency: async (param) => { const { setLoading, setAgencyList } = get(); diff --git a/src/utils/commons.js b/src/utils/commons.js index bfc5c8c..51b7cc8 100644 --- a/src/utils/commons.js +++ b/src/utils/commons.js @@ -637,3 +637,8 @@ export const formatColonTime = text => { const minutes = text.substring(2); return `${hours}:${minutes}`; }; + +// 生成唯一 36 位数字,用于新增记录 ID 赋值,React key 属性等 +export const generateId = () => ( + new Date().getTime().toString(36) + Math.random().toString(36).substring(2, 9) +) diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index 103de52..ac65f23 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -1,9 +1,9 @@ import { useEffect, useState } from 'react' import { Table, Form, Modal, Button, Radio, Input, Flex, Card, Select, Typography, InputNumber, Checkbox, DatePicker, Space } from 'antd' import { useTranslation } from 'react-i18next' -import dayjs from 'dayjs' import { CloseOutlined, StarTwoTone, PlusOutlined, ExclamationCircleFilled } from '@ant-design/icons'; import { useDatePresets } from '@/hooks/useDatePresets' +import dayjs from 'dayjs' import useProductsStore from '@/stores/Products/Index' const { RangePicker } = DatePicker @@ -245,8 +245,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => { const datePresets = useDatePresets() - const [newEmptyQuotation, appendQuotationList, quotationList] = - useProductsStore((state) => [state.newEmptyQuotation, state.appendQuotationList, state.quotationList]) + const [newEmptyQuotation, appendQuotationList, quotationList, saveOrUpdateQuotation] = + useProductsStore((state) => [state.newEmptyQuotation, state.appendQuotationList, state.quotationList, state.saveOrUpdateQuotation]) useEffect(() => { console.info('quotationList: ', quotationList) @@ -266,9 +266,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => { } const onQuotationFinish = (values) => { - console.info(values) + saveOrUpdateQuotation(values) setQuotationModalOpen(false) - // saveOrUpdateQuotation(values) // .then(() => { // setQuotationModalOpen(false) // }) @@ -282,20 +281,14 @@ const ProductInfoQuotation = ({ editable, ...props }) => { // }) } - const onQuotationFailed = (error) => { - console.log('Failed:', error) - // form.resetFields() - } - const onBatchSetupFinish = () => { - console.info(batchSetupForm.getFieldsValue()) - let previewList = [] + let priceList = [] const defList = batchSetupForm.getFieldsValue().defList defList.forEach(definition => { - const previewPrice = definition?.priceList.map(price => { + const mappedPriceList = definition?.priceList.map(price => { return { - id: 0, + id: null, adult_cost: price.priceInput.audultPrice, child_cost: price.priceInput.childrenPrice, group_size_min: price.priceInput.numberStart, @@ -309,10 +302,10 @@ const ProductInfoQuotation = ({ editable, ...props }) => { weekdays: definition.weekend.join(','), } }) - previewList.push(...previewPrice) + priceList.push(...mappedPriceList) }) - appendQuotationList(previewList) + appendQuotationList(priceList) setBatchSetupModalOpen(false) } @@ -379,18 +372,16 @@ const ProductInfoQuotation = ({ editable, ...props }) => { pagination={false} /> { - // editable && - + editable && + + + + } - { - // editable && - - } - { wrapperCol={{ span: 20 }} className='max-w-2xl' onFinish={onQuotationFinish} - onFinishFailed={onQuotationFailed} autoComplete='off' > {dom}