Commit 00a538e2 authored by 陈万宝's avatar 陈万宝

feat: 更新创建商品接口

parent 6095ba76
...@@ -12,7 +12,7 @@ const AddRepertoryModal = (props, ref) => { ...@@ -12,7 +12,7 @@ const AddRepertoryModal = (props, ref) => {
const [initialValues, setInitialValues] = useState({ const [initialValues, setInitialValues] = useState({
productStock: 0, productStock: 0,
maxStock: 0, maxStock: 0,
autoStock: 0, autoStock: false,
}); });
const { modifiedInventory, intactData, repertoryModel } = props; const { modifiedInventory, intactData, repertoryModel } = props;
...@@ -24,6 +24,7 @@ const AddRepertoryModal = (props, ref) => { ...@@ -24,6 +24,7 @@ const AddRepertoryModal = (props, ref) => {
})); }));
// 自动补全 // 自动补全
const onChangeAutoStock = e => { const onChangeAutoStock = e => {
console.log('onChangeAutoStock');
form.setFieldsValue({ form.setFieldsValue({
autoStock: e ? 1 : 0, autoStock: e ? 1 : 0,
}); });
...@@ -59,6 +60,7 @@ const AddRepertoryModal = (props, ref) => { ...@@ -59,6 +60,7 @@ const AddRepertoryModal = (props, ref) => {
const handleOk = async () => { const handleOk = async () => {
const values = await form.validateFields(); const values = await form.validateFields();
console.log('values', values); console.log('values', values);
values.autoStock = values.autoStock ? 1 : 0;
// 回调库存 // 回调库存
modifiedInventory(values); modifiedInventory(values);
// setConfirmLoading(true); // setConfirmLoading(true);
...@@ -72,17 +74,23 @@ const AddRepertoryModal = (props, ref) => { ...@@ -72,17 +74,23 @@ const AddRepertoryModal = (props, ref) => {
setOpenRepertory(false); setOpenRepertory(false);
}; };
useEffect(() => { useEffect(() => {
console.log('open', openRepertory); console.log('open', openRepertory, intactData?.items, repertoryModel);
const { productStock, serviceItem } = intactData?.items; if (intactData?.items?.length) {
const { productStock, serviceItem } = intactData?.items[0];
const { autoStock, maxStock } = serviceItem; const { autoStock, maxStock } = serviceItem;
const params = { const params = {
productStock, productStock,
autoStock, autoStock: +autoStock === 1,
maxStock, maxStock,
}; };
console.log('params=====', params);
switch (repertoryModel) { switch (repertoryModel) {
case 'all': // 统一设置 case 'all': // 统一设置
setInitialValues(params); console.log('params', params);
form.setFieldsValue(params);
form.setFieldsValue({ autoStock: true });
break; break;
case 'mlti': // 多规格设置 case 'mlti': // 多规格设置
setInitialValues(params); setInitialValues(params);
...@@ -93,6 +101,7 @@ const AddRepertoryModal = (props, ref) => { ...@@ -93,6 +101,7 @@ const AddRepertoryModal = (props, ref) => {
default: default:
break; break;
} }
}
}, [openRepertory, intactData]); }, [openRepertory, intactData]);
return ( return (
<> <>
...@@ -140,7 +149,7 @@ const AddRepertoryModal = (props, ref) => { ...@@ -140,7 +149,7 @@ const AddRepertoryModal = (props, ref) => {
onChange={onChangeMaxStock} onChange={onChangeMaxStock}
/> />
</Form.Item> </Form.Item>
<Form.Item name="autoStock" label="自动补足"> <Form.Item name="autoStock" label="自动补足" valuePropName="checked">
<Switch <Switch
checkedChildren="开启" checkedChildren="开启"
unCheckedChildren="关闭" unCheckedChildren="关闭"
...@@ -148,8 +157,8 @@ const AddRepertoryModal = (props, ref) => { ...@@ -148,8 +157,8 @@ const AddRepertoryModal = (props, ref) => {
onChange={onChangeAutoStock} onChange={onChangeAutoStock}
/> />
</Form.Item> </Form.Item>
<div className={styles.textStyle}>修改成功后,原库存将被替换,请谨慎操作!</div>
</Form> </Form>
<div className={styles.textStyle}>修改成功后,原库存将被替换,请谨慎操作!</div>
</Modal> </Modal>
)} )}
</> </>
......
...@@ -125,8 +125,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -125,8 +125,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
let singularSpu = []; // 多库存spu let singularSpu = []; // 多库存spu
const temp = { const temp = {
salePrice: 1, salePrice: 0,
productStock: 2, productStock: 0,
list: 1, list: 1,
serviceItem: { serviceItem: {
description, // 商品描述 description, // 商品描述
...@@ -138,15 +138,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -138,15 +138,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
label, // 商品标签id label, // 商品标签id
saleDates, // 可售日期 1-8 saleDates, // 可售日期 1-8
saleTimes, saleTimes,
autoStock: '', // 弹框设置---自动补足 autoStock: 0, // 弹框设置---自动补足
}, },
}; };
// 单规格 // 单规格
if (+repertoryType === 1) { if (+repertoryType === 1) {
const sepcs = { maxStock, quantity, unit, productStock }; const specs = { maxStock, quantity, unit: unit.splice(unit.length - 1)[0], productStock };
singularSpecList[0].specs = [sepcs]; singularSpecList[0].specs = [specs];
singularSpu = [{ ...temp, sepcs: [sepcs] }]; singularSpu = [{ ...temp, specs: [specs] }];
setSingularSpu(singularSpu); setSingularSpu(singularSpu);
} }
// 多规格 // 多规格
...@@ -155,6 +155,10 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -155,6 +155,10 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
if (name) { if (name) {
if (weight.length) { if (weight.length) {
weight.forEach((item, weightIndex) => { weight.forEach((item, weightIndex) => {
console.log('eee====', item);
if (item.unit && item.unit.length) {
item.unit = item.unit.slice(item.unit.length - 1).toString();
}
multiSpecList[0].specs = weight; multiSpecList[0].specs = weight;
// 循环一次 插入规则列表 // 循环一次 插入规则列表
let isFirstLoops = true; let isFirstLoops = true;
...@@ -203,6 +207,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -203,6 +207,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
singleDelivery, singleDelivery,
specList: +repertoryType === 1 ? singularSpecList : multiSpecList, // 单库存和多库存specList specList: +repertoryType === 1 ? singularSpecList : multiSpecList, // 单库存和多库存specList
items: +repertoryType === 1 ? singularSpu : multiSpu, items: +repertoryType === 1 ? singularSpu : multiSpu,
categoryId: infoMation.categoryId.slice(infoMation.categoryId.length - 1),
}; };
console.log('intactData======>', intactData); console.log('intactData======>', intactData);
setIntactData(intactData); setIntactData(intactData);
...@@ -217,6 +222,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -217,6 +222,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
item.serviceItem.autoStock = autoStock; item.serviceItem.autoStock = autoStock;
item.serviceItem.maxStock = maxStock; item.serviceItem.maxStock = maxStock;
}); });
console.log('intactData', intactData);
setIntactData(intactData); setIntactData(intactData);
} }
return false; return false;
...@@ -347,8 +353,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -347,8 +353,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
setTagList(res.data || []); setTagList(res.data || []);
} }
if (!unitsList.length) { if (!unitsList.length) {
// const res = await apiUnits(); const res = await apiUnits();
// setUnitsList(res.data || []); setUnitsList(res.data || []);
} }
return false; return false;
}; };
...@@ -561,7 +567,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -561,7 +567,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
<InputNumber min={1} style={{ width: 200 }} placeholder="请输入数字" /> <InputNumber min={1} style={{ width: 200 }} placeholder="请输入数字" />
</Form.Item> </Form.Item>
{/* <Form.Item <Form.Item
name="unit" name="unit"
rules={[{ type: 'array', required: true, message: '请选择单位' }]} rules={[{ type: 'array', required: true, message: '请选择单位' }]}
style={{ style={{
...@@ -573,11 +579,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -573,11 +579,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
placeholder="请选择单位" placeholder="请选择单位"
disabled={customer.isEdit && customer.isNormal} disabled={customer.isEdit && customer.isNormal}
showSearch={{ filter: filterCategoryOptions }} showSearch={{ filter: filterCategoryOptions }}
fieldNames={{ label: 'name', value: 'id', children: 'children' }} fieldNames={{ label: 'name', value: 'name', children: 'children' }}
onChange={props.onCategoryChange} onChange={props.onCategoryChange}
options={unitsList} options={unitsList}
/> />
</Form.Item> */} </Form.Item>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="salePrice" name="salePrice"
...@@ -631,7 +637,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -631,7 +637,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
<div className={styles.textStyle}>修改成功后,原库存将被替换,请谨慎操作!</div> <div className={styles.textStyle}>修改成功后,原库存将被替换,请谨慎操作!</div>
</Form.Item> </Form.Item>
<div className={styles.rowWarp}> <div className={styles.rowWarp}>
{singularSpu.length > 0 && {/* {singularSpu.length > 0 &&
takeawayData?.infoMation?.name && takeawayData?.infoMation?.name &&
singularSpu.map((item, index) => ( singularSpu.map((item, index) => (
<div className={styles.specsBetween}> <div className={styles.specsBetween}>
...@@ -649,7 +655,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -649,7 +655,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</div> </div>
</Form.Item> </Form.Item>
</div> </div>
))} ))} */}
</div> </div>
</> </>
)} )}
...@@ -736,7 +742,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -736,7 +742,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
showSearch={{ filter: filterCategoryOptions }} showSearch={{ filter: filterCategoryOptions }}
fieldNames={{ fieldNames={{
label: 'name', label: 'name',
value: 'id', value: 'name',
children: 'children', children: 'children',
}} }}
onChange={props.onCategoryChange} onChange={props.onCategoryChange}
...@@ -927,7 +933,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -927,7 +933,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
统一设置置库存 统一设置置库存
</Button> </Button>
<div className={styles.rowWarp}> {/* <div className={styles.rowWarp}>
{mltiSpu.length > 0 && {mltiSpu.length > 0 &&
takeawayData?.infoMation?.name && takeawayData?.infoMation?.name &&
mltiSpu.map((item, index) => ( mltiSpu.map((item, index) => (
...@@ -947,7 +953,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -947,7 +953,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item> </Form.Item>
</div> </div>
))} ))}
</div> </div> */}
</Form.Item> </Form.Item>
</> </>
)} )}
......
...@@ -22,7 +22,7 @@ import { ...@@ -22,7 +22,7 @@ import {
getByProductType, getByProductType,
apiCreateDraft, apiCreateDraft,
apiEditDraft, apiEditDraft,
apiQueryShopList, apiAddTakeawayProducts,
} from './service'; } from './service';
import { isUrl, filterSendData, clearCurrent, onAutoSaveValue, localAutoSaveKey } from './utils'; import { isUrl, filterSendData, clearCurrent, onAutoSaveValue, localAutoSaveKey } from './utils';
import { ServiceContext } from './context'; import { ServiceContext } from './context';
...@@ -62,7 +62,6 @@ const ServiceGoods = options => { ...@@ -62,7 +62,6 @@ const ServiceGoods = options => {
const [specList, setSpecList] = useState([]); // 规格列表 const [specList, setSpecList] = useState([]); // 规格列表
const [editData, setEditData] = useState({}); // 编辑保存数据 const [editData, setEditData] = useState({}); // 编辑保存数据
const [newCategoryList, setNewCategoryList] = useState({}); const [newCategoryList, setNewCategoryList] = useState({});
const [shopList, setShopList] = useState([{ id: 1, name: '分组1' }, { id: 2, name: '分组2' }]);
const [visibleCacheEdit, setVisibleCacheEdit] = useState(false); // 显示有缓存未保存提示 const [visibleCacheEdit, setVisibleCacheEdit] = useState(false); // 显示有缓存未保存提示
const [checkFormList] = useState([ const [checkFormList] = useState([
...@@ -155,13 +154,6 @@ const ServiceGoods = options => { ...@@ -155,13 +154,6 @@ const ServiceGoods = options => {
setSpecList(result.data || []); setSpecList(result.data || []);
} }
}; };
// 查询分组列表
const queryShopList = async () => {
if (!shopList.length) {
const result = await apiQueryShopList();
setShopList(result.data || []);
}
};
const getAfterSalesAddrsPage = async () => { const getAfterSalesAddrsPage = async () => {
if (!afterAddressList.length) { if (!afterAddressList.length) {
const result = await afterSalesAddrsPage(); const result = await afterSalesAddrsPage();
...@@ -207,15 +199,22 @@ const ServiceGoods = options => { ...@@ -207,15 +199,22 @@ const ServiceGoods = options => {
// 保存商品 // 保存商品
const submitEvent = async () => { const submitEvent = async () => {
const checkPromiseList = clearCurrent(checkFormList).map(({ current }) => current.onCheck()); const checkPromiseList = clearCurrent(checkFormList).map(({ current }) => current.onCheck());
console.log('333333333333', checkFormList);
const resuslt = await Promise.all(checkPromiseList); const resuslt = await Promise.all(checkPromiseList);
console.log('resuslt :>> ', resuslt); console.log('resuslt :>> ', resuslt);
if (!resuslt.includes(null)) { if (!resuslt.includes(null)) {
const params = resuslt.reduce((origin, item) => { const params = resuslt.reduce((origin, item) => {
console.log('origin', origin, item);
const { temp, ...other } = item; const { temp, ...other } = item;
origin[temp] = other; origin[temp] = other;
return origin; return origin;
}, {}); }, {});
// 外卖商品创建
if (+productType === 5) {
console.log('parmas', params);
const res = await sendMerchantProductHttpRequest(params?.takeawayItem?.intactData);
return false;
}
const sendData = filterSendData(productType, params); const sendData = filterSendData(productType, params);
if (isEdit) { if (isEdit) {
sendData.id = pageId; sendData.id = pageId;
...@@ -224,7 +223,7 @@ const ServiceGoods = options => { ...@@ -224,7 +223,7 @@ const ServiceGoods = options => {
sendData.productDraftId = SourceData.id; sendData.productDraftId = SourceData.id;
} }
console.log('sendData :>> ', sendData); console.log('sendData :>> ', sendData);
// sendMerchantProductHttpRequest(sendData); sendMerchantProductHttpRequest(sendData);
} }
}; };
...@@ -471,7 +470,6 @@ const ServiceGoods = options => { ...@@ -471,7 +470,6 @@ const ServiceGoods = options => {
ref={basicRef} ref={basicRef}
editData={editData.infoMation} editData={editData.infoMation}
newCategoryList={newCategoryList} newCategoryList={newCategoryList}
shopList={shopList}
categoryList={categoryList} categoryList={categoryList}
virtualCategoryList={virtualCategoryList} virtualCategoryList={virtualCategoryList}
brandList={brandList} brandList={brandList}
...@@ -544,7 +542,6 @@ const ServiceGoods = options => { ...@@ -544,7 +542,6 @@ const ServiceGoods = options => {
infoMation={editData.infoMation} infoMation={editData.infoMation}
supplierIdList={supplierIdList} supplierIdList={supplierIdList}
onValuesChange={onValuesChange} onValuesChange={onValuesChange}
/> />
</> </>
)} )}
......
...@@ -118,11 +118,14 @@ export const apiEditDraft = data => ...@@ -118,11 +118,14 @@ export const apiEditDraft = data =>
data, data,
}); });
// 查询分组列表 // 菜单分组 http://yapi.quantgroups.com/project/389/interface/api/64044
export const apiQueryShopList = data => export const apiQueryShopList = data =>
request.post('/api/merchants/products/storageRack/listByShopIdAndStorageRackIds', { request.post('/api/merchants/products/storageRack/listByShopIdAndStorageRackIds', {
prefix: goodsApi, prefix: goodsApi,
data, data: stringify(_.omitBy(data, v => !v)),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}); });
// 新建分组 // 新建分组
export const apiCreateShop = data => export const apiCreateShop = data =>
...@@ -131,20 +134,26 @@ export const apiCreateShop = data => ...@@ -131,20 +134,26 @@ export const apiCreateShop = data =>
data, data,
}); });
// 新增外卖商品 http://yapi.quantgroups.com/project/389/interface/api/57324 // 新增外卖商品 http://yapi.quantgroups.com/project/389/interface/api/57324
export const apiAddGoods = data => export const apiAddTakeawayProducts = data =>
request.post('/v1/channels/products/add', { request.post('/v1/channels/products/add', {
prefix: goodsApi, prefix: goodsApi,
data, data,
}); });
// 商品标签列表 http://yapi.quantgroups.com/project/389/interface/api/57979 // 商品标签列表 http://yapi.quantgroups.com/project/389/interface/api/57979
export const apiTagList = data => export const apiTagList = data =>
request.post('/v1/channels/products/tag/getAll', { request.post('/api/merchants/products/tag/getAll', {
prefix: goodsApi, prefix: goodsApi,
data, data,
}); });
// 单位列表 http://yapi.quantgroups.com/project/389/interface/api/57179 // 单位列表 http://yapi.quantgroups.com/project/389/interface/api/57179
export const apiUnits = data => export const apiUnits = data =>
request.get('/api/consoles/products/units', { request.get('/api/merchants/products/units', {
prefix: goodsApi,
data,
});
// 获取shopids http://yapi.quantgroups.com/project/389/interface/api/38056
export const apiShopIds = data =>
request.get('/api/merchants/shops/getBySupplierId?state=1', {
prefix: goodsApi, prefix: goodsApi,
data, data,
}); });
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