Commit 472b32ff authored by guang.wu's avatar guang.wu

fix: 优化服务展示

parent f678c23e
......@@ -22,7 +22,7 @@ import { formItemLayout } from '../config';
import { ServiceContext } from '../context';
import { debounce } from '@/utils/utils';
import UploadCropImage from './UploadCropImage';
import { apiShopIds, apiQueryShopList, getByProductType } from '../service';
import { apiShopIds, apiQueryShopList, apiServiceByCategory } from '../service';
import GroupInfo from '../../GoodsManage/Takeaway/components/GroupInfo';
const CreateSelectOption = optionList =>
......@@ -58,6 +58,8 @@ const FormInformationBasic = forwardRef((props, ref) => {
const [isEditTakeaway, setIsEditTakeaway] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
const [shopIdSource, setShopIdSource] = useState('');
const [serviceList, setServiceList] = useState({}); // 品类下的服务承诺
const [specServiceList, setSpecServiceList] = useState([]); // 服务承诺列表
const onCheck = async () => {
try {
......@@ -82,6 +84,25 @@ const FormInformationBasic = forwardRef((props, ref) => {
}
};
// 获取品类下的服务承诺
const getServiceList = async ids => {
const id = ids[ids.length - 1];
const res = await apiServiceByCategory(id);
if (res?.data?.length > 0) {
const obj = {};
res.data.forEach(item => {
obj[item.productServiceId] = item.required;
});
setServiceList(obj);
}
};
const onCategoryChange = ids => {
props.onCategoryChange(ids);
getServiceList(ids);
};
// 自定义加入菜单
const showModal = () => {
if (shopIdSource || editData?.productRefShopId) {
......@@ -185,6 +206,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
if (editData?.commonImageList?.length) {
onTakeawayImageList(editData?.commonImageList);
}
getServiceList(editData.categoryId);
}, [customer.isEdit, editData]);
useEffect(() => {
setShopList([]);
......@@ -200,6 +222,25 @@ const FormInformationBasic = forwardRef((props, ref) => {
};
form.setFieldsValue(temp);
}, [groupShopData]);
useEffect(() => {
// 品类下的设置的服务承诺不可选 required true默认选中 false默认不选中
if (specListData.length > 0) {
const defaultChecked = new Set(editData?.[specListData[0].specId] || []);
const arr = specListData[0].specValues.map(item => {
if (serviceList[item.value]) {
defaultChecked.add(item.value);
}
return {
...item,
disabled: typeof serviceList[item.value] === 'boolean',
};
});
setSpecServiceList(arr);
form.setFieldsValue({ [specListData[0].specId]: Array.from(defaultChecked) });
}
}, [serviceList, specListData]);
return (
<Form
{...formItemLayout}
......@@ -275,7 +316,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
disabled={customer.isEdit && customer.isNormal}
showSearch={{ filter: filterCategoryOptions }}
fieldNames={{ label: 'name', value: 'id', children: 'children' }}
onChange={props.onCategoryChange}
onChange={onCategoryChange}
options={newCategoryList[customer.productType]}
/>
</Form.Item>
......@@ -351,7 +392,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
!customer.isCard &&
specListData.map((item, index) => (
<Form.Item name={item.specId} key={item.specId} label={item.specName}>
<Checkbox.Group options={item.specValues} />
<Checkbox.Group options={specServiceList} />
</Form.Item>
))}
......
......@@ -176,3 +176,15 @@ export const apiGetShopDetail = data =>
'Content-Type': 'application/x-www-form-urlencoded',
},
});
/**
* 获取类目关联服务
* yApi地址: http://yapi.quantgroups.com/project/389/interface/api/69189
* */
export const apiServiceByCategory = (categoryId, refIdType = 1) =>
request.get(
`/api/merchants/products/service/config/list?refId=${categoryId}&refIdType=${refIdType}`,
{
prefix: goodsApi,
},
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment