Commit e64c6bba authored by 陈万宝's avatar 陈万宝

Merge branch 'feature/20230315_take_out_goods' into feature/20230327_public_takeaway

parents 6fec3ca3 5470e60a
......@@ -78,7 +78,7 @@ class goodsManage extends Component {
componentDidMount() {
this.props.goodsManage.tableData = {};
this.categoryList();
this.categoryList(this.state.productType);
this.categoryListByType(this.state.productType);
this.getVirtualCategory();
this.specList();
......
......@@ -245,6 +245,15 @@
.specsBetween {
display: flex;
flex-flow: row nowrap;
:global {
.ant-form-item-label{
overflow:inherit;
}
.ant-col-sm-3{
max-width: fit-content;
}
}
}
.specRepertory {
background-color: #319bfe;
......
......@@ -12,7 +12,7 @@ import { ServiceContext } from '../context';
import { debounce } from '@/utils/utils';
import AddMenusModal from './AddMenusModal';
import UploadImage from './UploadImage';
import { apiShopIds, apiQueryShopList } from '../service';
import { apiShopIds, apiQueryShopList, getByProductType } from '../service';
const CreateSelectOption = optionList =>
optionList.map(brandItem => (
......@@ -22,7 +22,6 @@ const CreateSelectOption = optionList =>
));
const fileterBrandOptions = (input, options) => options.children.includes(input);
const filterCategoryOptions = (inputValue, path) =>
path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
......@@ -35,6 +34,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
brandList,
afterAddressList,
specListData,
shopGetByProductType,
} = props;
const [form] = Form.useForm();
const [noreBrandList, setNoreBrandList] = useState([]);
......@@ -43,6 +43,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
const [takeawayImageList, setTakeawayImageList] = useState([]);
const [shopIds, setShopIds] = useState([]);
const [shopList, setShopList] = useState([]);
const [isEditTakeaway, setIsEditTakeaway] = useState(false);
const onCheck = async () => {
try {
......@@ -66,6 +67,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
return null;
}
};
// 自定义加入菜单
const showModal = () => {
childAddMenusModalRef.current.setOpen(true);
......@@ -100,6 +102,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
console.log('infoMation', values);
props.onValuesChange({ infoMation: values });
}, 400);
// 查询shopIds
......@@ -118,13 +121,17 @@ const FormInformationBasic = forwardRef((props, ref) => {
};
const onChangeShopId = async e => {
if (e) {
queryShopList({ shopId: e }); // 分组列表
setShopList([]);
queryShopList({ shopId: e });
}
};
useImperativeHandle(ref, () => ({
onCheck,
reset: form.resetFields,
}));
useEffect(() => {
queryShopIds();
}, [customer.productType]);
useEffect(() => {
const noreList = (brandList || []).filter(item => item.name === '虚拟商品');
......@@ -133,15 +140,15 @@ const FormInformationBasic = forwardRef((props, ref) => {
useEffect(() => {
if (!editData) return;
if (editData.productType === 5 && editData.name) {
shopGetByProductType(5);
queryShopList({ shopId: editData.productRefShopId });
setIsEditTakeaway(true);
}
form.setFieldsValue(editData);
onTakeawayImageList(editData.commonImageList);
}, [customer.isEdit, editData]);
useEffect(() => {
console.log('!customer.isTakeawayService', customer);
console.log('newCategoryList[customer.productType]', newCategoryList[customer.productType]);
console.log('newCategoryList[customer.productType]', shopList);
queryShopIds()
}, [customer.productType]);
return (
<Form
{...formItemLayout}
......@@ -152,6 +159,8 @@ const FormInformationBasic = forwardRef((props, ref) => {
name: '',
categoryId: [],
description: '',
productRefShopId: [],
storageRackIds: [],
}}
scrollToFirstError
onValuesChange={getFormValues}
......@@ -171,12 +180,12 @@ const FormInformationBasic = forwardRef((props, ref) => {
{customer.isTakeawayService && (
<Form.Item
name="productRefShopId"
key="productRefShopId"
label="所属门店"
rules={[{ required: true, message: '请选择所属门店' }]}
>
<Select
fieldNames={{ label: 'name', value: 'id' }}
filterOption={fileterBrandOptions}
placeholder="请选择所属门店"
options={shopIds}
onChange={onChangeShopId}
......@@ -195,7 +204,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={props.onCategoryChange}
options={shopList}
dropdownRender={dropdownRender}
/>
......@@ -205,7 +214,6 @@ const FormInformationBasic = forwardRef((props, ref) => {
<AddMenusModal ref={childAddMenusModalRef} queryShopList={queryShopList} />
<Form.Item
name="categoryId"
key="categoryId"
label="商品类目"
rules={[{ type: 'array', required: true, message: '请输入商品类目' }]}
>
......
......@@ -22,7 +22,7 @@ import {
getByProductType,
apiCreateDraft,
apiEditDraft,
apiAddTakeawayProducts,
apiGetShopDetail,
} from './service';
import { isUrl, filterSendData, clearCurrent, onAutoSaveValue, localAutoSaveKey } from './utils';
import { ServiceContext } from './context';
......@@ -35,12 +35,18 @@ import styles from './common.less';
* @returns ReactDOM
*/
const ServiceGoods = options => {
const { SourceData, categoryList, virtualCategoryList, specListData, permissions } = options;
const {
SourceData,
categoryList,
virtualCategoryList,
specListData,
permissions,
takeAway,
} = options;
const canAddService = permissions[GOOD_MANAGE.ADD_SERVICE_GOODS];
const canAddNormal = permissions[GOOD_MANAGE.ADD_NORMAL_GOODS];
// const canTakeawayService = permissions[GOOD_MANAGE.ADD_TAKEAWAY_GOODS];
// const canTakeawayService = true
const basicRef = useRef(null);
const stockRef = useRef(null);
const settingRef = useRef(null);
......@@ -62,6 +68,7 @@ const ServiceGoods = options => {
const [specList, setSpecList] = useState([]); // 规格列表
const [editData, setEditData] = useState({}); // 编辑保存数据
const [newCategoryList, setNewCategoryList] = useState({});
const [takeawayEditData, setTakeawayEditData] = useState({}); // 外卖编辑保存数据
const [visibleCacheEdit, setVisibleCacheEdit] = useState(false); // 显示有缓存未保存提示
const [checkFormList] = useState([
......@@ -111,10 +118,44 @@ const ServiceGoods = options => {
},
!0,
);
stockRef.current.onFinish();
if (stockRef.current) {
stockRef.current.onFinish();
}
}, 1000);
};
// 查询外卖商品详情
const querGetShopDetail = async params => {
const { spuId, shopId } = params;
const temp = {
id: spuId,
shopId,
};
const { data } = await apiGetShopDetail(temp);
const {
name,
storageRackIds,
firstCategoryId,
secondCategoryId,
thirdCategoryId,
commonImageList,
id,
} = data;
const categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
const editInfoMation = {
infoMation: {
name,
productRefShopId: `${shopId}`,
commonImageList,
categoryId,
storageRackIds,
productType: 5,
},
};
setEditData(editInfoMation);
setTakeawayEditData(data);
setIsEdit(true);
setPageLoading(false);
};
const onResetData = refresh => {
setPageId(null);
setIsEdit(false);
......@@ -195,7 +236,6 @@ const ServiceGoods = options => {
});
}
};
// 保存商品
const submitEvent = async () => {
const checkPromiseList = clearCurrent(checkFormList).map(({ current }) => current.onCheck());
......@@ -208,14 +248,11 @@ const ServiceGoods = options => {
origin[temp] = other;
return origin;
}, {});
// 外卖商品创建
if (+productType === 5) {
console.log('parmas', params);
const res = await sendMerchantProductHttpRequest(params?.takeawayItem?.intactData);
const sendData = filterSendData(productType, params);
if (productType === 5) {
sendMerchantProductHttpRequest(sendData);
return false;
}
const sendData = filterSendData(productType, params);
if (isEdit) {
sendData.id = pageId;
}
......@@ -333,6 +370,13 @@ const ServiceGoods = options => {
},
[specKeyList],
);
useEffect(() => {
// 外卖类型
if (takeAway && takeAway.spuId) {
setProductType(5);
querGetShopDetail(takeAway);
}
}, []);
const onEventBus = (event, params) => {
if (event === 'cloneImg') {
......@@ -411,7 +455,6 @@ const ServiceGoods = options => {
},
});
};
console.log('productType', productType);
const providerValue = {
pageId,
isEdit,
......@@ -470,6 +513,7 @@ const ServiceGoods = options => {
ref={basicRef}
editData={editData.infoMation}
newCategoryList={newCategoryList}
shopGetByProductType={shopGetByProductType}
categoryList={categoryList}
virtualCategoryList={virtualCategoryList}
brandList={brandList}
......@@ -538,7 +582,8 @@ const ServiceGoods = options => {
<>
<FormTakeaway
ref={takeawayRef}
editData={editData.takeawayItem}
takeAway={takeAway}
editData={takeawayEditData}
infoMation={editData.infoMation}
supplierIdList={supplierIdList}
onValuesChange={onValuesChange}
......
......@@ -109,7 +109,15 @@ const filterItems = (type, props) => {
};
export const filterSendData = (type, params) => {
const { infoMation, infoImageData, attributeApplyList } = params;
// takeawayItem 外卖商品
const { infoMation, infoImageData, attributeApplyList, takeawayItem } = params;
console.log('infoMation', infoMation, takeawayItem);
const temp = Object.assign({}, takeawayItem?.intactData, infoMation)
temp.categoryId = (Array.isArray(temp.categoryId) && temp.categoryId?.slice(temp.categoryId?.length - 1)?.toString())
// 外卖商品
if (type === 5) {
return temp;
}
const items = filterItems(type, params);
const commonImageList = type === 4 ? [] : infoImageData.commonImageList;
const obj = {
......@@ -128,6 +136,7 @@ export const filterSendData = (type, params) => {
if (attributeApplyList && attributeApplyList.attributeApplyList) {
obj.attributeApplyList = attributeApplyList.attributeApplyList;
}
return obj;
};
......
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