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

feat: 更新多规格

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