|
|
@ -5,7 +5,7 @@ import { useProductsTypesMapVal, useNewProductRecord } from '@/hooks/useProducts
|
|
|
|
import useProductsStore, { postProductsSaveAction } from '@/stores/Products/Index';
|
|
|
|
import useProductsStore, { postProductsSaveAction } from '@/stores/Products/Index';
|
|
|
|
import useAuthStore from '@/stores/Auth';
|
|
|
|
import useAuthStore from '@/stores/Auth';
|
|
|
|
import { PERM_PRODUCTS_MANAGEMENT, PERM_PRODUCTS_OFFER_PUT, PERM_PRODUCTS_INFO_PUT, PERM_PRODUCTS_NEW } from '@/config';
|
|
|
|
import { PERM_PRODUCTS_MANAGEMENT, PERM_PRODUCTS_OFFER_PUT, PERM_PRODUCTS_INFO_PUT, PERM_PRODUCTS_NEW } from '@/config';
|
|
|
|
import { isEmpty, pick } from '@/utils/commons';
|
|
|
|
import { isEmpty, objectMapper, pick, unique } from '@/utils/commons';
|
|
|
|
import ProductInfoForm from './ProductInfoForm';
|
|
|
|
import ProductInfoForm from './ProductInfoForm';
|
|
|
|
import { usingStorage } from '@/hooks/usingStorage';
|
|
|
|
import { usingStorage } from '@/hooks/usingStorage';
|
|
|
|
import Extras from './Extras';
|
|
|
|
import Extras from './Extras';
|
|
|
@ -50,13 +50,20 @@ const ProductInfo = ({ ...props }) => {
|
|
|
|
|
|
|
|
|
|
|
|
setLgcEdits({});
|
|
|
|
setLgcEdits({});
|
|
|
|
setInfoEditStatus('');
|
|
|
|
setInfoEditStatus('');
|
|
|
|
|
|
|
|
setEditKeys([]);
|
|
|
|
return () => {};
|
|
|
|
return () => {};
|
|
|
|
}, [activeAgency, editingProduct]);
|
|
|
|
}, [activeAgency, editingProduct]);
|
|
|
|
|
|
|
|
|
|
|
|
const [infoEditStatus, setInfoEditStatus] = useState('');
|
|
|
|
const [infoEditStatus, setInfoEditStatus] = useState('');
|
|
|
|
const [lgcEdits, setLgcEdits] = useState({});
|
|
|
|
const [lgcEdits, setLgcEdits] = useState({});
|
|
|
|
const onValuesChange = (changedValues, forms) => {
|
|
|
|
// const [editChanged, setEditChanged] = useState({});
|
|
|
|
|
|
|
|
const [editKeys, setEditKeys] = useState([]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onValuesChange = (changedValues) => {
|
|
|
|
// console.log('onValuesChange', changedValues);
|
|
|
|
// console.log('onValuesChange', changedValues);
|
|
|
|
|
|
|
|
const changedKeys = objectMapper(changedValues, { 'city': 'city_id', 'dept': 'dept_id', 'product_title': 'title'});
|
|
|
|
|
|
|
|
setEditKeys(prev => unique([...prev, ...Object.keys(changedKeys)]));
|
|
|
|
|
|
|
|
// const preValues = pick(editingProduct.info, editKeys);
|
|
|
|
if ('product_title' in changedValues) {
|
|
|
|
if ('product_title' in changedValues) {
|
|
|
|
setInfoEditStatus('2');
|
|
|
|
setInfoEditStatus('2');
|
|
|
|
setLgcEdits({...lgcEdits, '2': {'edit_status': '2'}});
|
|
|
|
setLgcEdits({...lgcEdits, '2': {'edit_status': '2'}});
|
|
|
@ -71,6 +78,9 @@ const ProductInfo = ({ ...props }) => {
|
|
|
|
|
|
|
|
|
|
|
|
const onSave = async (err, values, forms) => {
|
|
|
|
const onSave = async (err, values, forms) => {
|
|
|
|
values.travel_agency_id = activeAgency.travel_agency_id;
|
|
|
|
values.travel_agency_id = activeAgency.travel_agency_id;
|
|
|
|
|
|
|
|
const editChanged = pick(editingProduct.info, editKeys);
|
|
|
|
|
|
|
|
// console.log("editKeys pre values", editKeys, editChanged);
|
|
|
|
|
|
|
|
|
|
|
|
const copyNewProduct = structuredClone(newProductRecord);
|
|
|
|
const copyNewProduct = structuredClone(newProductRecord);
|
|
|
|
const poster = {
|
|
|
|
const poster = {
|
|
|
|
// ...(topPerm ? { } : { 'audit_state': -1 }), // 高级权限: 不变更状态值
|
|
|
|
// ...(topPerm ? { } : { 'audit_state': -1 }), // 高级权限: 不变更状态值
|
|
|
@ -78,9 +88,10 @@ const ProductInfo = ({ ...props }) => {
|
|
|
|
// "created_by": userId,
|
|
|
|
// "created_by": userId,
|
|
|
|
'travel_agency_id': activeAgency.travel_agency_id,
|
|
|
|
'travel_agency_id': activeAgency.travel_agency_id,
|
|
|
|
// "travel_agency_name": "",
|
|
|
|
// "travel_agency_name": "",
|
|
|
|
// "lastedit_changed": "",
|
|
|
|
'lastedit_changed': editChanged, // isEmpty(editChanged) ? "" : JSON.stringify(editChanged),
|
|
|
|
"edit_status": infoEditStatus || editingProduct.info.edit_status,
|
|
|
|
'edit_status': infoEditStatus || editingProduct.info.edit_status,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// console.log("ready to post", poster);
|
|
|
|
const copyFields = pick(editingProduct.info, ['product_type_id']); // 'title',
|
|
|
|
const copyFields = pick(editingProduct.info, ['product_type_id']); // 'title',
|
|
|
|
const readyToSubInfo = { ...copyNewProduct.info, ...editingProduct.info, title: editingProduct.info.product_title, ...values.info, ...copyFields, ...poster };
|
|
|
|
const readyToSubInfo = { ...copyNewProduct.info, ...editingProduct.info, title: editingProduct.info.product_title, ...values.info, ...copyFields, ...poster };
|
|
|
|
// console.log('onSave', editingProduct.info, readyToSubInfo);
|
|
|
|
// console.log('onSave', editingProduct.info, readyToSubInfo);
|
|
|
@ -95,8 +106,9 @@ const ProductInfo = ({ ...props }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// console.log('before save', '\n lgcEdits:', lgcEdits, '\n mergedLgc', mergedLgc);
|
|
|
|
// console.log('before save', readyToSubInfo, '\n lgcEdits:', lgcEdits, '\n mergedLgc', mergedLgc);
|
|
|
|
// return false; // debug: 0
|
|
|
|
// return false; // debug: 0
|
|
|
|
|
|
|
|
// throw new Error("Test save");
|
|
|
|
/** 提交保存 */
|
|
|
|
/** 提交保存 */
|
|
|
|
setLoading(true);
|
|
|
|
setLoading(true);
|
|
|
|
const { success, result } = await postProductsSaveAction({
|
|
|
|
const { success, result } = await postProductsSaveAction({
|
|
|
|