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: 10px 0;
margin-bottom: 8px; }
} .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,6 +538,150 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -481,6 +538,150 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
className="dynamic-delete-button" className="dynamic-delete-button"
onClick={() => remove(field.name)} onClick={() => remove(field.name)}
/> />
) : null} */}
<Form.List name="weight">
{(weightFields, { add: weightAdd, remove: weightRemove }) => (
<>
{weightFields.map(weightField => (
<Space key={weightField.key} align="baseline" className={styles.conBg}>
<Form.Item
{...weightField}
name={[weightField.name, 'specName']}
rules={[
{
required: true,
message: '请输入名称',
},
]}
>
<Input style={{ width: '200px' }} placeholder="名称" />
</Form.Item>
<Form.Item
{...weightField}
name={[weightField.name, 'unit']}
rules={[
{
required: true,
message: '份量',
},
]}
>
<Input style={{ width: '200px' }} placeholder="约 份量(数字)" />
</Form.Item>
<span className="ant-form-text"></span>
<Form.Item
{...weightField}
name={[weightField.name, 'quantity']}
rules={[
{
type: 'array',
required: true,
message: '请选择单位',
},
]}
>
<Cascader
placeholder="请选择单位"
disabled={customer.isEdit && customer.isNormal}
showSearch={{ filter: filterCategoryOptions }}
fieldNames={{
label: 'name',
value: 'id',
children: 'children',
}}
onChange={props.onCategoryChange}
options={unitsList}
/>
</Form.Item>
<Form.Item
{...weightField}
name={[weightField.name, 'salePrice']}
rules={[
{
required: true,
message: '销售价',
},
]}
>
<Input style={{ width: '200px' }} placeholder="销售价(元)" />
</Form.Item>
<Form.Item
{...weightField}
name={[weightField.name, 'activityPrice']}
rules={[
{
required: true,
message: '活动价',
},
]}
>
<Input style={{ width: '200px' }} placeholder="活动价(元)" />
</Form.Item>
<MinusCircleOutlined onClick={() => weightRemove(weightField.name)} />
</Space>
))}
<Form.Item>
<Button
type="primary"
onClick={() => weightAdd()}
block
style={{ width: '400px' }}
icon={<PlusOutlined />}
>
新增份量
</Button>
</Form.Item>
</>
)}
</Form.List>
{/* </Form.Item>
))} */}
{/* <Form.Item>
<Button
type="primary"
onClick={() => add()}
style={{
width: '400px',
}}
icon={<PlusOutlined />}
>
添加份量
</Button>
</Form.Item> */}
{/* </>
)}
</Form.List> */}
</Form.Item>
<Form.Item>
<div>添加规格(如加料、甜度、辣度等)</div>
<Form.List name="specs">
{(specsFields, { add, remove }) => (
<>
{specsFields.map((field, index) => (
<Form.Item key={field.key} className={styles.conBg}>
<Form.Item
{...field}
validateTrigger={['onChange', 'onBlur']}
name={[field.name, 'specGroupName']}
rules={[
{
required: true,
whitespace: true,
message: '请输入规格名称',
},
]}
noStyle
>
<Input placeholder="规格名称" className={styles.nameWidth} />
</Form.Item>
{specsFields.length > 1 ? (
<MinusCircleOutlined
className="dynamic-delete-button"
onClick={() => remove(field.name)}
/>
) : null} ) : null}
<Form.List <Form.List
{...field} {...field}
...@@ -488,98 +689,51 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -488,98 +689,51 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
initialValue={[ initialValue={[
{ {
specName: '', specName: '',
salePrice: '',
}, },
]} ]}
> >
{(dealInfoFields, { add: dealAdd, remove: dealRemove }) => ( {(specsInfoFields, { add: specsAdd, remove: specsRemove }) => (
<> <>
{dealInfoFields.map(dealInfoField => ( {specsInfoFields.map(specsInfofield => (
<Space key={dealInfoField.key} align="baseline"> <Space key={specsInfofield.key} align="baseline">
<Form.Item
{...dealInfoField}
name={[dealInfoField.name, 'specName']}
rules={[
{
required: true,
message: '请输入名称',
},
]}
>
<Input style={{ width: '200px' }} placeholder="名称" />
</Form.Item>
<Form.Item <Form.Item
{...dealInfoField} {...specsInfofield}
name={[dealInfoField.name, 'quantity']} name={[specsInfofield.name, 'specName']}
rules={[ rules={[
{ {
type: 'array',
required: true, required: true,
message: '选择单位', message: '输入加价名称',
}, },
]} ]}
> >
<Cascader <Input style={{ width: '200px' }} placeholder="加价名称" />
placeholder="请选择单位"
disabled={customer.isEdit && customer.isNormal}
showSearch={{ filter: filterCategoryOptions }}
fieldNames={{
label: 'name',
value: 'id',
children: 'children',
}}
onChange={props.onCategoryChange}
options={unitsList}
/>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
{...dealInfoField} {...specsInfofield}
name={[dealInfoField.name, 'unit']} name={[specsInfofield.name, 'salePrice']}
rules={[ rules={[
{ {
required: true, required: true,
message: '份量', message: '请输入加价金额(元)',
}, },
]} ]}
> >
<Input <InputNumber
style={{ width: '200px' }} style={{ width: '200px' }}
placeholder="约 份量(数字)" placeholder="加价名称金额(元)"
/> />
</Form.Item> </Form.Item>
<Form.Item
{...dealInfoField}
name={[dealInfoField.name, 'salePrice']}
rules={[
{
required: true,
message: '销售价',
},
]}
>
<Input style={{ width: '200px' }} placeholder="销售价(元)" />
</Form.Item>
<Form.Item
{...dealInfoField}
name={[dealInfoField.name, 'activityPrice']}
rules={[
{
required: true,
message: '活动价',
},
]}
>
<Input style={{ width: '200px' }} placeholder="活动价(元)" />
</Form.Item>
<MinusCircleOutlined <MinusCircleOutlined
onClick={() => dealRemove(dealInfoField.name)} onClick={() => specsRemove(specsInfofield.name)}
/> />
</Space> </Space>
))} ))}
<Form.Item> <Form.Item>
<Button <Button
type="dashed" type="dashed"
onClick={() => dealAdd()} onClick={() => specsAdd()}
block block
style={{ width: '400px' }} style={{ width: '400px' }}
icon={<PlusOutlined />} icon={<PlusOutlined />}
...@@ -592,142 +746,20 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -592,142 +746,20 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</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',
}}
icon={<PlusOutlined />} icon={<PlusOutlined />}
> >
添加份量 新增规格
</Button> </Button>
</Form.Item> </Form.Item>
</> </>
)} )}
</Form.List> </Form.List>
</Form.Item> </Form.Item>
<Form.Item>
<div>添加规格(如加料、甜度、辣度等)</div>
<Form.Item>
<Form.List name="specs">
{(specsFields, { add, remove }) => (
<>
{specsFields.map((field, index) => (
<Form.Item
// {...(index === 0 ? formItemLayout : formItemLayoutWithOutLabel)}
// label={index === 0 ? 'Passengers' : ''}
required={false}
key={field.key}
>
<Form.Item
{...field}
validateTrigger={['onChange', 'onBlur']}
className={styles.deal}
style={{ marginBottom: '8px' }}
rules={[
{
required: true,
whitespace: true,
message: '请输入规格名称',
},
]}
>
<Input placeholder="规格名称" className={styles.nameWidth} />
{specsFields.length > 1 ? (
<MinusCircleOutlined
className="dynamic-delete-button"
onClick={() => remove(field.name)}
/>
) : null}
</Form.Item>
<Form.Item>
<Form.List name="sights">
{(sightsFields, { add, remove }) => (
<>
{sightsFields.map(field => (
<Space key={field.key} align="baseline">
<Form.Item
noStyle
shouldUpdate={(prevValues, curValues) =>
prevValues.area !== curValues.area ||
prevValues.sights !== curValues.sights
}
>
{() => (
<Form.Item
{...field}
// label="Sight"
name={[field.name, 'sight']}
rules={[
{
required: true,
message: 'Missing sight',
},
]}
>
<Input
style={{ width: '200px' }}
placeholder="加价名称"
/>
</Form.Item>
)}
</Form.Item>
<Form.Item
{...field}
// label="Price"
// name={[field.name, 'price']}
rules={[
{
required: true,
message: 'Missing price',
},
]}
>
<InputNumber
style={{ width: '200px' }}
placeholder="加价名称金额(元)"
/>
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</Space>
))}
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
block
style={{ width: '400px' }}
icon={<PlusOutlined />}
>
新增加价
</Button>
</Form.Item>
</>
)}
</Form.List>
</Form.Item>
</Form.Item>
))}
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
style={{ width: '400px' }}
icon={<PlusOutlined />}
>
新增规格
</Button>
</Form.Item>
</>
)}
</Form.List>
</Form.Item>
</Form.Item>
<Form.Item <Form.Item
name="receptionVolume" name="receptionVolume"
label="多规格库存" label="多规格库存"
...@@ -744,16 +776,20 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -744,16 +776,20 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
统一设置置库存 统一设置置库存
</Button> </Button>
<Form.Item label="多规格1"> {[1, 2, 3].map(item => (
<div <div className={styles.specsBetween}>
className={styles.specRepertory} <Form.Item label="多规格1">
onClick={() => { <div
showAddRepertoryModal(true); className={styles.specRepertory}
}} onClick={() => {
> showAddRepertoryModal(true);
去设置 }}
>
设置库存
</div>
</Form.Item>
</div> </div>
</Form.Item> ))}
</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