Commit 6db69753 authored by 陈万宝's avatar 陈万宝

feat: 更新多规格

parent ae61a64f
...@@ -62,7 +62,7 @@ class goodsManage extends Component { ...@@ -62,7 +62,7 @@ class goodsManage extends Component {
auditRow: {}, // 查看审核信息使用 auditRow: {}, // 查看审核信息使用
isVisibleDraft: false, // 显示隐藏草稿箱 isVisibleDraft: false, // 显示隐藏草稿箱
isEditDraft: false, // 是否编辑草稿 isEditDraft: false, // 是否编辑草稿
productType: 1, // 商品类型 productType: 5, // 商品类型
takeAway: {}, // 弹窗外卖商品参数 takeAway: {}, // 弹窗外卖商品参数
searchValue: {}, // 搜索条件 searchValue: {}, // 搜索条件
refresh: '', // 外卖刷新 refresh: '', // 外卖刷新
...@@ -78,7 +78,7 @@ class goodsManage extends Component { ...@@ -78,7 +78,7 @@ class goodsManage extends Component {
componentDidMount() { componentDidMount() {
this.props.goodsManage.tableData = {}; this.props.goodsManage.tableData = {};
this.categoryList(); this.categoryList(this.state.productType);
this.categoryListByType(this.state.productType); this.categoryListByType(this.state.productType);
this.getVirtualCategory(); this.getVirtualCategory();
this.specList(); this.specList();
......
...@@ -12,7 +12,7 @@ import { ServiceContext } from '../context'; ...@@ -12,7 +12,7 @@ import { ServiceContext } from '../context';
import { debounce } from '@/utils/utils'; import { debounce } from '@/utils/utils';
import AddMenusModal from './AddMenusModal'; import AddMenusModal from './AddMenusModal';
import UploadImage from './UploadImage'; import UploadImage from './UploadImage';
import { apiShopIds, apiQueryShopList } from '../service'; import { apiShopIds, apiQueryShopList, getByProductType } from '../service';
const CreateSelectOption = optionList => const CreateSelectOption = optionList =>
optionList.map(brandItem => ( optionList.map(brandItem => (
...@@ -34,6 +34,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -34,6 +34,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
brandList, brandList,
afterAddressList, afterAddressList,
specListData, specListData,
shopGetByProductType,
} = props; } = props;
const [form] = Form.useForm(); const [form] = Form.useForm();
const [noreBrandList, setNoreBrandList] = useState([]); const [noreBrandList, setNoreBrandList] = useState([]);
...@@ -66,6 +67,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -66,6 +67,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
return null; return null;
} }
}; };
// 自定义加入菜单 // 自定义加入菜单
const showModal = () => { const showModal = () => {
childAddMenusModalRef.current.setOpen(true); childAddMenusModalRef.current.setOpen(true);
...@@ -136,9 +138,9 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -136,9 +138,9 @@ const FormInformationBasic = forwardRef((props, ref) => {
}, [brandList]); }, [brandList]);
useEffect(() => { useEffect(() => {
console.log('商品类目', newCategoryList[customer.productType]);
if (!editData) return; if (!editData) return;
if (editData.productType === 5 && editData.name) { if (editData.productType === 5 && editData.name) {
shopGetByProductType(5);
queryShopList({ shopId: editData.productRefShopId }); queryShopList({ shopId: editData.productRefShopId });
setIsEditTakeaway(true); setIsEditTakeaway(true);
} }
...@@ -156,7 +158,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -156,7 +158,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
name: '', name: '',
categoryId: [], categoryId: [],
description: '', description: '',
productRefShopId: [15], productRefShopId: [],
storageRackIds: [], storageRackIds: [],
}} }}
scrollToFirstError scrollToFirstError
......
...@@ -75,6 +75,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -75,6 +75,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const [repertoryState, setRepertoryState] = useState(''); const [repertoryState, setRepertoryState] = useState('');
const [repertoryModel, setRepertoryModel] = useState({}); const [repertoryModel, setRepertoryModel] = useState({});
const [tempMultiSpu, setTempMultiSpu] = useState([]); const [tempMultiSpu, setTempMultiSpu] = useState([]);
const [tempWeight, setTempWeight] = useState([]);
const [tempSpecs, setTempSpecs] = useState([]);
const initialDealValue = [ const initialDealValue = [
{ {
specGroupName: '', specGroupName: '',
...@@ -101,11 +104,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -101,11 +104,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const takeawayCalc = takeawayData => { const takeawayCalc = takeawayData => {
// 商品基本信息编辑商品名称 // 商品基本信息编辑商品名称
const { infoMation: name, infoMation, takeawayItem } = takeawayData; const { infoMation: name, infoMation, takeawayItem } = takeawayData;
console.log('infoMation========', infoMation); console.log('i========', infoMation, takeawayItem, repertoryType);
// weight 份量 specs规格 生成sku规则 weight * specs // weight 份量 specs规格 生成sku规则 weight * specs
const { const {
specs = [], specs = tempSpecs,
weight = [], weight = tempWeight,
description, description,
detailImageList, detailImageList,
list, list,
...@@ -125,10 +128,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -125,10 +128,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
id, id,
categoryId, categoryId,
} = takeawayItem; } = takeawayItem;
console.log('id', id, skuList); console.log('skuList====', skuList);
const singularSpecList = [{ specGroupName: '份量', generateSku: 1, specs: [] }]; // 单规格 const singularSpecList = [{ specGroupName: '份量', generateSku: 1, specs: [] }]; // 单规格
const multiSpecList = [{ specGroupName: '份量', generateSku: 1, specs: [] }]; // 多规格 const multiSpecList = [{ specGroupName: '份量', generateSku: 1, specs: [] }]; // 多规格
// const multiSpu = customer.isEdit ? skuList:[]; // 多库存spu、
const multiSpu = []; // 多库存spu、 const multiSpu = []; // 多库存spu、
let singularSpu = []; // 单库存spu let singularSpu = []; // 单库存spu
const saleTimesTemp = []; const saleTimesTemp = [];
let initIndex = 0; let initIndex = 0;
...@@ -143,7 +148,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -143,7 +148,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
salePrice: salePrice || 0, salePrice: salePrice || 0,
productStock, productStock,
list: 1, list: 1,
id: skuList?.length === 1 ? skuList[0].id:'', // 单规格默认取第一个 id: skuList?.length === 1 ? skuList[0].id : '', // 单规格默认取第一个
serviceItem: { serviceItem: {
description, // 商品描述 description, // 商品描述
maxStock, // 最大库存 maxStock, // 最大库存
...@@ -173,16 +178,16 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -173,16 +178,16 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
singularSpu = [{ ...temp, specs: [specs] }]; singularSpu = [{ ...temp, specs: [specs] }];
setSingularSpu(singularSpu); setSingularSpu(singularSpu);
} }
console.log('singularSpu', singularSpu); console.log('weight', weight);
// 多规格 // 多规格
if (+repertoryType === 2) { if (+repertoryType === 2) {
if (name) { if (name || editData.name) {
console.log('weight', weight);
if (weight.length) { if (weight.length) {
weight.forEach((item, weightIndex) => { weight.forEach((item, weightIndex) => {
console.log('eee====', item);
if (item?.unit && item?.unit.length) { if (item?.unit && item?.unit.length) {
item.unit = item?.unit?.slice(item.unit.length - 1)?.toString(); item.unit =
item?.unit &&
(Array.isArray(item?.unit) ? item.unit.slice(item.unit.length - 1)[0] : item.unit);
} }
if (item && !item.specGroupName) { if (item && !item.specGroupName) {
item.specGroupName = '份量'; item.specGroupName = '份量';
...@@ -248,21 +253,26 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -248,21 +253,26 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}); });
} }
} }
// console.log('multiSpu', multiSpu);
if (tempMultiSpu.length) { if (tempMultiSpu.length) {
multiSpu.forEach((item, index) => { multiSpu.forEach((item, index) => {
tempMultiSpu.forEach((itm, idx) => { tempMultiSpu.forEach((itm, idx) => {
console.log('itm', itm);
if (item.unique === itm.unique) { if (item.unique === itm.unique) {
item.serviceItem = objectComparison(item.serviceItem, itm); item.serviceItem = objectComparison(item.serviceItem, itm);
item.id = itm.id;
console.log('item', item);
} }
}); });
}); });
} }
console.log('multiSpu=====11', tempMultiSpu);
console.log('multiSpu=====22', multiSpu);
// debugger // debugger
console.log('multiSpu', multiSpu);
// debugger;
setMultiSpu(multiSpu); setMultiSpu(multiSpu);
} }
console.log('categoryId', categoryId);
// +repertoryType === 1 单规格 2多规格 // +repertoryType === 1 单规格 2多规格
const intactDataTemp = { const intactDataTemp = {
...takeawayItem, ...takeawayItem,
...@@ -285,7 +295,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -285,7 +295,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}; };
setIntactData(intactDataTemp); setIntactData(intactDataTemp);
console.log('intactData======>', intactDataTemp); console.log('intactData======>', form.getFieldsValue(), intactDataTemp);
return intactData; return intactData;
}; };
// 过滤对象 // 过滤对象
...@@ -307,14 +317,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -307,14 +317,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const takeawayData = customer.isEdit const takeawayData = customer.isEdit
? { takeawayItem: Object.assign({}, editData, values) } ? { takeawayItem: Object.assign({}, editData, values) }
: localStorage.get(localAutoSaveKey) || {}; : localStorage.get(localAutoSaveKey) || {};
console.log('takeawayDatatakeawayData', takeawayData);
setTakeawayData(takeawayData); setTakeawayData(takeawayData);
takeawayCalc(takeawayData); takeawayCalc(takeawayData);
}, 400); }, 400);
// 设置库存 // 设置库存
const modifiedInventory = (type, idx, values) => { const modifiedInventory = (type, idx, values) => {
const { productStock, maxStock, autoStock } = values; const { productStock, maxStock, autoStock } = values;
console.log('type', type);
if (type === 'multi') { if (type === 'multi') {
multiSpu.map(item => { multiSpu.map(item => {
if (item.unique === idx) { if (item.unique === idx) {
...@@ -340,16 +348,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -340,16 +348,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
tempMultiSpu.push(...temp); tempMultiSpu.push(...temp);
setTempMultiSpu(tempMultiSpu); setTempMultiSpu(tempMultiSpu);
setMultiSpu(multiSpu); setMultiSpu(multiSpu);
// if (intactData?.items.length) {
// intactData?.items.forEach(item => {
// item.serviceItem.productStock = productStock;
// item.serviceItem.autoStock = autoStock;
// item.serviceItem.maxStock = maxStock;
// return item;
// });
// const temp = { ...intactData };
// setIntactData(temp);
// }
} }
console.log('=========', multiSpu, tempMultiSpu); console.log('=========', multiSpu, tempMultiSpu);
getFormValues(); getFormValues();
...@@ -400,8 +398,10 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -400,8 +398,10 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
); );
// 切换库存 // 切换库存
const onChangeRepertory = e => { const onChangeRepertory = e => {
setRepertoryType(`${e.target.value}`); if (e) {
console.log('e,===', e); setRepertoryType(`${e.target.value} `);
}
setRepertoryType(2);
}; };
// 勾选库存设置 // 勾选库存设置
const onChangeSetRepertory = e => { const onChangeSetRepertory = e => {
...@@ -472,7 +472,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -472,7 +472,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
if (customer.isEdit || customer.isUseCache) { if (customer.isEdit || customer.isUseCache) {
if (!editData) return; if (!editData) return;
let { label, firstCategoryId, secondCategoryId, thirdCategoryId, id } = editData; let { label, firstCategoryId, secondCategoryId, thirdCategoryId, id } = editData;
console.log('id', id);
editData.label = +label; editData.label = +label;
if (editData?.skuList.length) { if (editData?.skuList.length) {
editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum; editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum;
...@@ -480,8 +479,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -480,8 +479,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
if (editData?.skuList.length === 1) { if (editData?.skuList.length === 1) {
let { let {
productStock, productStock,
shopId,
specs, specs,
serviceItem: { maxStock, saleTimeType, saleDates, saleTimes,id }, serviceItem: { maxStock, saleTimeType, saleDates, saleTimes, id },
} = editData?.skuList[0]; } = editData?.skuList[0];
let { quantity, unit, salePrice } = specs[0]; let { quantity, unit, salePrice } = specs[0];
editData.productStock = productStock; editData.productStock = productStock;
...@@ -493,23 +493,62 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -493,23 +493,62 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
editData.saleTimeType = saleTimeType; editData.saleTimeType = saleTimeType;
editData.saleDates = saleDates; editData.saleDates = saleDates;
editData.saleTimes = saleTimes.length editData.saleTimes = saleTimes.length
editData.skuId = id
? saleTimes.map(item => { ? saleTimes.map(item => {
item = [moment(item?.startTime, format), moment(item?.endTime, format)]; return [moment(item?.startTime, format), moment(item?.endTime, format)];
return item;
}) })
: []; : [];
editData.productRefShopId = editData.shopId;
editData.skuId = id;
form.setFieldsValue(editData);
setTimeType(saleTimeType); setTimeType(saleTimeType);
} } else {
// 多规格
setRepertoryType(`2`);
let {
serviceItem: { saleTimeType, saleDates, saleTimes },
} = editData?.skuList[0];
let specList = editData?.specList;
let weight = specList.filter(item => item.specGroupName === '份量');
let specs = specList.filter(item => item.specGroupName !== '份量');
editData.categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
editData.saleTimeType = saleTimeType;
editData.saleDates = saleDates;
editData.saleTimes = saleTimes.length
? saleTimes.map(item => {
return [moment(item?.startTime, format), moment(item?.endTime, format)];
})
: [];
editData.productRefShopId = editData.shopId;
// setTempWeight(weight)
// setTempSpecs(specs)
setTimeType(saleTimeType);
form.setFieldsValue({ weight: weight[0].specs });
form.setFieldsValue(editData); form.setFieldsValue(editData);
form.setFieldsValue({ specs });
console.log('editData?.skuList', editData?.skuList);
const tempMultiSpu = editData?.skuList.map(item => {
if (item) {
let weightIdx = item.specs.findIndex(itm => itm.specGroupName === '份量');
console.log('weightIdx', weightIdx);
let specsIdx = item.specs.findIndex(itm => itm.specGroupName !== '份量');
console.log('specsIdx', specsIdx);
item.unique = `${item.specs[weightIdx]?.specName}-${item.specs[specsIdx]?.specGroupName}-${item.specs[specsIdx]?.specName}`;
}
return item;
});
setTempMultiSpu(tempMultiSpu || []);
// debugger
}
form.setFieldsValue({ productRefShopId: editData.shopId });
onCardSuccessImageList(editData?.detailImageList); onCardSuccessImageList(editData?.detailImageList);
getFormValues(); getFormValues();
// setInitValue({ ...editData }); // setInitValue({ ...editData });
}else {
} }
} }
}, [customer.isEdit, editData]); }, [customer.isEdit, editData]);
useEffect(() => { useEffect(() => {
setIntactData(intactData); setIntactData(intactData);
...@@ -671,6 +710,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -671,6 +710,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
<Title title="规格信息" /> <Title title="规格信息" />
{!customer.isEdit && (
<Form.Item label="库存" name="stock"> <Form.Item label="库存" name="stock">
<Radio.Group <Radio.Group
options={ENUM_REPERTORY} options={ENUM_REPERTORY}
...@@ -680,6 +720,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -680,6 +720,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
optionType="button" optionType="button"
/> />
</Form.Item> </Form.Item>
)}
{/* 单规格 */} {/* 单规格 */}
{repertoryType === '1' && ( {repertoryType === '1' && (
<> <>
...@@ -828,7 +869,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -828,7 +869,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
name={[weightField.name, 'unit']} name={[weightField.name, 'unit']}
rules={[ rules={[
{ {
type: 'array', // type: 'array',
required: true, required: true,
message: '请选择单位', message: '请选择单位',
}, },
...@@ -890,19 +931,28 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -890,19 +931,28 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
)} )}
</Form.List> </Form.List>
</Form.Item> </Form.Item>
{takeawayData?.takeawayItem?.weight?.length > 0 && ( {/* takeawayData?.takeawayItem?.weight?.length > 0 && */}
{
<> <>
<Form.Item> <Form.Item>
<div>添加规格(如加料、甜度、辣度等)</div> <div>添加规格(如加料、甜度、辣度等)</div>
<Form.List name="specs"> <Form.List
name="specs"
initialValue={[
{
specGroupName: '1',
specs: [],
},
]}
>
{(specsFields, { add, remove }) => ( {(specsFields, { add, remove }) => (
<> <>
{specsFields.map((field, index) => ( {specsFields.map((specsField, index) => (
<Form.Item key={field.key} className={styles.conBg}> <Form.Item key={specsField.key} className={styles.conBg}>
<Form.Item <Form.Item
{...field} {...specsField}
validateTrigger={['onChange', 'onBlur']} validateTrigger={['onChange', 'onBlur']}
name={[field.name, 'specGroupName']} name={[specsField.name, 'specGroupName']}
rules={[ rules={[
{ {
required: true, required: true,
...@@ -914,15 +964,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -914,15 +964,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
<Input placeholder="规格名称" className={styles.nameWidth} /> <Input placeholder="规格名称" className={styles.nameWidth} />
</Form.Item> </Form.Item>
{specsFields.length > 1 ? ( {/* {specsFields.length > 1 ? ( */}
<MinusCircleOutlined <MinusCircleOutlined
className="dynamic-delete-button" className="dynamic-delete-button"
onClick={() => remove(field.name)} onClick={() => remove(specsField.name)}
/> />
) : null} {/* ) : null} */}
<Form.List <Form.List
{...field} {...specsField}
name={[field.name, 'specs']} name={[specsField.name, 'specs']}
initialValue={[ initialValue={[
{ {
specName: '', specName: '',
...@@ -1046,7 +1096,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -1046,7 +1096,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</div> </div>
</Form.Item> </Form.Item>
</> </>
)} }
</> </>
)} )}
</Form> </Form>
......
...@@ -86,7 +86,7 @@ const ServiceGoods = options => { ...@@ -86,7 +86,7 @@ const ServiceGoods = options => {
const resetForm = () => clearCurrent(checkFormList).forEach(({ current }) => current.reset()); const resetForm = () => clearCurrent(checkFormList).forEach(({ current }) => current.reset());
const onValuesChange = e => { const onValuesChange = e => {
console.log('e======', e, !isEdit, visibleCacheEdit); // console.log('e======', e, !isEdit, visibleCacheEdit);
if (!isEdit) { if (!isEdit) {
if (visibleCacheEdit) { if (visibleCacheEdit) {
setVisibleCacheEdit(false); setVisibleCacheEdit(false);
...@@ -513,6 +513,7 @@ const ServiceGoods = options => { ...@@ -513,6 +513,7 @@ const ServiceGoods = options => {
ref={basicRef} ref={basicRef}
editData={editData.infoMation} editData={editData.infoMation}
newCategoryList={newCategoryList} newCategoryList={newCategoryList}
shopGetByProductType={shopGetByProductType}
categoryList={categoryList} categoryList={categoryList}
virtualCategoryList={virtualCategoryList} virtualCategoryList={virtualCategoryList}
brandList={brandList} brandList={brandList}
......
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