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

feat: 更新商品库内容

parent 139bafe6
...@@ -262,12 +262,16 @@ ...@@ -262,12 +262,16 @@
} }
} }
} }
.dealInput { .conBg {
background:#f8f8f8 ;
min-width: 100%;
width: fit-content;
:global { :global {
.ant-form-item-control-input-content {
.ant-input { .ant-input {
margin-bottom: 8px; margin: 10px 0;
} }
.ant-form-item {
margin-bottom: 8px;
} }
} }
} }
......
...@@ -36,16 +36,21 @@ import styles from '../common.less'; ...@@ -36,16 +36,21 @@ import styles from '../common.less';
import AddRepertoryModal from './AddRepertoryModal'; import AddRepertoryModal from './AddRepertoryModal';
import AddMultiSpecModal from './AddMultiSpecModal'; import AddMultiSpecModal from './AddMultiSpecModal';
import { apiTagList, apiUnits } from '../service'; import { apiTagList, apiUnits } from '../service';
import { localAutoSaveKey } from '../utils';
import localStorage from '@/utils/localStorage';
const createInitValues = () => ({ const createInitValues = () => ({
description: 1, // 商品描述 description: '', // 商品描述
detailImageList: [], // 商品图片 detailImageList: [], // 商品图片
stock: '1', // 库存类型 stock: '1', // 库存类型
saleTimeType: 1, // 售卖时间
singleDelivery: 0, // 单点不送
list: 1, // 列出商品
}); });
const format = 'HH:mm'; const format = 'HH:mm';
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const TakeawayGoodsInfo = forwardRef((props, ref) => { const TakeawayGoodsInfo = forwardRef((props, ref) => {
const { editData } = props; const { editData, infoMation } = props;
const [form] = Form.useForm(); const [form] = Form.useForm();
const [initValue, setInitValue] = useState(createInitValues()); const [initValue, setInitValue] = useState(createInitValues());
const customer = useContext(ServiceContext); const customer = useContext(ServiceContext);
...@@ -55,7 +60,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -55,7 +60,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const AddRepertoryRef = useRef(null); const AddRepertoryRef = useRef(null);
const AddMultiSpecRef = useRef(null); const AddMultiSpecRef = useRef(null);
const [saleDates, setSaleDates] = useState({ const [saleDates, setSaleDates] = useState({
unavailableDate: [], saleDates: [],
saleTimes: [], saleTimes: [],
// saleTimes: [[moment('22-02', 'HH:mm'), moment('23-02', 'HH:mm')]], // saleTimes: [[moment('22-02', 'HH:mm'), moment('23-02', 'HH:mm')]],
}); // 可售日期 }); // 可售日期
...@@ -63,6 +68,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -63,6 +68,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const [repertoryType, setRepertoryType] = useState('1'); const [repertoryType, setRepertoryType] = useState('1');
const [tagList, setTagList] = useState([]); const [tagList, setTagList] = useState([]);
const [unitsList, setUnitsList] = useState([]); const [unitsList, setUnitsList] = useState([]);
const [takeawayData, setTakeawayData] = useState({});
const [takeawaySku, setTakeawaySku] = useState({});
const initialDealValue = [ const initialDealValue = [
{ {
specGroupName: '', specGroupName: '',
...@@ -79,13 +87,57 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -79,13 +87,57 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const values = await form.validateFields(); const values = await form.validateFields();
return { return {
...values, ...values,
temp: 'settlementItem', temp: 'takeawayItem',
limitPurchase: values.limitPurchase ? 1 : 0, limitPurchase: values.limitPurchase ? 1 : 0,
}; };
} catch (errorInfo) { } catch (errorInfo) {
return null; return null;
} }
}; };
const takeawayCalc = takeawayData => {
// 商品基本信息编辑商品名称
const {
infoMation: name,
takeawayItem,
minPurchaseNum,
saleTimeType,
singleDelivery,
list,
label,
saleDates,
description,
maxStock,
saleTimes,
} = takeawayData;
// weight 份量 specs规格 生成sku规则 weight * specs
const { specs = [], weight = [] } = takeawayItem;
if (name) {
console.log('===', name);
if (weight.length) {
const takeawaySkuTemp = [];
weight.map((item, weightIndex) => {
item.salePrice = 1;
item.productStock = 2;
item.list = 1;
item.serviceItem = {
description, // 商品描述
maxStock, // 最大库存
minPurchaseNum, // 最少购买
saleTimeType, // 售卖时间
singleDelivery, // 单点不送
list, // 是否列出 1 是 0 否(外卖商品必填)
label, // 商品标签id
saleDates, // 可售日期 1-8
saleTimes,
autoStock: '', // 弹框设置---自动补足
};
item.specs = {};
});
console.log('3333', weight, takeawaySkuTemp);
}
}
};
const onChange = () => {}; const onChange = () => {};
const onDealFinish = values => { const onDealFinish = values => {
console.log('Received values of form:', values); console.log('Received values of form:', values);
...@@ -93,8 +145,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -93,8 +145,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
console.log('values========', values); console.log('values========', values);
props.onValuesChange({ takeawayItem: values });
props.onValuesChange({ settlementItem: values }); const takeawayData = localStorage.get(localAutoSaveKey);
console.log('takeawayData', takeawayData);
setTakeawayData(takeawayData);
takeawayCalc(takeawayData);
}, 400); }, 400);
const fileterBrandOptions = (input, options) => options.children.includes(input); const fileterBrandOptions = (input, options) => options.children.includes(input);
...@@ -110,6 +165,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -110,6 +165,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}, },
})); }));
const startTime = moment(moment().format(format));
const endTime = moment(moment().format(format));
// 上传图片 // 上传图片
const onCardSuccessImageList = imgList => { const onCardSuccessImageList = imgList => {
setDetailImageList(imgList); setDetailImageList(imgList);
...@@ -233,13 +290,13 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -233,13 +290,13 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
// rules={[{ type: 'array', required: true, message: '请输入售卖时间!' }]} // rules={[{ type: 'array', required: true, message: '请输入售卖时间!' }]}
> >
<Radio.Group onChange={onChangeTime}> <Radio.Group onChange={onChangeTime}>
<Radio value={0}>全时段</Radio> <Radio value={1}>全时段</Radio>
<Radio value={1}>自定义售卖时间</Radio> <Radio value={2}>自定义售卖时间</Radio>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
{timeType === 1 && ( {timeType === 2 && (
<> <>
<Form.Item name="unavailableDate" label="售卖时期(可多选)"> <Form.Item name="saleDates" label="售卖时期(可多选)">
<Checkbox.Group> <Checkbox.Group>
<Row> <Row>
<Col className={styles.colRow} span={8}> <Col className={styles.colRow} span={8}>
...@@ -285,7 +342,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -285,7 +342,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}, },
]} ]}
> >
<RangePicker picker="time" format={format} onChange={onChange} /> <RangePicker
picker="time"
defaultPickerValue={[startTime, endTime]}
format={format}
onChange={onChange}
/>
</Form.Item> </Form.Item>
{fields.length > 1 ? ( {fields.length > 1 ? (
<MinusCircleOutlined <MinusCircleOutlined
...@@ -334,26 +396,22 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -334,26 +396,22 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
options={tagList} options={tagList}
/> />
</Form.Item> </Form.Item>
<Form.Item name="singleDelivery" label="单点不送"> <Form.Item name="singleDelivery" label="单点不送" extra="开启后顾客点单则此商品不可下单">
<Radio.Group> <Radio.Group>
<Radio value={1}></Radio> <Radio value={1}></Radio>
<Radio value={0}></Radio> <Radio value={0}></Radio>
</Radio.Group> </Radio.Group>
开启后顾客点单则此商品不可下单
</Form.Item> </Form.Item>
<Form.Item name="list" label="列出商品"> <Form.Item name="list" label="列出商品" extra="开启后平台展示商品">
<Radio.Group> <Radio.Group>
<Radio value={1}></Radio> <Radio value={1}></Radio>
<Radio value={0}></Radio> <Radio value={0}></Radio>
</Radio.Group> </Radio.Group>
开启后平台展示商品
</Form.Item> </Form.Item>
<Title title="规格信息" /> <Title title="规格信息" />
<Form.Item label="份量" className={styles.required}> <Form.Item label="份量" className={styles.required}>
<Form.Item <Form.Item
name="receptionVolume" name="quantity"
style={{ style={{
display: 'inline-block', display: 'inline-block',
}} }}
...@@ -362,7 +420,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -362,7 +420,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="categoryId" name="unit"
rules={[{ type: 'array', required: true, message: '请选择单位' }]} rules={[{ type: 'array', required: true, message: '请选择单位' }]}
style={{ style={{
display: 'inline-block', display: 'inline-block',
...@@ -380,7 +438,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -380,7 +438,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item> </Form.Item>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="销售价格" name="salePrice"
label="销售价格" label="销售价格"
rules={[{ required: true, message: '请输入销售价格' }]} rules={[{ required: true, message: '请输入销售价格' }]}
> >
...@@ -429,7 +487,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -429,7 +487,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item> </Form.Item>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="receptionVolume" name="maxStock"
label="最大库存" label="最大库存"
rules={[{ required: true, message: '请填写最大库存' }]} rules={[{ required: true, message: '请填写最大库存' }]}
> >
...@@ -450,16 +508,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -450,16 +508,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
<> <>
<Form.Item> <Form.Item>
<div>份量(如大小/小份、微辣/特辣等)</div> <div>份量(如大小/小份、微辣/特辣等)</div>
<Form.List name="deal"> {/* <Form.List name="deal">
{(dealFields, { add, remove }) => ( {(dealFields, { add, remove }) => (
<> <>
{dealFields.map((field, index) => ( {dealFields.map((field, index) => (
<Form.Item key={field.key}> <Form.Item key={field.key} className={styles.conBg}>
<Form.Item <Form.Item
{...field} {...field}
validateTrigger={['onChange', 'onBlur']} validateTrigger={['onChange', 'onBlur']}
name={[field.name, 'specGroupName']} name={[field.name, 'specGroupName']}
className={styles.dealInput}
rules={[ rules={[
{ {
required: true, required: true,
...@@ -481,35 +538,41 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -481,35 +538,41 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
className="dynamic-delete-button" className="dynamic-delete-button"
onClick={() => remove(field.name)} onClick={() => remove(field.name)}
/> />
) : null} ) : null} */}
<Form.List <Form.List name="weight">
{...field} {(weightFields, { add: weightAdd, remove: weightRemove }) => (
name={[field.name, 'specs']} <>
initialValue={[ {weightFields.map(weightField => (
<Space key={weightField.key} align="baseline" className={styles.conBg}>
<Form.Item
{...weightField}
name={[weightField.name, 'specName']}
rules={[
{ {
specName: '', required: true,
message: '请输入名称',
}, },
]} ]}
> >
{(dealInfoFields, { add: dealAdd, remove: dealRemove }) => ( <Input style={{ width: '200px' }} placeholder="名称" />
<> </Form.Item>
{dealInfoFields.map(dealInfoField => (
<Space key={dealInfoField.key} align="baseline">
<Form.Item <Form.Item
{...dealInfoField} {...weightField}
name={[dealInfoField.name, 'specName']} name={[weightField.name, 'unit']}
rules={[ rules={[
{ {
required: true, required: true,
message: '请输入名称', message: '份量',
}, },
]} ]}
> >
<Input style={{ width: '200px' }} placeholder="名称" /> <Input style={{ width: '200px' }} placeholder="约 份量(数字)" />
</Form.Item> </Form.Item>
<span className="ant-form-text"></span>
<Form.Item <Form.Item
{...dealInfoField} {...weightField}
name={[dealInfoField.name, 'quantity']} name={[weightField.name, 'quantity']}
rules={[ rules={[
{ {
type: 'array', type: 'array',
...@@ -532,23 +595,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -532,23 +595,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
/> />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
{...dealInfoField} {...weightField}
name={[dealInfoField.name, 'unit']} name={[weightField.name, 'salePrice']}
rules={[
{
required: true,
message: '份量',
},
]}
>
<Input
style={{ width: '200px' }}
placeholder="约 份量(数字)"
/>
</Form.Item>
<Form.Item
{...dealInfoField}
name={[dealInfoField.name, 'salePrice']}
rules={[ rules={[
{ {
required: true, required: true,
...@@ -559,8 +607,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -559,8 +607,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
<Input style={{ width: '200px' }} placeholder="销售价(元)" /> <Input style={{ width: '200px' }} placeholder="销售价(元)" />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
{...dealInfoField} {...weightField}
name={[dealInfoField.name, 'activityPrice']} name={[weightField.name, 'activityPrice']}
rules={[ rules={[
{ {
required: true, required: true,
...@@ -570,32 +618,30 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -570,32 +618,30 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
<Input style={{ width: '200px' }} placeholder="活动价(元)" /> <Input style={{ width: '200px' }} placeholder="活动价(元)" />
</Form.Item> </Form.Item>
<MinusCircleOutlined <MinusCircleOutlined onClick={() => weightRemove(weightField.name)} />
onClick={() => dealRemove(dealInfoField.name)}
/>
</Space> </Space>
))} ))}
<Form.Item> <Form.Item>
<Button <Button
type="dashed" type="primary"
onClick={() => dealAdd()} onClick={() => weightAdd()}
block block
style={{ width: '400px' }} style={{ width: '400px' }}
icon={<PlusOutlined />} icon={<PlusOutlined />}
> >
新增加价 新增份量
</Button> </Button>
</Form.Item> </Form.Item>
</> </>
)} )}
</Form.List> </Form.List>
</Form.Item> {/* </Form.Item>
))} ))} */}
<Form.Item> {/* <Form.Item>
<Button <Button
type="dashed" type="primary"
onClick={() => add()} onClick={() => add()}
style={{ style={{
width: '400px', width: '400px',
...@@ -604,29 +650,22 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -604,29 +650,22 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
添加份量 添加份量
</Button> </Button>
</Form.Item> </Form.Item> */}
</> {/* </>
)} )}
</Form.List> </Form.List> */}
</Form.Item> </Form.Item>
<Form.Item> <Form.Item>
<div>添加规格(如加料、甜度、辣度等)</div> <div>添加规格(如加料、甜度、辣度等)</div>
<Form.Item>
<Form.List name="specs"> <Form.List name="specs">
{(specsFields, { add, remove }) => ( {(specsFields, { add, remove }) => (
<> <>
{specsFields.map((field, index) => ( {specsFields.map((field, index) => (
<Form.Item <Form.Item key={field.key} className={styles.conBg}>
// {...(index === 0 ? formItemLayout : formItemLayoutWithOutLabel)}
// label={index === 0 ? 'Passengers' : ''}
required={false}
key={field.key}
>
<Form.Item <Form.Item
{...field} {...field}
validateTrigger={['onChange', 'onBlur']} validateTrigger={['onChange', 'onBlur']}
className={styles.deal} name={[field.name, 'specGroupName']}
style={{ marginBottom: '8px' }}
rules={[ rules={[
{ {
required: true, required: true,
...@@ -634,55 +673,49 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -634,55 +673,49 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
message: '请输入规格名称', message: '请输入规格名称',
}, },
]} ]}
noStyle
> >
<Input placeholder="规格名称" className={styles.nameWidth} /> <Input placeholder="规格名称" className={styles.nameWidth} />
</Form.Item>
{specsFields.length > 1 ? ( {specsFields.length > 1 ? (
<MinusCircleOutlined <MinusCircleOutlined
className="dynamic-delete-button" className="dynamic-delete-button"
onClick={() => remove(field.name)} onClick={() => remove(field.name)}
/> />
) : null} ) : null}
</Form.Item> <Form.List
<Form.Item> {...field}
<Form.List name="sights"> name={[field.name, 'specs']}
{(sightsFields, { add, remove }) => ( initialValue={[
<> {
{sightsFields.map(field => ( specName: '',
<Space key={field.key} align="baseline"> salePrice: '',
<Form.Item },
noStyle ]}
shouldUpdate={(prevValues, curValues) =>
prevValues.area !== curValues.area ||
prevValues.sights !== curValues.sights
}
> >
{() => ( {(specsInfoFields, { add: specsAdd, remove: specsRemove }) => (
<>
{specsInfoFields.map(specsInfofield => (
<Space key={specsInfofield.key} align="baseline">
<Form.Item <Form.Item
{...field} {...specsInfofield}
// label="Sight" name={[specsInfofield.name, 'specName']}
name={[field.name, 'sight']}
rules={[ rules={[
{ {
required: true, required: true,
message: 'Missing sight', message: '请输入加价名称',
}, },
]} ]}
> >
<Input <Input style={{ width: '200px' }} placeholder="加价名称" />
style={{ width: '200px' }}
placeholder="加价名称"
/>
</Form.Item>
)}
</Form.Item> </Form.Item>
<Form.Item <Form.Item
{...field} {...specsInfofield}
// label="Price" name={[specsInfofield.name, 'salePrice']}
// name={[field.name, 'price']}
rules={[ rules={[
{ {
required: true, required: true,
message: 'Missing price', message: '请输入加价金额(元)',
}, },
]} ]}
> >
...@@ -692,14 +725,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -692,14 +725,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
/> />
</Form.Item> </Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} /> <MinusCircleOutlined
onClick={() => specsRemove(specsInfofield.name)}
/>
</Space> </Space>
))} ))}
<Form.Item> <Form.Item>
<Button <Button
type="dashed" type="dashed"
onClick={() => add()} onClick={() => specsAdd()}
block block
style={{ width: '400px' }} style={{ width: '400px' }}
icon={<PlusOutlined />} icon={<PlusOutlined />}
...@@ -711,11 +745,10 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -711,11 +745,10 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
)} )}
</Form.List> </Form.List>
</Form.Item> </Form.Item>
</Form.Item>
))} ))}
<Form.Item> <Form.Item>
<Button <Button
type="dashed" type="primary"
onClick={() => add()} onClick={() => add()}
style={{ width: '400px' }} style={{ width: '400px' }}
icon={<PlusOutlined />} icon={<PlusOutlined />}
...@@ -727,7 +760,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -727,7 +760,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
)} )}
</Form.List> </Form.List>
</Form.Item> </Form.Item>
</Form.Item>
<Form.Item <Form.Item
name="receptionVolume" name="receptionVolume"
label="多规格库存" label="多规格库存"
...@@ -744,6 +776,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -744,6 +776,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
统一设置置库存 统一设置置库存
</Button> </Button>
{[1, 2, 3].map(item => (
<div className={styles.specsBetween}>
<Form.Item label="多规格1"> <Form.Item label="多规格1">
<div <div
className={styles.specRepertory} className={styles.specRepertory}
...@@ -751,9 +785,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -751,9 +785,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
showAddRepertoryModal(true); showAddRepertoryModal(true);
}} }}
> >
去设置 设置库存
</div> </div>
</Form.Item> </Form.Item>
</div>
))}
</Form.Item> </Form.Item>
</> </>
)} )}
......
...@@ -80,7 +80,7 @@ const ServiceGoods = options => { ...@@ -80,7 +80,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); console.log('e======', e, !isEdit, visibleCacheEdit);
if (!isEdit) { if (!isEdit) {
if (visibleCacheEdit) { if (visibleCacheEdit) {
setVisibleCacheEdit(false); setVisibleCacheEdit(false);
...@@ -540,9 +540,11 @@ const ServiceGoods = options => { ...@@ -540,9 +540,11 @@ const ServiceGoods = options => {
<> <>
<FormTakeaway <FormTakeaway
ref={takeawayRef} ref={takeawayRef}
editData={editData.serviceItem} editData={editData.takeawayItem}
infoMation={editData.infoMation}
supplierIdList={supplierIdList} supplierIdList={supplierIdList}
onValuesChange={onValuesChange} onValuesChange={onValuesChange}
/> />
</> </>
)} )}
......
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