编辑页面的各操作权限: 有 `htid` 则不允许修改信息; 提交审核方法

perf/export-docx
Lei OT 11 months ago
parent 8dfb787db5
commit 1cb54dbb75

@ -131,6 +131,7 @@ export const useNewProductRecord = () => {
return {
info: {
'id': '',
'htid': 0,
'title': '',
'code': '',
'product_type_id': '',
@ -138,7 +139,7 @@ export const useNewProductRecord = () => {
'remarks': '',
'duration': 0,
'duration_unit': 'h',
'open_weekdays': '',
'open_weekdays': ['1', '2', '3', '4', '5', '6', '7'],
'recommends_rate': 0,
'dept': '',
'dept_id': 0,

@ -64,6 +64,9 @@ export const getAgencyProductExtrasAction = async (param) => {
return errcode !== 0 ? [] : result;
};
/**
* 审核一条价格
*/
export const postProductsQuoteAuditAction = async (auditState, quoteRow) => {
const postbody = {
audit_state: auditState,
@ -79,22 +82,27 @@ export const postProductsQuoteAuditAction = async (auditState, quoteRow) => {
// return errcode !== 0 ? {} : result;
};
export const postProductsAuditAction = async (auditState, infoRow) => {
/**
* 供应商提交审核
*/
export const postAgencyAuditAction = async (travel_agency_id, use_year) => {
const postbody = {
audit_state: auditState,
id: infoRow.id,
travel_agency_id: infoRow.travel_agency_id,
use_year,
travel_agency_id,
};
const formData = new FormData();
Object.keys(postbody).forEach((key) => {
formData.append(key, postbody[key]);
});
const json = await postForm(`${HT_HOST}/Service_BaseInfoWeb/travel-agency-products-audit`, formData);
return json;
const { errcode, result } = await postForm(`${HT_HOST}/Service_BaseInfoWeb/agency_submit`, formData);
return { errcode, result, success: errcode === 0 };
// const { errcode, result } = json;
// return errcode !== 0 ? {} : result;
};
/**
* 保存一个产品
*/
export const postProductsSaveAction = async (products) => {
const { errcode, result } = await postJSON(`${HT_HOST}/Service_BaseInfoWeb/agency_product_save`, products);
return { errcode, result, success: errcode === 0 };
@ -131,9 +139,9 @@ export const useProductsStore = create(
setEditing: (editing) => set({ editing }),
setSwitchParams: (switchParams) => set({ switchParams }),
newProduct: (productItem) => {
appendNewProduct: (productItem) => {
const { setActiveAgency, agencyProducts, setAgencyProducts } = get();
const typeGroup = agencyProducts[productItem.info.product_type_id];
const typeGroup = agencyProducts[productItem.info.product_type_id] || [];
const newIndex = typeGroup.findIndex((item) => item.info.id === productItem.info.id);
if (newIndex !== -1) {
typeGroup.splice(newIndex, 1, productItem);

@ -8,7 +8,7 @@ import useProductsStore, { postProductsQuoteAuditAction, } from '@/stores/Produc
import { cloneDeep, isEmpty, isNotEmpty } from '@/utils/commons';
import useAuthStore from '@/stores/Auth';
import RequireAuth from '@/components/RequireAuth';
import { 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 Header from './Detail/Header';
import dayjs from 'dayjs';
import { usingStorage } from '@/hooks/usingStorage';
@ -163,6 +163,7 @@ const TypesPanels = (props) => {
};
const Audit = ({ ...props }) => {
const isPermitted = useAuthStore(state => state.isPermitted);
const { travel_agency_id, use_year, audit_state } = useParams();
const [loading, activeAgency, getAgencyProducts] = useProductsStore((state) => [state.loading, state.activeAgency, state.getAgencyProducts]);
const { travelAgencyId } = usingStorage();
@ -176,7 +177,7 @@ const Audit = ({ ...props }) => {
return (
<>
<SecondHeaderWrapper loading={loading} backTo={`/products`} header={<Header title={activeAgency.travel_agency_name} refresh={handleGetAgencyProducts} />}>
<SecondHeaderWrapper loading={loading} backTo={isPermitted(PERM_PRODUCTS_MANAGEMENT) ? `/products` : false} header={<Header title={activeAgency.travel_agency_name} refresh={handleGetAgencyProducts} />} >
{/* <PrintContractPDF /> */}
<TypesPanels refresh={handleGetAgencyProducts} />

@ -1,16 +1,13 @@
import { useState, useEffect } from 'react';
import { message, Divider, Empty, Flex } from 'antd';
import { Divider, Empty, Flex } from 'antd';
import { useNavigate } from 'react-router-dom';
import Extras from './Detail/Extras';
import { isEmpty } from '@/utils/commons';
import SecondHeaderWrapper from '@/components/SecondHeaderWrapper';
import Header from './Detail/Header';
import { useParams } from 'react-router-dom';
import useProductsStore from '@/stores/Products/Index';
import dayjs from 'dayjs';
import { HT_HOST } from '@/config';
import { postForm } from '@/utils/request';
import { PERM_PRODUCTS_OFFER_AUDIT, PERM_PRODUCTS_OFFER_PUT } from '@/config';
import { PERM_PRODUCTS_MANAGEMENT } from '@/config';
import { usingStorage } from '@/hooks/usingStorage';
import ProductsTree from './Detail/ProductsTree';
import ProductInfo from './Detail/ProductInfo';
@ -18,11 +15,9 @@ import useAuthStore from '@/stores/Auth';
import NewProductModal from './Detail/NewProductModal';
function Detail() {
// const { t } = useTranslation();
const navigate = useNavigate();
const { travel_agency_id, audit_state, use_year } = useParams();
const [addProductVisible, setAddProductVisible] = useState(false);
const [editingProduct, ] = useProductsStore((state) => [state.editingProduct]);
const [agencyProducts, loading] = useProductsStore((state) => [state.agencyProducts, state.loading]);
const [getAgencyProducts, activeAgency] = useProductsStore((state) => [state.getAgencyProducts, state.activeAgency]);
const [setSwitchParams] = useProductsStore((state) => [state.setSwitchParams]);
@ -42,165 +37,16 @@ function Detail() {
setSwitchParams(param);
// setEditingProduct({});
getAgencyProducts(param);
// console.log("AgencyProducts",agencyProducts);
// navigate(`/products/${agency}/${year}/${audit_state}/edit`);
};
// 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;
// }
// }
// }
// };
const isPermitted = useAuthStore((state) => state.isPermitted);
const [editable, setEditable] = useState(true);
const topPerm = isPermitted(PERM_PRODUCTS_MANAGEMENT); //
const [newActionable, setNewActionable] = useState(false);
useEffect(() => {
const notAudit = activeAgency.audit_state_id < 0 || activeAgency.audit_state_id === 3;
const hasAuditPer = isPermitted(PERM_PRODUCTS_OFFER_AUDIT);
const hasEditPer = isPermitted(PERM_PRODUCTS_OFFER_PUT);
setEditable(hasAuditPer ? true : notAudit && hasEditPer);
// setEditable(true); // debug: 0
// console.log('editable', hasAuditPer, (notAudit && hasEditPer));
setNewActionable(topPerm || notAudit);
return () => {};
}, [activeAgency, editingProduct]);
//
// const onSave = async (values) => {
// let tempInfo;
// 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;
// let tempQuotation = quotation.map((element) => {
// const updateData = {
// ...element,
// audit_state: '-1',
// };
// delete updateData.tempKey;
// return updateData;
// });
// let tempLgc_details = [{ ...lgc_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('');
// } else {
// message.error(`: ${result}`);
// }
// return;
// }
// tempInfo = {
// ...info,
// ...values.info,
// audit_state: '-1',
// };
// console.log('tempInfo', tempInfo);
// let tempQuotation = quotation.map((element) => {
// const updateData = {
// ...element,
// audit_state: '-1',
// };
// return updateData;
// });
// const tempData = {
// travel_agency_id,
// info: tempInfo,
// quotation: tempQuotation,
// lgc_details: Object.values(lgc_details),
// };
// console.log('tempData', tempData);
// // const { errcode, result } = await postProductsSave(tempData);
// const { errcode, result } = await postJSON(`${HT_HOST}/Service_BaseInfoWeb/agency_product_save`, tempData);
// if (errcode === 0) {
// message.success('');
// } else {
// message.error(`: ${result}`);
// }
// return;
// };
//
const submitReview = async () => {
const formData = new FormData();
formData.append('use_year', use_year);
formData.append('travel_agency_id', travel_agency_id);
try {
const { errcode, result } = await postForm(`${HT_HOST}/Service_BaseInfoWeb/agency_submit`, formData);
console.log('errcode', errcode);
if (errcode === 0) {
message.success('提交审核成功');
navigate(`/products/${travel_agency_id}/${use_year}/${audit_state}/audit`);
} else {
message.error('提交审核失败');
}
console.log('result', result);
} catch (error) {
console.error('提交审核请求失败', error);
message.error('提交审核请求失败');
}
};
}, [activeAgency]);
return (
<SecondHeaderWrapper
@ -211,8 +57,7 @@ function Detail() {
title={activeAgency.travel_agency_name}
refresh={handleGetAgencyProducts}
handleNewProduct={() => setAddProductVisible(true)}
handleSubmitForAudit={submitReview}
editable={editable}
newActionable={newActionable}
/>
}>
{isEmpty(agencyProducts) ? (
@ -224,8 +69,7 @@ function Detail() {
<ProductsTree className='basis-64 sticky top-16 overflow-y-auto shrink-0' style={{ height: 'calc(100vh - 150px)' }} />
<Divider type={'vertical'} className='mx-1 h-auto' />
<div className=' flex-auto grow-0 min-w-[800px]'>
<ProductInfo editable={editable} />
{!isEmpty(editingProduct) && <Extras productId={editingProduct?.info?.id} />}
<ProductInfo />
</div>
</Flex>

@ -3,7 +3,7 @@ import { useParams, Link, useNavigate, useLocation } from 'react-router-dom';
import { App, Button, Divider, Select } from 'antd';
import { useProductsAuditStatesMapVal } from '@/hooks/useProductsSets';
import { useTranslation } from 'react-i18next';
import useProductsStore, { postProductsQuoteAuditAction } from '@/stores/Products/Index';
import useProductsStore, { postProductsQuoteAuditAction, postAgencyAuditAction } from '@/stores/Products/Index';
import { isEmpty } from '@/utils/commons';
import useAuthStore from '@/stores/Auth';
import RequireAuth from '@/components/RequireAuth';
@ -12,15 +12,16 @@ import { PERM_PRODUCTS_OFFER_AUDIT, PERM_PRODUCTS_OFFER_PUT } from '@/config';
import dayjs from 'dayjs';
import VendorSelector from '@/components/VendorSelector';
import AuditStateSelector from '@/components/AuditStateSelector';
const Header = ({ refresh, editable, ...props }) => {
const Header = ({ refresh, newActionable, ...props }) => {
const location = useLocation();
console.log(location);
const showEditA = !location.pathname.includes('edit');
const showAuditA = !location.pathname.includes('audit');
const { travel_agency_id, use_year, audit_state } = useParams();
const { t } = useTranslation();
const isPermitted = useAuthStore((state) => state.isPermitted);
const [activeAgency, setActiveAgency] = useProductsStore((state) => [state.activeAgency, state.setActiveAgency]);
const [switchParams] = useProductsStore((state) => [state.switchParams]);
const stateMapVal = useProductsAuditStatesMapVal();
const { message, notification } = App.useApp();
const navigate = useNavigate();
@ -86,6 +87,33 @@ const Header = ({ refresh, editable, ...props }) => {
});
});
};
const handleSubmitForAudit = () => {
postAgencyAuditAction(activeAgency.travel_agency_id, switchParams.use_year)
.then((json) => {
if (json.errcode === 0) {
message.success(t('Success'));
if (typeof refresh === 'function') {
refresh(param);
const auditPagePath = isPermitted(PERM_PRODUCTS_OFFER_AUDIT)
? `/products/${activeAgency.travel_agency_id}/${switchParams.use_year}/all/audit`
: isPermitted(PERM_PRODUCTS_OFFER_PUT)
? `/products/audit`
: '';
navigate(auditPagePath);
}
}
})
.catch((ex) => {
notification.error({
message: 'Notification',
description: ex.message,
placement: 'top',
duration: 4,
});
});
};
return (
<div className='flex justify-end items-center gap-4 h-full'>
<div className='grow'>
@ -141,7 +169,7 @@ const Header = ({ refresh, editable, ...props }) => {
</RequireAuth>
{/* 编辑 */}
<Divider type='vertical' />
{editable && (
{newActionable && (
<>
<RequireAuth subject={PERM_PRODUCTS_OFFER_PUT}>
<Button size='small' type={'primary'} onClick={props.handleNewProduct}>
@ -150,7 +178,7 @@ const Header = ({ refresh, editable, ...props }) => {
</Button>
</RequireAuth>
<RequireAuth subject={PERM_PRODUCTS_OFFER_PUT}>
<Button size='small' type={'primary'} onClick={props.handleSubmitForAudit}>
<Button size='small' type={'primary'} onClick={handleSubmitForAudit}>
{t('Submit')}
{t('Audit')}
</Button>

@ -1,53 +1,68 @@
import { createContext, useEffect, useState } from 'react';
import { App, Breadcrumb, Form, Divider, Button, Input, Select, Row, Col } from 'antd';
import { useEffect, useState } from 'react';
import { App, Breadcrumb, Divider } from 'antd';
import { useTranslation } from 'react-i18next';
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 DeptSelector from '@/components/DeptSelector';
import CitySelector from '@/components/CitySelector';
import { at, isEmpty, pick } from '@/utils/commons';
import { PERM_PRODUCTS_MANAGEMENT, PERM_PRODUCTS_OFFER_PUT } from '@/config';
import { isEmpty, pick } from '@/utils/commons';
import ProductInfoForm from './ProductInfoForm';
import dayjs from 'dayjs';
import { usingStorage } from '@/hooks/usingStorage'
import { usingStorage } from '@/hooks/usingStorage';
import Extras from './Extras';
const ProductInfo = ({ editable, ...props }) => {
const ProductInfo = ({ ...props }) => {
const { t } = useTranslation();
const { notification, message } = App.useApp();
const { userId } = usingStorage()
const { userId } = usingStorage();
const isPermitted = useAuthStore((state) => state.isPermitted);
const productsTypesMapVal = useProductsTypesMapVal();
const newProductRecord = useNewProductRecord();
const [loading, setLoading, newProduct] = useProductsStore((state) => [state.loading, state.setLoading, state.newProduct]);
const [activeAgency, agencyProducts, editingProduct, setEditingProduct] = useProductsStore((state) => [state.activeAgency, state.agencyProducts, state.editingProduct, state.setEditingProduct]);
const [loading, setLoading, appendNewProduct] = useProductsStore((state) => [state.loading, state.setLoading, state.appendNewProduct]);
const [activeAgency, editingProduct, setEditingProduct] = useProductsStore((state) => [state.activeAgency, state.editingProduct, state.setEditingProduct]);
const [extrasVisible, setExtrasVisible] = useState(false);
const [editable, setEditable] = useState(false);
const topPerm = isPermitted(PERM_PRODUCTS_MANAGEMENT); //
useEffect(() => {
const hasHT = (editingProduct?.info?.htid || 0) > 0;
// const hasAuditPer = isPermitted(PERM_PRODUCTS_OFFER_AUDIT);
const hasEditPer = isPermitted(PERM_PRODUCTS_OFFER_PUT);
setEditable(topPerm || (!hasHT && hasEditPer));
// setEditable(topPerm || (hasAuditPer ? true : (!hasHT && hasEditPer)));
// setEditable(true); // debug: 0
// console.log('editable', hasAuditPer, (notAudit && hasEditPer));
const showExtras = topPerm && !isEmpty(editingProduct) && hasHT;
setExtrasVisible(showExtras);
return () => {};
}, [activeAgency, editingProduct]);
const onSave = async (err, values, forms) => {
values.travel_agency_id = activeAgency.travel_agency_id;
const copyNewProduct = structuredClone(newProductRecord);
const poster = {
"audit_state": "-1",
'audit_state': '-1',
// "create_date": dayjs().format('YYYY-MM-DD HH:mm:ss'),
// "created_by": userId,
"travel_agency_id": activeAgency.travel_agency_id,
'travel_agency_id': activeAgency.travel_agency_id,
// "travel_agency_name": "",
// "lastedit_changed": "",
};
/** lgc_details */
const copyFields = pick(editingProduct.info, ['title', 'product_type_id', ]);
const readyToSubInfo = {...copyNewProduct.info, ...values.info, ...copyFields, type: copyFields.product_type_id, ...poster };
const copyFields = pick(editingProduct.info, ['title', 'product_type_id']);
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 prevLgcDetailsMapped = editingProduct.lgc_details.reduce((r, c) => ({ ...r, [c.lgc]: { ...c, description: c.descriptions } }), {}); // todo: description
const mergedLgc = { ...prevLgcDetailsMapped, ...values.lgc_details_mapped };
/** quotation */
// todo:
const prevQuotationMapped = editingProduct.quotation.reduce((r, c) => ({...r, [c.id]: {...c, unit: c.unit_id, audit_state: c.audit_state_id }}), {});
const prevQuotationMapped = editingProduct.quotation.reduce((r, c) => ({ ...r, [c.id]: { ...c, unit: c.unit_id, audit_state: c.audit_state_id } }), {});
const mergedQ = { ...prevQuotationMapped, ...(values.quotation || []) };
// console.log(values);
// return false;
console.log(values);
// return false; // debug: 0
/** 提交保存 */
setLoading(true);
const { success, result } = await postProductsSaveAction({
travel_agency_id: activeAgency.travel_agency_id,
@ -58,7 +73,7 @@ const ProductInfo = ({ editable, ...props }) => {
setLoading(false);
success ? message.success(t('Success')) : message.error(t('Failed'));
//
newProduct(result);
appendNewProduct(result);
setEditingProduct(result);
};
return (
@ -66,13 +81,14 @@ const ProductInfo = ({ editable, ...props }) => {
<Breadcrumb
items={[
{ title: productsTypesMapVal[editingProduct?.info?.product_type_id]?.label || editingProduct?.info?.product_type_name },
{ title: editingProduct?.info?.title || t('New') },
{ title: editingProduct?.info?.title ?? t('New') },
]}
/>
<Divider className='my-1' />
<h2>{t('products:EditComponents.info')}</h2>
<ProductInfoForm editable={editable} showSubmit initialValues={editingProduct?.info} onSubmit={onSave} />
<ProductInfoForm editable={editable} initialValues={editingProduct?.info} onSubmit={onSave} />
<Divider className='my-1' />
{extrasVisible && <Extras productId={editingProduct?.info?.id} />}
</>
);
};

@ -9,15 +9,11 @@ import { useProductsTypesFieldsets } from '@/hooks/useProductsSets';
import useProductsStore from '@/stores/Products/Index';
import ProductInfoLgc from './ProductInfoLgc';
import ProductInfoQuotation from './ProductInfoQuotation';
import useAuthStore from '@/stores/Auth';
import { PERM_PRODUCTS_OFFER_AUDIT } from '@/config';
import { useHTLanguageSetsMapVal } from '@/hooks/useHTLanguageSets';
const InfoForm = ({ onSubmit, onReset, onValuesChange, editable: _editable, showSubmit, confirmText, formName, ...props }) => {
const { t } = useTranslation('products');
const HTLanguageSetsMapVal = useHTLanguageSetsMapVal();
const isPermitted = useAuthStore((state) => state.isPermitted);
const [loading, editingProduct] = useProductsStore((state) => [state.loading, state.editingProduct]);
const weekdays = useWeekdays();
const [form] = Form.useForm();
@ -32,20 +28,15 @@ const InfoForm = ({ onSubmit, onReset, onValuesChange, editable: _editable, show
const filedsets = useProductsTypesFieldsets(editingProduct?.info?.product_type_id);
const shows = filedsets[0];
const topPerm = isPermitted(PERM_PRODUCTS_OFFER_AUDIT); //
const [ignoreEditable, setIgnoreEditable] = useState(false);
const [editable, setEditable] = useState(true);
useEffect(() => {
form.resetFields();
form.setFieldValue('city', { value: editingProduct?.info?.city_id, label: editingProduct?.info?.city_name });
form.setFieldValue('dept', { value: editingProduct?.info?.dept_id, label: editingProduct?.info?.dept_name });
form.setFieldValue('lgc_details', editingProduct?.lgc_details || []);
const lgc_details_mapped = (editingProduct?.lgc_details || []).reduce((r, c) => ({ ...r, [c.lgc]: c }), {});
form.setFieldValue('lgc_details_mapped', lgc_details_mapped);
const isNew = isEmpty(editingProduct?.info?.id) || _editable; // ; =
const ignoreEditable0 = topPerm || isNew; //
const editable0 = isEmpty(editingProduct) ? false : _editable; //
setIgnoreEditable(ignoreEditable0);
// console.log('+++++++++++++++++++', '\ntopPerm', topPerm, '\nisNew', isNew, '\nignoreEditable0', ignoreEditable0, '\neditable0', editable0, '\n_editable', _editable);
setEditable(editable0);
return () => {};
}, [editingProduct?.info?.id, _editable]);
@ -85,7 +76,7 @@ const InfoForm = ({ onSubmit, onReset, onValuesChange, editable: _editable, show
<>
<Form
form={form}
disabled={!(editable || false)}
disabled={!editable}
name={formName || 'product_info'}
// preserve={false}
onFinish={onFinish}
@ -94,7 +85,7 @@ const InfoForm = ({ onSubmit, onReset, onValuesChange, editable: _editable, show
initialValues={editingProduct?.info}
onFinishFailed={onFinishFailed}>
<Row>
{getFields({ sort, initialValue: editingProduct?.info, hides, shows, fieldProps, fieldComProps, form, t, dataSets: { weekdays }, editable, ignoreEditable })}
{getFields({ sort, initialValue: editingProduct?.info, hides, shows, fieldProps, fieldComProps, form, t, dataSets: { weekdays }, editable })}
{/* {showSubmit && (
<Col flex='1 0 90px' className='flex justify-end items-start'>
<Space align='center'>
@ -106,11 +97,12 @@ const InfoForm = ({ onSubmit, onReset, onValuesChange, editable: _editable, show
)} */}
</Row>
{/* <Divider className='my-1' /> */}
<Form.Item name={'lgc_details_mapped'}
<Form.Item
name={'lgc_details_mapped'}
rules={[
() => ({
transform(value) {
return Object.values(value).filter(_v => !isEmpty(_v));
return Object.values(value).filter((_v) => !isEmpty(_v));
},
validator: async (_, valueArr) => {
const invalidLgcName = valueArr
@ -124,7 +116,7 @@ const InfoForm = ({ onSubmit, onReset, onValuesChange, editable: _editable, show
},
}),
]}>
<ProductInfoLgc editable={editable} ignoreEditable={ignoreEditable} formInstance={form} />
<ProductInfoLgc editable={editable} formInstance={form} />
</Form.Item>
<Form.Item hidden name={'id'} label={'ID'}>
@ -282,8 +274,7 @@ function getFields(props) {
item(
'open_weekdays',
99,
<Form.Item name='open_weekdays' label={t('OpenWeekdays')} initialValue={['1', '2', '3', '4', '5', '6', '7']} {...fieldProps.open_weekdays}>
{/* 默认全部 */}
<Form.Item name='open_weekdays' label={t('OpenWeekdays')} {...fieldProps.open_weekdays}>
<Checkbox.Group options={dataSets.weekdays} {...styleProps} {...editableProps('open_weekdays')} />
</Form.Item>,
fieldProps?.open_weekdays?.col || 24
@ -370,10 +361,24 @@ const formValuesMapper = (values) => {
// },
// ],
'lgc_details_mapped': [
{ key: 'lgc_details', transform: (value) => {
const valueArr = Object.values(value).filter(_v => !isEmpty(_v));
{
key: 'lgc_details',
transform: (value) => {
const valueArr = Object.values(value)
.filter((_v) => !isEmpty(_v))
.map((e) => ({ title: '', ...e, description: e.description || '' }));
return valueArr;
}},
},
},
{
key: 'lgc_details_mapped',
transform: (value) => {
const valueArr = Object.values(value)
.filter((_v) => !isEmpty(_v))
.map((e) => ({ title: '', ...e, description: e.description || '' }));
return valueArr.reduce((r, c) => ({ ...r, [c.lgc]: c }), {});
},
},
],
};
let dest = {};
@ -387,7 +392,7 @@ const formValuesMapper = (values) => {
// omit empty
// Object.keys(dest).forEach((key) => (dest[key] == null || dest[key] === '' || dest[key].length === 0) && delete dest[key]);
const { lgc_details, lgc_details_mapped, ...info } = dest; // quotation
return { info, lgc_details, lgc_details_mapped, }; // quotation
return { info, lgc_details, lgc_details_mapped }; // quotation
};
export default InfoForm;

@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
import { useDefaultLgc } from '@/i18n/LanguageSwitcher';
import { cloneDeep, isEmpty, isNotEmpty } from '@/utils/commons';
const ProductInfoLgc = ({ editable, ignoreEditable, formInstance, ...props }) => {
const ProductInfoLgc = ({ editable, formInstance, ...props }) => {
const { t } = useTranslation();
const { language: languageHT } = useDefaultLgc();
const HTLanguageSetsMapVal = useHTLanguageSetsMapVal();
@ -30,10 +30,9 @@ const ProductInfoLgc = ({ editable, ignoreEditable, formInstance, ...props }) =>
className={' !text-slate-600'}
allowClear
// onChange={(e) => handleChange('title', e.target.value)}
// disabled={isCanEditable}
// disabled={ignoreEditable ? false : (!isEmpty(ele.title) || !editable)}
disabled={ignoreEditable ? false : !editable}
// disabled={!editable}
// disabled={ignoreEditable ? false : !editable}
disabled={!editable}
/>
</Form.Item>
<Form.Item name={['lgc_details_mapped', `${ele.lgc}`, 'description']} label={t('products:Description')} initialValue={ele.descriptions}>
@ -43,8 +42,8 @@ const ProductInfoLgc = ({ editable, ignoreEditable, formInstance, ...props }) =>
allowClear
// onChange={(e) => handleChange('description', e.target.value)}
// disabled={ignoreEditable ? false : (!isEmpty(ele.descriptions) || !editable)}
disabled={ignoreEditable ? false : !editable}
// disabled={!editable}
// disabled={ignoreEditable ? false : !editable}
disabled={!editable}
/>
</Form.Item>
<Form.Item hidden name={['lgc_details_mapped', `${ele.lgc}`, 'lgc']} initialValue={ele.lgc}>

Loading…
Cancel
Save