Commit e61c50de authored by baxibaba's avatar baxibaba

feat: 更新显示框

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