diff --git a/src/views/products/Detail.jsx b/src/views/products/Detail.jsx index fdaaf95..145218e 100644 --- a/src/views/products/Detail.jsx +++ b/src/views/products/Detail.jsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; -import { Tooltip, 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 { Tooltip, Button, Card, Col, Row, Breadcrumb, Table, Popconfirm, Form, Input, InputNumber, Tag, Modal, Select, Tree, FloatButton, DatePicker, Spin, message, Divider } from 'antd'; +import { Link, useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { useProductsTypes, useProductsAuditStatesMapVal } from '@/hooks/useProductsSets'; import Extras from './Detail/Extras'; @@ -24,6 +24,7 @@ import { PERM_PRODUCTS_MANAGEMENT } from '@/config'; function Detail() { const { t } = useTranslation(); const [form] = Form.useForm(); + const navigate = useNavigate() const { RangePicker } = DatePicker; const [tags, setTags] = useState([]); const [isModalVisible, setIsModalVisible] = useState(false); @@ -45,7 +46,7 @@ function Detail() { const { Search } = Input; const [addProductVisible, setAddProductVisible] = useState(false); const [editingProduct, setEditingProduct] = useProductsStore((state) => [state.editingProduct, state.setEditingProduct]); - const [agencyProducts, setAgencyProducts] = useProductsStore((state) => [state.agencyProducts, state.setAgencyProducts]); + const [agencyProducts, setAgencyProducts,loading] = useProductsStore((state) => [state.agencyProducts, state.setAgencyProducts, state.loading]); const { getAgencyProducts, activeAgency } = useProductsStore(); const [expandedKeys, setExpandedKeys] = useState([]); const [searchValue, setSearchValue] = useState(''); @@ -59,9 +60,29 @@ function Detail() { const [selectedDays, setSelectedDays] = useState([]); const [weekdays, setWeekdays] = useState([]); const [info, setInfo] = useState(); + const yearOptions = []; + const currentYear = dayjs().year(); + const baseYear = Number(use_year === 'all' ? currentYear : use_year); + for (let i = baseYear - 3; i <= baseYear + 3; i++) { + yearOptions.push({ label: i, value: i, }); + } + const [param, setParam] = useState({ pick_year: baseYear, pick_agency: travel_agency_id }); + const [pickYear, setPickYear] = useState(baseYear); + const handleYearChange = (value) => { + setPickYear(value); + setParam((pre) => ({ ...pre, ...{ pick_year: value } })); + }; + const handleGetAgencyProducts = ({pick_year, pick_agency}={}) => { + const year = pick_year || use_year; + const agency = pick_agency || travel_agency_id; + console.log("loading",loading); + getAgencyProducts({ travel_agency_id: agency, use_year: year, audit_state }); + console.log("loading",loading); + console.log("AgencyProducts",agencyProducts); + }; const travel_agency_name = activeAgency.travel_agency_name; const audit_state_id = activeAgency.audit_state_id; - let isCanEditable = !(audit_state_id === 1 || audit_state_id === 3 || audit_state_id === -1) + let isCanEditable = !(audit_state_id === 1 || audit_state_id === 3 || audit_state_id === -1) const [currentQuotationRecord, setCurrentQuotationRecord] = useState({ use_dates_start: null, use_dates_end: null @@ -76,6 +97,7 @@ function Detail() { ? formatDate(currentQuotationRecord.use_dates_end) : null; + const [editIndex, setEditIndex] = useState(null); const presets = useDatePresets(); const handleBatchImportData = (data) => { @@ -271,13 +293,63 @@ function Detail() { }, []); + useEffect(()=>{ + handleGetAgencyProducts(param); + },[param]); + + useEffect(() => { + editingProductQuotation(); + }, [treeData, editingProduct]) + + const editingProductQuotation = () => { + console.log("editingProduct", editingProduct) + const editingProductID = editingProduct.id; + console.log("editingProductID", editingProductID) + let stopProgram = false; + for (const element of treeData) { + if (stopProgram) { + return; + } + const childList = element.children; + for (const product of childList) { + const childrenID = product.key.split('-')[1]; + if (editingProductID == childrenID) { + const fatherKey = product.key.split('-')[0]; + setSelectedCategory(productProject[fatherKey]); + stopProgram = true; + const tempInfo = product._raw.info; + const tempLgc_details = product._raw.lgc_details.find(record => record.lgc === 2); + console.log("tempLgc_details", tempLgc_details); + const tempQuotation = product._raw.quotation; + console.log({ + info: tempInfo, + lgc_details: { + title: tempLgc_details.title, + description: tempLgc_details.descriptions + }, + }) + setQuotation(tempQuotation); + setTags([languageLabel]); + setRemainderLanguage(HTLanguageSets.filter(item => item.key !== language.toString())); + + form.setFieldsValue({ + info: tempInfo, + lgc_details: { + title: tempLgc_details.title, + description: tempLgc_details.descriptions + }, + }) + break; + } + } + + } + } useEffect(() => { const fetchData = async () => { - if (productsTypes && !dataFetched) { - const agency_id = { travel_agency_id }; - await getAgencyProducts(agency_id); + if (productsTypes.length > 0 && travel_agency_id && Object.keys(agencyProducts).length > 0) { const generateTreeData = (productsTypes, productsData) => { return productsTypes.map(type => ({ title: type.label, @@ -287,56 +359,22 @@ function Detail() { title: product.info.title, key: `${type.value}-${product.info.id}`, _raw: product, - })) + })), })); }; - const tempExpandedKeys = productsTypes.map(item => item.key) + const tempExpandedKeys = productsTypes.map(item => item.key); const treeData = generateTreeData(productsTypes, agencyProducts); - - setDataFetched(true); // 设置标志位为 true,表示数据已获取 setTreeData(treeData); setExpandedKeys(tempExpandedKeys); - console.log("stateMapVal", stateMapVal); setProductsData(agencyProducts); setDefaultData(treeData); setDataList(flattenTreeData(treeData)); + setDataFetched(true); } - }; fetchData(); - }, [agencyProducts, dataFetched]); - - // useEffect(()=>{ - // // if(editingProduct && treeData){ - - // editingProductQuotation(); - // // } - - // },[treeData,editingProduct]) - - // const editingProductQuotation = () => { - // console.log("editingProduct",editingProduct) - // const editingProductID = editingProduct.id; - // let stopProgram = false; - // for (const element of treeData) { - // if (stopProgram) { - // return; - // } - // const childList = element.children; - // for (const product of childList) { - // const childrenID = product.key.split('-')[1]; - // console.log("childrenID",childrenID); - // console.log("editingProductID",editingProductID); - // if (editingProductID == childrenID) { - // console.log("AAAAAAAAAA"); - // console.log("product",product); - // stopProgram = true; - // handleNodeSelect(product); - // break; - // } - // } - // } - // } + }, [productsTypes, travel_agency_id, use_year, audit_state, agencyProducts]); + const flattenTreeData = (tree) => { let flatList = []; const flatten = (nodes) => { @@ -351,17 +389,6 @@ function Detail() { return flatList; }; - // const ProductsSave = async (products) => { - // await postProductsSave(products) - // .then((json)=> { - // if (json.errcode === 0) { - // message.success("保存成功"); - // }else{ - // message.error("保存失败") - // } - // }) - // } - const getParentKey = (key, tree) => { let parentKey; for (let i = 0; i < tree.length; i++) { @@ -425,7 +452,6 @@ function Detail() { const handleDelete = (index) => { const newData = [...quotation]; - // // 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)); @@ -438,7 +464,6 @@ function Detail() { return aGroupSize - bGroupSize; }); - setQuotation(sortedData); }; @@ -569,11 +594,6 @@ function Detail() { }); } - - - - - const handleTagClick = (tag) => { setSelectedTag(tag); const matchedLanguage = HTLanguageSets.find(language => language.label === tag); @@ -657,7 +677,6 @@ function Detail() { //树组件方法 const handleNodeSelect = (_, { node }) => { - console.log("node",node) setSelectedNodeid(node.key); const fatherKey = node.key.split('-')[0]; setSelectedCategory(productProject[fatherKey]); @@ -675,7 +694,6 @@ function Detail() { let infoData = node._raw.info; setInfo(node._raw.info); const newLgcDetails = node._raw.lgc_details - const fatherKey = node.key.split('-')[0]; setSelectedNodeid(node.key); form.setFieldsValue({ info: { @@ -728,6 +746,7 @@ function Detail() { let initialQuotationData = null; let infoData = null; let lgcDetailsData = null; + console.log("") productsData[fatherKey].forEach(element => { if (element.info.id === node._raw.info.id) { initialQuotationData = element.quotation; @@ -956,16 +975,12 @@ function Detail() { return } - - - tempInfo = { ...info, ...values.info, audit_state: "-1" } - console.log("tempInfo", tempInfo) let tempQuotation = quotation.map(element => { @@ -1000,12 +1015,27 @@ function Detail() { return ( -
+
- + + + + + + + +