diff --git a/src/views/products/Detail.jsx b/src/views/products/Detail.jsx
index f624d56..669ce1d 100644
--- a/src/views/products/Detail.jsx
+++ b/src/views/products/Detail.jsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef, useMemo } from 'react';
-import { Button, Card, Col, Row, Breadcrumb, Table, Popconfirm, Form, Input, InputNumber, Tag, Modal, Select, Tree, FloatButton, DatePicker } from 'antd';
+import { Button, Card, Col, Row, Breadcrumb, Table, Popconfirm, Form, Input, InputNumber, Tag, Modal, Select, Tree, FloatButton, DatePicker, Spin, message } from 'antd';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useProductsTypes } from '@/hooks/useProductsSets';
@@ -13,23 +13,22 @@ import dayjs from 'dayjs';
import { PlusCircleFilled } from '@ant-design/icons';
import { DeptSelector } from '@/components/DeptSelector';
import { useDatePresets } from '@/hooks/useDatePresets';
-
+import CitySelector from '@/components/CitySelector';
+import { HT_HOST } from '@/config';
+import { postJSON } from '@/utils/request';
+import { create } from 'zustand';
function Detail() {
const { t } = useTranslation();
const [form] = Form.useForm();
const { RangePicker } = DatePicker;
- const [editingid, setEditingid] = useState('');
const [tags, setTags] = useState([]);
const [isModalVisible, setIsModalVisible] = useState(false);
const [selectedTag, setSelectedTag] = useState(null);
- const [saveData, setSaveData] = useState(null);
const [batchImportPriceVisible, setBatchImportPriceVisible] = useState(false);
const [quotationTableVisible, setQuotationTableVisible] = useState(false)
- const [currentid, setCurrentid] = useState(null);
const [languageStatus, setLanguageStatus] = useState(null);
const [selectedNodeid, setSelectedNodeid] = useState(null);
const [remainderLanguage, setRemainderLanguage] = useState([])
- const [selectedDateData, setSelectedDateData] = useState({ dateRange: null, selectedDays: [] });
const [treeData, setTreeData] = useState([]);
const productsTypes = useProductsTypes();
const [productsData, setProductsData] = useState(null);
@@ -44,7 +43,7 @@ function Detail() {
const [addProductVisible, setAddProductVisible] = useState(false);
const [editingProduct, setEditingProduct] = useProductsStore((state) => [state.editingProduct, state.setEditingProduct]);
const [agencyProducts, setAgencyProducts] = useProductsStore((state) => [state.agencyProducts, state.setAgencyProducts]);
- const { getAgencyProducts } = useProductsStore();
+ const { getAgencyProducts, activeAgency } = useProductsStore();
const [expandedKeys, setExpandedKeys] = useState([]);
const [searchValue, setSearchValue] = useState('');
const [autoExpandParent, setAutoExpandParent] = useState(true);
@@ -56,7 +55,9 @@ function Detail() {
const [dataFetched, setDataFetched] = useState(false); // 添加一个标志位
const [selectedNodeKey, setSelectedNodeKey] = useState(null);
const [selectedDays, setSelectedDays] = useState([]);
- const [weekdays,setWeekdays] = useState([]);
+ const [weekdays, setWeekdays] = useState([]);
+ const [info, setInfo] = useState();
+ const travel_agency_name = activeAgency.travel_agency_name;
const [currentQuotationRecord, setCurrentQuotationRecord] = useState({
use_dates_start: null,
use_dates_end: null
@@ -154,8 +155,6 @@ function Detail() {
if (productsTypes && !dataFetched) {
const agency_id = { travel_agency_id };
await getAgencyProducts(agency_id);
- console.log("agencyProducts", agencyProducts)
- console.log("productsTypes", productsTypes)
const generateTreeData = (productsTypes, productsData) => {
return productsTypes.map(type => ({
title: type.label,
@@ -169,19 +168,17 @@ function Detail() {
}));
};
const tempExpandedKeys = productsTypes.map(item => item.key)
- console.log("tempExpandedKeys", tempExpandedKeys)
const treeData = generateTreeData(productsTypes, agencyProducts);
- console.log("treeData", treeData)
setDataFetched(true); // 设置标志位为 true,表示数据已获取
setTreeData(treeData);
- setExpandedKeys(tempExpandedKeys)
+ setExpandedKeys(tempExpandedKeys);
+ console.log("agencyProducts", agencyProducts)
setProductsData(agencyProducts);
setDefaultData(treeData);
setDataList(flattenTreeData(treeData));
}
};
-
fetchData();
}, [agencyProducts, dataFetched]);
@@ -244,7 +241,6 @@ function Detail() {
.filter(item => item.title.includes(value))
.map(item => getParentKey(item.key, defaultData))
.filter((item, i, self) => item && self.indexOf(item) === i);
- console.log("newExpandedKeys", newExpandedKeys)
setExpandedKeys(newExpandedKeys);
setSearchValue(value);
setAutoExpandParent(true);
@@ -255,13 +251,9 @@ function Detail() {
setAutoExpandParent(false);
};
- const isEditing = (record) => record.id === editingid;
-
const edit = (record, index) => {
setQuotationTableVisible(true);
setEditIndex(index);
- // record.use_dates_start = dayjs(record.use_dates_start);
- // record.use_dates_end = dayjs(record.use_dates_end);
setCurrentQuotationRecord(record);
};
@@ -269,36 +261,38 @@ function Detail() {
setEditingid('');
};
- const handleDelete = (id) => {
+ const handleDelete = (index) => {
const newData = [...quotation];
- const index = newData.findIndex((item) => id === item.id);
+ // // const index = newData.findIndex((item) => id === item.id);
newData.splice(index, 1);
-
const sortedData = [...newData].sort((a, b) => {
const aValidPeriod = dayjs(a.use_dates_end).diff(dayjs(a.use_dates_start));
const bValidPeriod = dayjs(b.use_dates_end).diff(dayjs(b.use_dates_start));
if (aValidPeriod !== bValidPeriod) {
- return aValidPeriod - bValidPeriod;
+ return aValidPeriod - bValidPeriod;
}
const aGroupSize = a.group_size_max - a.group_size_min;
const bGroupSize = b.group_size_max - b.group_size_min;
return aGroupSize - bGroupSize;
- });
+ });
setQuotation(sortedData);
};
const handleAdd = () => {
const newData = {
- value: '',
+ adult_cost: 0,
+ child_cost: 0,
currency: '',
- unit_name: '',
- weekdays: '',
+ group_size_min: 0,
+ group_size_max: 0,
+ id: '',
+ lastedit_changed: '',
use_dates_start: '',
use_dates_end: '',
- group_size_min: '',
- group_size_max: ''
+ weekdays: '',
+ tempKey: Math.random()
};
setQuotation([...quotation, newData]);
};
@@ -307,33 +301,23 @@ function Detail() {
setBatchImportPriceVisible(true);
}
- const handleDateSelect = (id) => {
- setCurrentid(id);
- setDatePickerVisible(true);
- };
-
const quotationTableVisibleOK = () => {
currentQuotationRecord.use_dates_start = dayjs(currentQuotationRecord.use_dates_start).format('YYYY-MM-DD')
currentQuotationRecord.use_dates_end = dayjs(currentQuotationRecord.use_dates_end).format('YYYY-MM-DD')
- console.log("currentQuotationRecord", currentQuotationRecord);
- console.log("qqqqq", quotation)
const tempQuotation = [...quotation];
- tempQuotation[editIndex] = { ...currentQuotationRecord,weekdays:weekdays };
- console.log("tempQuotation", tempQuotation)
+ tempQuotation[editIndex] = { ...currentQuotationRecord, weekdays: weekdays };
const sortedData = [...tempQuotation].sort((a, b) => {
const aValidPeriod = dayjs(a.use_dates_end).diff(dayjs(a.use_dates_start));
const bValidPeriod = dayjs(b.use_dates_end).diff(dayjs(b.use_dates_start));
if (aValidPeriod !== bValidPeriod) {
- return aValidPeriod - bValidPeriod;
+ return aValidPeriod - bValidPeriod;
}
const aGroupSize = a.group_size_max - a.group_size_min;
const bGroupSize = b.group_size_max - b.group_size_min;
return aGroupSize - bGroupSize;
- });
- console.log("sortedData",sortedData)
-
+ });
setQuotation(sortedData);
setQuotationTableVisible(false);
}
@@ -343,14 +327,9 @@ function Detail() {
const handleBatchImportOK = () => {
- console.log("quotation", quotation)
- console.log('Batch Import Data:', batchImportData);
-
-
-
const tempBatchImportData = batchImportData.map(item => {
const { tag, validPeriod, ...rest } = item;
- return rest;
+ return rest;
});
const newData = [...quotation, ...tempBatchImportData];
const sortedData = [...newData].sort((a, b) => {
@@ -372,7 +351,13 @@ function Detail() {
{ title: t('products:adultPrice'), dataIndex: 'adult_cost', width: '10%', editable: true },
{ title: t('products:childrenPrice'), dataIndex: 'child_cost', width: '10%', editable: true },
{ title: t('products:currency'), dataIndex: 'currency', width: '10%', editable: true },
- { title: t('products:Types'), dataIndex: 'unit_name', width: '10%', editable: true },
+ {
+ title: t('products:Types'),
+ dataIndex: 'unit',
+ width: '10%',
+ editable: true,
+ render: (text) => (text === '0' ? '每人' : text === '1' ? '每团' : text),
+ },
{
title: t('products:number'),
dataIndex: 'group_size',
@@ -398,7 +383,7 @@ function Detail() {
return (
edit(record, index)} style={{ marginRight: 8 }}>{t('Edit')}
- handleDelete(record.id)}>
+ handleDelete(index)}>
{t('Delete')}
@@ -409,23 +394,6 @@ function Detail() {
];
- // const mergedColumns = columns.map((col) => {
- // if (!col.editable) {
- // return col;
- // }
- // return {
- // ...col,
- // onCell: (record) => ({
- // record,
- // inputType: col.dataIndex === 'age' ? 'number' : 'text',
- // dataIndex: col.dataIndex,
- // title: col.title,
- // editing: isEditing(record),
- // handleDateSelect: handleDateSelect,
- // }),
- // };
- // });
-
const handleTagClick = (tag) => {
setSelectedTag(tag);
const matchedLanguage = HTLanguageSets.find(language => language.label === tag);
@@ -433,7 +401,7 @@ function Detail() {
form.setFieldsValue({
lgc_details: {
title: lgc_details[key] ? lgc_details[key].title : '',
- descriptions: lgc_details[key] ? lgc_details[key].descriptions : ''
+ description: lgc_details[key] ? lgc_details[key].description : ''
}
});
setLanguageStatus(key)
@@ -458,7 +426,8 @@ function Detail() {
...lgc_details, [languageKey]: {
title: "",
lgc: languageKey,
- descriptions: ""
+ description: "",
+ id: ""
}
}
setLgc_details(tempLgc_details)
@@ -475,7 +444,6 @@ function Detail() {
const handleTagChange = (value) => {
- console.log("handleTagChange", value)
setSelectedTag(value);
};
@@ -483,9 +451,13 @@ function Detail() {
// 更新整个 lgc_details 对象
const updatedLgcDetails = {
...lgc_details,
- [languageStatus]: { ...lgc_details[languageStatus], [field]: value, lgc: languageStatus }
+ [languageStatus]: {
+ ...lgc_details[languageStatus],
+ [field]: value,
+ lgc: languageStatus.toString(),
+ id: lgc_details[languageStatus]?.id || ''
+ }
};
- console.log("updatedLgcDetails", updatedLgcDetails)
setLgc_details(updatedLgcDetails)
};
@@ -497,144 +469,190 @@ function Detail() {
const updatedDays = prevSelectedDays.includes(dayOfWeek)
? prevSelectedDays.filter((d) => d !== dayOfWeek)
: [...prevSelectedDays, dayOfWeek];
- console.log("updatedDays",updatedDays);
const weekdaysString = updatedDays.sort().join(',');
- console.log("weekdaysString",weekdaysString)
- setWeekdays(weekdaysString)
+ setWeekdays(weekdaysString);
return updatedDays;
});
};
//树组件方法
const handleNodeSelect = (_, { node }) => {
+ setSelectedNodeid(node.key);
+ const fatherKey = node.key.split('-')[0];
+ setSelectedNodeKey(fatherKey);
+ setSelectedCategory(productProject[fatherKey]);
+ setTags([languageLabel]);
+ // 如果点击的是同一个节点,不做任何操作
+ if (selectedNodeid === node.key) return;
+ setLanguageStatus(language);
+ const matchedLanguage = HTLanguageSets.find(HTLanguage => HTLanguage.key === language.toString());
+ const languageLabelRefresh = matchedLanguage.label;
+ setLanguageLabel(languageLabelRefresh);
+ setSelectedTag(languageLabelRefresh);
+ setRemainderLanguage(HTLanguageSets.filter(item => item.key !== language.toString()));
+ setEditingProduct(node._raw);
if (!node._raw.info.id) {
- console.log("nodeNoID", node)
- setQuotation([])
- const infoData = node._raw.info
+ let infoData = node._raw.info;
+ setInfo(node._raw.info);
+ console.log("node._raw",node._raw)
+ console.log("没有id");
const newLgcDetails = node._raw.lgc_details
const fatherKey = node.key.split('-')[0];
setSelectedNodeid(node.key);
setSelectedNodeKey(fatherKey);
form.setFieldsValue({
info: {
- title: infoData.title,
- code: infoData.code,
- product_type_name: infoData.product_type_name,
- city_name: infoData.city_name,
- remarks: infoData.remarks,
- open_weekdays: infoData.open_weekdays,
- recommends_rate: infoData.recommends_rate,
- duration: infoData.duration,
- dept: infoData.dept,
- km: infoData.km,
- dept_name: infoData.dept_name,
+ id: infoData.id || "",
+ title: infoData.title || "",
+ code: infoData.code || "",
+ type: infoData.product_type_id || "",
+ audit_state:"-1",
+ create_date: infoData.create_date || "",
+ created_by: infoData.created_by || "",
+ travel_agency_id: travel_agency_id || "",
+ travel_agency_name: activeAgency.travel_agency_name || "",
+ lastedit_changed: infoData.lastedit_changed || "",
+ remarks: infoData.remarks || "",
+ duration: infoData.duration || "",
+ duration_unit: infoData.duration_unit || "",
+ open_weekdays: infoData.open_weekdays || "",
+ recommends_rate: infoData.recommends_rate || "",
+ dept: infoData.dept_id || "",
+ display_to_c: infoData.display_to_c || "",
+ km: infoData.km || "",
+ city_name: infoData.city_name || "",
+ city_id: infoData.city_id || "",
+ // product_type_name: infoData.product_type_name || "",
+ // dept_name: infoData.dept_name || "",
+
},
lgc_details: {
lgc: language,
title: newLgcDetails[language]?.title || '',
- descriptions: newLgcDetails[language]?.descriptions || ''
+ description: newLgcDetails[language]?.description || ''
}
})
+ setLgc_details([])
+ setQuotation([{
+ adult_cost: 0,
+ child_cost: 0,
+ currency: '',
+ group_size_min: 0,
+ group_size_max: 0,
+ id: '',
+ lastedit_changed: '',
+ use_dates_start: '',
+ use_dates_end: '',
+ weekdays: '',
+ tempKey: Math.random()
+ }])
return
- }
-
-
- setTags([languageLabel])
- // 如果点击的是同一个节点,不做任何操作
- if (selectedNodeid === node.key) return;
-
- setSelectedNodeid(node.key);
- const fatherKey = node.key.split('-')[0];
- setSelectedNodeKey(fatherKey);
- console.log("node.key", node.key);
- console.log("fatherKey", fatherKey)
- setSelectedCategory(productProject[fatherKey]);
+ } else {
- setLanguageStatus(language);
- const matchedLanguage = HTLanguageSets.find(HTLanguage => HTLanguage.key === language.toString());
- const languageLabelRefresh = matchedLanguage.label;
- setLanguageLabel(languageLabelRefresh);
- setSelectedTag(languageLabelRefresh);
- setRemainderLanguage(HTLanguageSets.filter(item => item.key !== language.toString()));
+
+
+ let initialQuotationData = null;
+ let infoData = null;
+ let lgcDetailsData = null;
+ productsData[fatherKey].forEach(element => {
+ if (element.info.id === node._raw.info.id) {
+ initialQuotationData = element.quotation;
+ infoData = element.info;
+ lgcDetailsData = element.lgc_details.map(item => {
+ const newItem = {
+ ...item,
+ description: item.descriptions,
+ };
+ delete newItem.descriptions;
+ return newItem;
+ });
+ }
+ });
+ const quotationData = initialQuotationData.map(element => {
+ const updatedObject = {
+ ...element,
+ unit: element.unit_id,
+ tempKey: Math.random()
+ };
+ delete updatedObject.unit_name;
+ delete updatedObject.unit_id;
+ delete updatedObject.audit_state_id;
+ delete updatedObject.audit_state_name;
+ return updatedObject;
+ });
- setEditingProduct(node._raw);
+ if (!node._raw.info.id) {
- let initialQuotationData = null;
- let infoData = null;
- let lgcDetailsData = null;
- console.log("productsData", productsData)
- console.log("productsData[fatherKey]", productsData[fatherKey])
- console.log("node", node)
- // console.log("node",node._raw)
- productsData[fatherKey].forEach(element => {
- if (element.info.id === node._raw.info.id) {
- initialQuotationData = element.quotation;
- infoData = element.info;
- lgcDetailsData = element.lgc_details;
}
- });
+ // 累积 lgc_details 数据
+ let newLgcDetails = {};
+ if (lgcDetailsData) {
+ lgcDetailsData.forEach(element => {
+ newLgcDetails[element.lgc] = element;
+ });
+ }
- if (!node._raw.info.id) {
+ if (node._raw.info.id) {
+ setInfoDataForId(infoData.id)
+ }
+ setLgc_details(newLgcDetails);
- }
- console.log("lgcDetailsData", lgcDetailsData)
- // 累积 lgc_details 数据
- let newLgcDetails = {};
- if (lgcDetailsData) {
- lgcDetailsData.forEach(element => {
- newLgcDetails[element.lgc] = element;
- });
- }
- console.log("infoData", infoData)
- console.log("laug", language)
+ let sortedData = [...quotationData].sort((a, b) => {
+ // 计算有效期范围大小
+ const aValidPeriod = dayjs(a.use_dates_end).diff(dayjs(a.use_dates_start));
+ const bValidPeriod = dayjs(b.use_dates_end).diff(dayjs(b.use_dates_start));
- if (node._raw.info.id) {
- setInfoDataForId(infoData.id)
- }
- setLgc_details(newLgcDetails);
+ // 按照有效期范围大小升序排序
+ if (aValidPeriod !== bValidPeriod) {
+ return aValidPeriod - bValidPeriod;
+ }
+ // 如果有效期范围相同,则按照人数范围大小升序排序
+ const aGroupSize = a.group_size_max - a.group_size_min;
+ const bGroupSize = b.group_size_max - b.group_size_min;
- const sortedData = [...initialQuotationData].sort((a, b) => {
- // 计算有效期范围大小
- const aValidPeriod = dayjs(a.use_dates_end).diff(dayjs(a.use_dates_start));
- const bValidPeriod = dayjs(b.use_dates_end).diff(dayjs(b.use_dates_start));
+ return aGroupSize - bGroupSize;
+ });
- // 按照有效期范围大小升序排序
- if (aValidPeriod !== bValidPeriod) {
- return aValidPeriod - bValidPeriod;
+ const tempInfo = {
+ id: infoData.id || "",
+ title: infoData.title || "",
+ code: infoData.code || "",
+ type: infoData.product_type_id || "",
+ create_date: infoData.create_date || "",
+ created_by: infoData.created_by || "",
+ travel_agency_id: travel_agency_id || "",
+ travel_agency_name: activeAgency.travel_agency_name || "",
+ lastedit_changed: infoData.lastedit_changed || "",
+ remarks: infoData.remarks || "",
+ duration: infoData.duration || "",
+ duration_unit: infoData.duration_unit || "",
+ open_weekdays: infoData.open_weekdays || "",
+ recommends_rate: infoData.recommends_rate || "",
+ dept: infoData.dept_id || "",
+ display_to_c: infoData.display_to_c || "",
+ km: infoData.km || "",
+ city_name: infoData.city_name || "",
+ city_id: infoData.city_id || "",
+ product_type_name: infoData.product_type_name || "",
+ dept_name: infoData.dept_name || "",
+ };
+ setInfo(tempInfo);
+ setQuotation(sortedData);
+ if (node._raw.info.id) {
+ form.setFieldsValue({
+ info: tempInfo,
+ lgc_details: {
+ lgc: language,
+ title: newLgcDetails[language]?.title || '',
+ description: newLgcDetails[language]?.description || ''
+ }
+ });
}
- // 如果有效期范围相同,则按照人数范围大小升序排序
- const aGroupSize = a.group_size_max - a.group_size_min;
- const bGroupSize = b.group_size_max - b.group_size_min;
-
- return aGroupSize - bGroupSize;
- });
- setQuotation(sortedData);
- if (node._raw.info.id) {
- form.setFieldsValue({
- info: {
- title: infoData.title,
- code: infoData.code,
- product_type_name: infoData.product_type_name,
- city_name: infoData.city_name,
- remarks: infoData.remarks,
- open_weekdays: infoData.open_weekdays,
- recommends_rate: infoData.recommends_rate,
- duration: infoData.duration,
- dept: infoData.dept,
- km: infoData.km,
- dept_name: infoData.dept_name,
- },
- lgc_details: {
- lgc: language,
- title: newLgcDetails[language]?.title || '',
- descriptions: newLgcDetails[language]?.descriptions || ''
- }
- });
}
};
@@ -642,187 +660,245 @@ function Detail() {
const handelAddProduct = () => {
// 找到对应的产品类型节点
const productTypeNode = treeData.find(item => item.key === addProductType);
- console.log("productTypeNode", productTypeNode);
-
- if (productTypeNode) {
- // 在 children 数组中插入新的产品节点
- const newChildren = [
- ...productTypeNode.children,
- {
- title: addproductName,
- key: `${addProductType}-${Date.now()}`, // 使用时间戳作为唯一的 key
- _raw: {
- info: { code: '' },
- lgc_details: [],
- quotation: []
- }
- }
- ];
- // 创建新的 treeData 数组,确保 React 能够检测到更改
- const newTreeData = treeData.map(item => {
- if (item.key === addProductType) {
- return {
- ...item,
- children: newChildren,
- };
- }
- return item;
- });
- // 更新 treeData
- setEditingProduct(null)
- setTreeData(newTreeData);
- }
-
- console.log("productData", productsData)
- console.log("addProductType", addProductType)
- let tempProductDataList = productsData[addProductType];
-
- //初始化产品数据
- const newProduct = {
+ console.log("productTypeNode", productTypeNode)
+ // if (productTypeNode) {
+ // // 在 children 数组中插入新的产品节点
+ const tempAddData = {
info: {
- code: 'addProduct'
+ id: "",
+ title: addproductName,
+ code: "",
+ type: addProductType,
+ create_date: "",
+ created_by: "",
+ travel_agency_id: "",
+ travel_agency_name: "",
+ lastedit_changed: "",
+ remarks: "",
+ duration: "",
+ duration_unit: "",
+ open_weekdays: "",
+ recommends_rate: "",
+ dept: "",
+ display_to_c: "",
+ km: "",
+ city_name: "",
+ city_id: "",
+ product_type_name: "",
+ dept_name: "",
},
- quotation: [],
- lgc_details: []
+ lgc_details: [
+ ],
+ quotation: []
}
- tempProductDataList.push(newProduct);
- console.log("tempProductDataList", tempProductDataList)
+ const newChildren = [
+ ...productTypeNode.children,
+ {
+ title: addproductName,
+ key: `${addProductType}-${Date.now()}`,
+ _raw: tempAddData
+ }
+
+ ];
+ // // 创建新的 treeData 数组,确保 React 能够检测到更改
+ const newTreeData = treeData.map(item => {
+ if (item.key === addProductType) {
+ return {
+ ...item,
+ children: newChildren,
+ };
+ }
+ return item;
+ });
+ // 更新 treeData
+ setEditingProduct(null)
+ console.log("newTreeData", newTreeData);
+ setTreeData(newTreeData);
+
+ let tempProductDataList = productsData[addProductType];
+ tempProductDataList.push(tempAddData);
const newProductsData = {
...productsData, // 假设使用了展开运算符来复制现有数组
[addProductType]: tempProductDataList
};
setProductsData(newProductsData);
- console.log("newProductsData", newProductsData)
setAddProductVisible(false);
+ }
+
+ // let tempProductDataList = productsData[addProductType];
+
+ // //初始化产品数据
+ // const newProduct = {
+ // info: {
+ // code: 'addProduct'
+ // },
+ // quotation: [],
+ // lgc_details: []
+ // }
+ // tempProductDataList.push(newProduct);
+ // const newProductsData = {
+ // ...productsData, // 假设使用了展开运算符来复制现有数组
+ // [addProductType]: tempProductDataList
+ // };
+ // setProductsData(newProductsData);
+ // setAddProductVisible(false);
+ // };
+
+
+ const renderFormItem = (item) => {
+ switch (item.code) {
+ case "duration":
+ return ;
+ case "display_to_c":
+ return (
+
+ );
+ case "dept_name":
+ return ;
+ case "city_name":
+ return ;
+ default:
+ return ;
+ }
};
- const onSave = (values) => {
- // 找到匹配的树节点
- let matchedTreeData = treeData.find(treeKey => treeKey.key === selectedNodeKey);
- if (matchedTreeData) {
- // 找到匹配的子节点
- const matchedTreeDataChildren = matchedTreeData.children;
- // 检查是否已存在具有 selectedNodeid 的子节点
- console.log("matchedTreeDataChildren", matchedTreeDataChildren)
- console.log("selectedNodeid", selectedNodeid)
- // if (matchedTreeDataChildren.some(child => child.key === selectedNodeid)) {
- // console.log("Child with this ID already exists.");
- // return;
- // }
- let tempTreeDataChildrenData = matchedTreeDataChildren.find(element => element.key === selectedNodeid);
- console.log("tempTreeDataChildrenData", tempTreeDataChildrenData);
- // if (tempTreeDataChildrenData) {
- tempTreeDataChildrenData._raw = values;
- console.log("tempTreeDataChildrenData改", tempTreeDataChildrenData)
- console.log("treeData111111", treeData)
- console.log("lgc_details", lgc_details)
- tempTreeDataChildrenData._raw.lgc_details = lgc_details
- // console.log("matchedTreeData", matchedTreeData)
- // if (!matchedTreeData.children.some(element => element.key === selectedNodeid)) {
- // console.log("重复了");
- // matchedTreeData.children.push(tempTreeDataChildrenData)
- // console.log("matchedTreeData改", matchedTreeData)
- // return;
- // }
-
-
- // } else {
- // console.log("No matching child node found.");
- // }
+ const onSave = async (values) => {
+ let tempInfo
+ console.log("values", values)
+ console.log("info", info)
+ if (info.id === "") {
+ tempInfo = {
+ ...info,
+ ...values.info,
+ city_name: values.info.city_name.label,
+ audit_state:"-1"
+ }
+ delete tempInfo.product_type_name;
+ delete tempInfo.dept_name;
+
+ console.log("新增")
+
+ let tempQuotation = quotation.map(element => {
+ const updateData = {
+ ...element,
+ audit_state: "-1"
+ }
+ delete updateData.tempKey
+ return updateData
+ })
+ let tempLgc_details = [{...lgc_details}]
+ console.log("tempLgc_details",tempLgc_details)
+ const tempData = {
+ travel_agency_id,
+ info: tempInfo,
+ quotation: tempQuotation,
+ lgc_details: Object.values(lgc_details)
+ };
+ console.log("tempData",tempData);
+
+ const { errcode, result } = await postJSON(`${HT_HOST}/Service_BaseInfoWeb/agency_product_save`, tempData);
+ console.log("result",result)
+ if (errcode === 0) {
+ message.success("保存成功");
+ setDataFetched(false);
+ } else {
+ message.error(`保存失败: ${result}`);
+ }
+ return
} else {
- console.log("No matching tree node found.");
+ tempInfo = {
+ ...info,
+ ...values.info,
+ audit_state: "-1"
+ }
}
+ console.log("tempInfo", tempInfo)
+ let tempQuotation = quotation.map(element => {
+ const updateData = {
+ ...element,
+ audit_state: "-1"
+ }
+ return updateData
+ })
- // if (infoDataForId) {
- // // 创建新的 tempData 对象
- // const tempData = {
- // ...values,
- // info: { ...values.info, id: infoDataForId },
- // quotation: quotation,
- // lgc_details: Object.values(lgc_details)
- // };
+ const tempData = {
+ travel_agency_id,
+ info: tempInfo,
+ quotation: tempQuotation,
+ lgc_details: Object.values(lgc_details)
+ };
- // setSaveData(tempData);
- // console.log("保存的数据", tempData);
- // } else {
- // // 创建新的 tempData 对象
- // const tempData = {
- // ...values,
- // info: { ...values.info },
- // quotation: quotation,
- // lgc_details: Object.values(lgc_details)
- // };
+ console.log("tempData", tempData)
+ const { errcode, result } = await postJSON(`${HT_HOST}/Service_BaseInfoWeb/agency_product_save`, tempData);
- // setSaveData(tempData);
- // console.log("保存的数据", tempData);
- // }
+ if (errcode === 0) {
+ message.success("保存成功");
+ setDataFetched(false);
+ } else {
+ message.error(`保存失败: ${result}`);
+ }
+
+ return
};
return (
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
- {/* */}
-
- {/* */}
- } onClick={() => setAddProductVisible(true)} />
-
-
+ {/*
*/}
+
+ {/* */}
+
} onClick={() => setAddProductVisible(true)} />
+
+
- {
- batchImportPriceVisible && (
-
setBatchImportPriceVisible(false)}
- width="80%"
- >
-
-
- )
- }
+ {
+ (
+
setBatchImportPriceVisible(false)}
+ width="80%"
+ >
+
+
+ )
+ }
- {
- addProductVisible && (
-
setAddProductVisible(false)}
- >
- 选择产品类别
-
-
-
- 新增产品名称
- setAddProductName(e.target.value)}
- />
-
- )
- }
+
选择产品类别
- {
- quotationTableVisible && (
-
- 成人价
- setCurrentQuotationRecord({ ...currentQuotationRecord, adult_cost: e })} />
- 儿童价
- setCurrentQuotationRecord({ ...currentQuotationRecord, child_cost: e })} />
- 币种
-
- 类型
-
-
- 人等
-
- setCurrentQuotationRecord({ ...currentQuotationRecord, group_size_min: e })}
- style={{ width: '50%', marginRight: '10px' }}
+
+
+ 新增产品名称
+ setAddProductName(e.target.value)}
/>
- -
- setCurrentQuotationRecord({ ...currentQuotationRecord, group_size_max: e })}
- style={{ width: '50%', marginLeft: '10px' }}
+
+ )
+ }
+
+ {
+ (
+
+ 成人价
+ setCurrentQuotationRecord({ ...currentQuotationRecord, adult_cost: e })} />
+ 儿童价
+ setCurrentQuotationRecord({ ...currentQuotationRecord, child_cost: e })} />
+ 币种
+
+ 类型
+
+
+ 人等
+
+ setCurrentQuotationRecord({ ...currentQuotationRecord, group_size_min: e })}
+ style={{ width: '50%', marginRight: '10px' }}
+ />
+ -
+ setCurrentQuotationRecord({ ...currentQuotationRecord, group_size_max: e })}
+ style={{ width: '50%', marginLeft: '10px' }}
+ />
+ |
+ 有效期
+ {
+ setCurrentQuotationRecord({
+ ...currentQuotationRecord,
+ use_dates_start: dates[0],
+ use_dates_end: dates[1]
+ });
+ }}
/>
- |
- 有效期
- {
- setCurrentQuotationRecord({
- ...currentQuotationRecord,
- use_dates_start: dates[0],
- use_dates_end: dates[1]
- });
- }}
- />
- 周末
- {days.map((day, index) => (
-
- ))}
+ 周末
+ {days.map((day, index) => (
+
+ ))}
-
+
- )
- }
-
+ )
+ }
+
+
);
}
export default Detail;