Commit e61c50de authored by baxibaba's avatar baxibaba

feat: 更新显示框

parent f5fe20b0
...@@ -78,6 +78,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -78,6 +78,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const [tempWeight, setTempWeight] = useState([]); const [tempWeight, setTempWeight] = useState([]);
const [tempSpecs, setTempSpecs] = useState([]); const [tempSpecs, setTempSpecs] = useState([]);
const [weightUnits, setWeightUnits] = useState([]); const [weightUnits, setWeightUnits] = useState([]);
const [peopleUnits, setPeopleUnits] = useState([]);
// 自定义加入菜单 // 自定义加入菜单
const showModal = () => { const showModal = () => {
...@@ -198,6 +199,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -198,6 +199,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}); });
} }
const sepcx = specs.map(item => item.specs); const sepcx = specs.map(item => item.specs);
sepcx.map(item => {
item.unit = '';
});
// 生成 specs 规格sku // 生成 specs 规格sku
let tempSku = [[...weight], ...sepcx].reduce( let tempSku = [[...weight], ...sepcx].reduce(
(x, y) => { (x, y) => {
...@@ -230,18 +234,25 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -230,18 +234,25 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
item.salePrice = 0; item.salePrice = 0;
item.unique = item?.specs item.unique = item?.specs
.map(itm => { .map(itm => {
itm.unit = if (itm.unit) {
itm.unit && itm.unit =
(Array.isArray(itm?.unit) ? itm.unit.slice(itm.unit.length - 1)[0] : itm.unit); itm?.unit &&
(Array.isArray(itm?.unit) ? itm?.unit.slice(itm?.unit.length - 1)[0] : itm?.unit);
if (itm?.unit && peopleUnits.includes(itm.unit)) {
delete itm.quantity;
}
}
if (itm?.specName) { if (itm?.specName) {
return itm.specName; return itm.specName;
} }
}) })
.toString(); .toString();
}); });
console.log('multiSpu', multiSpu);
if (tempMultiSpu.length) { if (tempMultiSpu.length) {
multiSpu.forEach((item, index) => { multiSpu.forEach((item, index) => {
console.log('item===', item);
tempMultiSpu.forEach((itm, idx) => { tempMultiSpu.forEach((itm, idx) => {
if (item.unique === itm.unique) { if (item.unique === itm.unique) {
item.serviceItem = objectComparison(item.serviceItem, itm); item.serviceItem = objectComparison(item.serviceItem, itm);
...@@ -249,6 +260,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -249,6 +260,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}); });
}); });
} }
console.log(multiSpu, 'multiSpumultiSpu');
setMultiSpu(JSON.parse(JSON.stringify(multiSpu))); setMultiSpu(JSON.parse(JSON.stringify(multiSpu)));
} }
} }
...@@ -288,6 +301,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -288,6 +301,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const onChange = () => {}; const onChange = () => {};
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
console.log(values, 'values===');
props.onValuesChange({ takeawayItem: JSON.parse(JSON.stringify(values)) }); props.onValuesChange({ takeawayItem: JSON.parse(JSON.stringify(values)) });
const takeawayData = customer.isEdit const takeawayData = customer.isEdit
? { takeawayItem: Object.assign({}, editData, values) } ? { takeawayItem: Object.assign({}, editData, values) }
...@@ -452,10 +466,18 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -452,10 +466,18 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
if (!unitsList.length) { if (!unitsList.length) {
const res = await apiUnits(); const res = await apiUnits();
setUnitsList(res.data || []); setUnitsList(res.data || []);
let temp = res.data.filter(item => item.name === '准确重量单位'); let tempWeight = res.data.filter(item => item.name === '准确重量单位');
if (temp.length && temp[0]?.children) { let tempPeople = res.data.filter(item => item.name === '适用人数');
const tempWeightName = temp[0]?.children.map(item => item.name);
if (tempWeight.length && tempWeight[0]?.children) {
const tempWeightName = tempWeight[0]?.children.map(item => item.name);
sessionStorage.setItem('weightUnits', JSON.stringify(tempWeightName || [])); sessionStorage.setItem('weightUnits', JSON.stringify(tempWeightName || []));
setWeightUnits(tempWeightName);
}
if (tempPeople.length && tempPeople[0]?.children) {
const tempPeopleName = tempPeople[0]?.children.map(item => item.name);
sessionStorage.setItem('peopleUnits', JSON.stringify(tempPeopleName || []));
setPeopleUnits(tempPeopleName);
} }
} }
setTempMultiSpu([]); setTempMultiSpu([]);
...@@ -870,7 +892,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -870,7 +892,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
<Form.List name="weight" initialValue={[{}]}> <Form.List name="weight" initialValue={[{}]}>
{(weightFields, { add: weightAdd, remove: weightRemove }) => ( {(weightFields, { add: weightAdd, remove: weightRemove }) => (
<> <>
{weightFields.map(weightField => ( {weightFields.map((weightField, index) => (
<Space key={weightField.key} align="baseline" className={styles.conBg}> <Space key={weightField.key} align="baseline" className={styles.conBg}>
<Form.Item <Form.Item
{...weightField} {...weightField}
...@@ -884,25 +906,35 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -884,25 +906,35 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
<Input style={{ width: '200px' }} placeholder="名称" /> <Input style={{ width: '200px' }} placeholder="名称" />
</Form.Item> </Form.Item>
{weightUnits.includes(form.getFieldValue(['weight'])?.[index]?.unit) && (
<span className="ant-form-text"> 约</span>
)}
<Form.Item <Form.Item
style={{
display:
peopleUnits.includes(form.getFieldValue(['weight'])?.[index]?.unit) &&
'none',
}}
{...weightField} {...weightField}
name={[weightField.name, 'quantity']} name={[weightField.name, 'quantity']}
rules={[ rules={[
{ {
required: true, required: peopleUnits.includes(
form.getFieldValue(['weight'])?.[index]?.unit,
)
? false
: true,
message: '份量', message: '份量',
}, },
]} ]}
> >
<InputNumber <InputNumber
style={{ width: '200px' }} style={{ width: '120px' }}
max={999999999} max={999999999}
min={0} min={0}
placeholder="约 份量(数字)" placeholder="约 份量(数字)"
/> />
</Form.Item> </Form.Item>
<span className="ant-form-text"> 约</span>
<Form.Item <Form.Item
{...weightField} {...weightField}
name={[weightField.name, 'unit']} name={[weightField.name, 'unit']}
...@@ -941,7 +973,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -941,7 +973,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
max={999999999} max={999999999}
min={0} min={0}
precision={2} precision={2}
style={{ width: '200px' }} style={{ width: '120px' }}
placeholder="销售价(元)" placeholder="销售价(元)"
/> />
</Form.Item> </Form.Item>
...@@ -959,7 +991,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -959,7 +991,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
max={999999999} max={999999999}
min={0} min={0}
precision={2} precision={2}
style={{ width: '200px' }} style={{ width: '120px' }}
placeholder="活动价(元)" placeholder="活动价(元)"
/> />
</Form.Item> </Form.Item>
......
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