|
|
@ -22,18 +22,25 @@ const ProductInfo = ({ ...props }) => {
|
|
|
|
const [activeAgency, editingProduct, setEditingProduct] = useProductsStore((state) => [state.activeAgency, state.editingProduct, state.setEditingProduct]);
|
|
|
|
const [activeAgency, editingProduct, setEditingProduct] = useProductsStore((state) => [state.activeAgency, state.editingProduct, state.setEditingProduct]);
|
|
|
|
|
|
|
|
|
|
|
|
const [extrasVisible, setExtrasVisible] = useState(false);
|
|
|
|
const [extrasVisible, setExtrasVisible] = useState(false);
|
|
|
|
const [editable, setEditable] = useState(false);
|
|
|
|
const [editablePerm, setEditablePerm] = useState(false);
|
|
|
|
|
|
|
|
const [infoEditable, setInfoEditable] = useState(false);
|
|
|
|
|
|
|
|
const [priceEditable, setPriceEditable] = useState(false);
|
|
|
|
const topPerm = isPermitted(PERM_PRODUCTS_MANAGEMENT); // 高级权限
|
|
|
|
const topPerm = isPermitted(PERM_PRODUCTS_MANAGEMENT); // 高级权限
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
const hasHT = (editingProduct?.info?.htid || 0) > 0;
|
|
|
|
const hasHT = (editingProduct?.info?.htid || 0) > 0;
|
|
|
|
// const hasAuditPer = isPermitted(PERM_PRODUCTS_OFFER_AUDIT);
|
|
|
|
// const hasAuditPer = isPermitted(PERM_PRODUCTS_OFFER_AUDIT);
|
|
|
|
const hasEditPer = isPermitted(PERM_PRODUCTS_OFFER_PUT);
|
|
|
|
const hasEditPer = isPermitted(PERM_PRODUCTS_OFFER_PUT);
|
|
|
|
setEditable(topPerm || (!hasHT && hasEditPer));
|
|
|
|
|
|
|
|
|
|
|
|
setEditablePerm(topPerm || hasEditPer);
|
|
|
|
// setEditable(topPerm || (hasAuditPer ? true : (!hasHT && hasEditPer)));
|
|
|
|
// setEditable(topPerm || (hasAuditPer ? true : (!hasHT && hasEditPer)));
|
|
|
|
// setEditable(true); // debug: 0
|
|
|
|
// setEditable(true); // debug: 0
|
|
|
|
// console.log('editable', hasAuditPer, (notAudit && hasEditPer));
|
|
|
|
// console.log('editable', hasAuditPer, (notAudit && hasEditPer));
|
|
|
|
|
|
|
|
setInfoEditable(topPerm || (!hasHT && hasEditPer));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const _priceEditable = [-1, 3].includes(activeAgency?.audit_state_id);
|
|
|
|
|
|
|
|
setPriceEditable(topPerm || (_priceEditable && hasEditPer));
|
|
|
|
|
|
|
|
|
|
|
|
const showExtras = topPerm && !isEmpty(editingProduct) && hasHT;
|
|
|
|
const showExtras = topPerm && hasHT; // !isEmpty(editingProduct) &&
|
|
|
|
setExtrasVisible(showExtras);
|
|
|
|
setExtrasVisible(showExtras);
|
|
|
|
return () => {};
|
|
|
|
return () => {};
|
|
|
|
}, [activeAgency, editingProduct]);
|
|
|
|
}, [activeAgency, editingProduct]);
|
|
|
@ -42,18 +49,19 @@ const ProductInfo = ({ ...props }) => {
|
|
|
|
values.travel_agency_id = activeAgency.travel_agency_id;
|
|
|
|
values.travel_agency_id = activeAgency.travel_agency_id;
|
|
|
|
const copyNewProduct = structuredClone(newProductRecord);
|
|
|
|
const copyNewProduct = structuredClone(newProductRecord);
|
|
|
|
const poster = {
|
|
|
|
const poster = {
|
|
|
|
...(topPerm ? {} : {'audit_state': '-1',}), // 高级权限: 不变更状态值
|
|
|
|
...(topPerm ? {} : { 'audit_state': -1 }), // 高级权限: 不变更状态值
|
|
|
|
// "create_date": dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
// "create_date": dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
// "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": "",
|
|
|
|
};
|
|
|
|
};
|
|
|
|
/** lgc_details */
|
|
|
|
|
|
|
|
const copyFields = pick(editingProduct.info, ['product_type_id']); // 'title',
|
|
|
|
const copyFields = pick(editingProduct.info, ['product_type_id']); // 'title',
|
|
|
|
const readyToSubInfo = { ...copyNewProduct.info, ...editingProduct.info, ...values.info, ...copyFields, type: copyFields.product_type_id, ...poster };
|
|
|
|
const readyToSubInfo = { ...copyNewProduct.info, ...editingProduct.info, ...values.info, ...copyFields, type: copyFields.product_type_id, ...poster };
|
|
|
|
|
|
|
|
readyToSubInfo.dept = Number(readyToSubInfo.dept);
|
|
|
|
// console.log('onSave', editingProduct.info, readyToSubInfo);
|
|
|
|
// console.log('onSave', editingProduct.info, readyToSubInfo);
|
|
|
|
const prevLgcDetailsMapped = editingProduct.lgc_details.reduce((r, c) => ({ ...r, [c.lgc]: { ...c, description: c.descriptions } }), {}); // todo: description字段不一致
|
|
|
|
/** lgc_details */
|
|
|
|
|
|
|
|
const prevLgcDetailsMapped = editingProduct.lgc_details.reduce((r, c) => ({ ...r, [c.lgc]: { ...c, description: c.descriptions } }), {});
|
|
|
|
const mergedLgc = { ...prevLgcDetailsMapped, ...values.lgc_details_mapped };
|
|
|
|
const mergedLgc = { ...prevLgcDetailsMapped, ...values.lgc_details_mapped };
|
|
|
|
|
|
|
|
|
|
|
|
// console.log(values);
|
|
|
|
// console.log(values);
|
|
|
@ -64,15 +72,15 @@ const ProductInfo = ({ ...props }) => {
|
|
|
|
travel_agency_id: activeAgency.travel_agency_id,
|
|
|
|
travel_agency_id: activeAgency.travel_agency_id,
|
|
|
|
info: readyToSubInfo,
|
|
|
|
info: readyToSubInfo,
|
|
|
|
lgc_details: Object.values(mergedLgc),
|
|
|
|
lgc_details: Object.values(mergedLgc),
|
|
|
|
quotation: values.quotation, // || editingProduct.quotation, // 没改动, 就用原来的
|
|
|
|
quotation: values.quotation.map((q) => ({ ...q, unit: Number(q.unit || q.unit_id), unit_id: Number(q.unit_id) })), // || editingProduct.quotation, // 没改动, 就用原来的
|
|
|
|
}).catch(ex => {
|
|
|
|
}).catch((ex) => {
|
|
|
|
setLoading(false);
|
|
|
|
setLoading(false);
|
|
|
|
notification.error({
|
|
|
|
notification.error({
|
|
|
|
message: 'Notification',
|
|
|
|
message: 'Notification',
|
|
|
|
description: ex.message,
|
|
|
|
description: ex.message,
|
|
|
|
placement: 'top',
|
|
|
|
placement: 'top',
|
|
|
|
duration: 4,
|
|
|
|
duration: 4,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
setLoading(false);
|
|
|
|
setLoading(false);
|
|
|
|
success ? message.success(t('Success')) : message.error(t('Failed'));
|
|
|
|
success ? message.success(t('Success')) : message.error(t('Failed'));
|
|
|
@ -90,11 +98,15 @@ const ProductInfo = ({ ...props }) => {
|
|
|
|
]}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<Divider className='my-1' />
|
|
|
|
<Divider className='my-1' />
|
|
|
|
|
|
|
|
{isEmpty(editingProduct) ? null : (
|
|
|
|
|
|
|
|
<>
|
|
|
|
<h2>{t('products:EditComponents.info')}</h2>
|
|
|
|
<h2>{t('products:EditComponents.info')}</h2>
|
|
|
|
<ProductInfoForm editable={editable} initialValues={editingProduct?.info} onSubmit={onSave} />
|
|
|
|
<ProductInfoForm {...{ editablePerm, infoEditable, priceEditable }} initialValues={editingProduct?.info} onSubmit={onSave} />
|
|
|
|
<Divider className='my-1' />
|
|
|
|
<Divider className='my-1' />
|
|
|
|
{extrasVisible && <Extras productId={editingProduct?.info?.id} />}
|
|
|
|
{extrasVisible && <Extras productId={editingProduct?.info?.id} />}
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export default ProductInfo;
|
|
|
|
export default ProductInfo;
|
|
|
|