|
|
|
@ -1,35 +1,51 @@
|
|
|
|
|
import { createContext, useEffect, useState } from 'react';
|
|
|
|
|
import { Breadcrumb, Form, Divider, Button, Input, Select, Row, Col } from 'antd';
|
|
|
|
|
import { App, Breadcrumb, Form, Divider, Button, Input, Select, Row, Col } from 'antd';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { useProductsTypesMapVal, } from '@/hooks/useProductsSets';
|
|
|
|
|
import useProductsStore, { postProductsSave } from '@/stores/Products/Index';
|
|
|
|
|
import { useProductsTypesMapVal, useNewProductRecord } from '@/hooks/useProductsSets';
|
|
|
|
|
import useProductsStore, { postProductsSaveAction } from '@/stores/Products/Index';
|
|
|
|
|
import useAuthStore from '@/stores/Auth';
|
|
|
|
|
import RequireAuth from '@/components/RequireAuth';
|
|
|
|
|
import { PERM_PRODUCTS_MANAGEMENT, PERM_PRODUCTS_OFFER_AUDIT, PERM_PRODUCTS_OFFER_PUT } from '@/config';
|
|
|
|
|
import { PERM_PRODUCTS_MANAGEMENT, PERM_PRODUCTS_OFFER_AUDIT, PERM_PRODUCTS_OFFER_PUT, } from '@/config';
|
|
|
|
|
import DeptSelector from '@/components/DeptSelector';
|
|
|
|
|
import CitySelector from '@/components/CitySelector';
|
|
|
|
|
import { at, isEmpty, pick } from '@/utils/commons';
|
|
|
|
|
import ProductInfoForm from './ProductInfoForm';
|
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
import { usingStorage } from '@/hooks/usingStorage'
|
|
|
|
|
|
|
|
|
|
const ProductInfo = ({ editable, ...props }) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const { notification, message } = App.useApp();
|
|
|
|
|
const { userId } = usingStorage()
|
|
|
|
|
const isPermitted = useAuthStore((state) => state.isPermitted);
|
|
|
|
|
const productsTypesMapVal = useProductsTypesMapVal();
|
|
|
|
|
const [activeAgency, agencyProducts, editingProduct, setEditingProduct] = useProductsStore((state) => [state.activeAgency, state.agencyProducts, state.editingProduct, state.setEditingProduct]);
|
|
|
|
|
const newProduct = useNewProductRecord();
|
|
|
|
|
|
|
|
|
|
const onSave = (err, values, forms) => {
|
|
|
|
|
const [loading, setLoading, ] = useProductsStore((state) => [state.loading, state.setLoading]);
|
|
|
|
|
const [activeAgency, agencyProducts, editingProduct, ] = useProductsStore((state) => [state.activeAgency, state.agencyProducts, state.editingProduct, ]);
|
|
|
|
|
|
|
|
|
|
const onSave = async (err, values, forms) => {
|
|
|
|
|
values.travel_agency_id = activeAgency.travel_agency_id;
|
|
|
|
|
const poster = {
|
|
|
|
|
const copyNewProduct = structuredClone(newProduct);
|
|
|
|
|
const poster = {
|
|
|
|
|
"audit_state": "-1",
|
|
|
|
|
// "create_date": "",
|
|
|
|
|
// "created_by": "",
|
|
|
|
|
// "create_date": dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
// "created_by": userId,
|
|
|
|
|
"travel_agency_id": activeAgency.travel_agency_id,
|
|
|
|
|
// "travel_agency_name": "",
|
|
|
|
|
// "lastedit_changed": "",
|
|
|
|
|
};
|
|
|
|
|
const copyFields = pick(editingProduct.info, ['title', 'product_type_id', ]);
|
|
|
|
|
const readyToSubInfo = {...values.info, ...copyFields, type: copyFields.product_type_id, ...poster };
|
|
|
|
|
console.log('onSave', editingProduct.info, readyToSubInfo);
|
|
|
|
|
const readyToSubInfo = {...copyNewProduct.info, ...values.info, ...copyFields, type: copyFields.product_type_id, ...poster };
|
|
|
|
|
// console.log('onSave', editingProduct.info, readyToSubInfo);
|
|
|
|
|
const prevLgcDetailsMapped = editingProduct.lgc_details.reduce((r, c) => ({...r, [c.lgc]: {...c, description: c.descriptions}}), {}); // todo: description字段不一致
|
|
|
|
|
const mergedLgc = { ...prevLgcDetailsMapped, ...values.lgc_details_mapped };
|
|
|
|
|
// todo: 报价不能为空
|
|
|
|
|
setLoading(true);
|
|
|
|
|
const success = await postProductsSaveAction({ travel_agency_id: activeAgency.travel_agency_id, info: readyToSubInfo, lgc_details: Object.values(mergedLgc), });
|
|
|
|
|
setLoading(false);
|
|
|
|
|
success ? message.success(t('Success')) : message.error(t('Failed'));
|
|
|
|
|
// todo: 保存后更新数据
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|