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

feat: 更新创建商品接口

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