Commit cdf53e53 authored by baxibaba's avatar baxibaba

feat: 更新外卖商品

parent 8d5d77d7
......@@ -36,7 +36,7 @@ import AddSellTimeModal from './AddSellTimeModal';
import styles from '../common.less';
import AddRepertoryModal from './AddRepertoryModal';
import AddMultiSpecModal from './AddMultiSpecModal';
import { apiTagList, apiUnits, apiGetShopDetail } from '../service';
import { apiTagList, apiUnits } from '../service';
import { localAutoSaveKey } from '../utils';
import localStorage from '@/utils/localStorage';
......@@ -51,7 +51,7 @@ const createInitValues = () => ({
const format = 'HH:mm';
const { RangePicker } = DatePicker;
const TakeawayGoodsInfo = forwardRef((props, ref) => {
const { editData, infoMation } = props;
const { editData, infoMation, takeAway } = props;
const [form] = Form.useForm();
const [initValue, setInitValue] = useState(createInitValues());
const customer = useContext(ServiceContext);
......@@ -63,7 +63,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const [saleDates, setSaleDates] = useState({
saleDates: [],
saleTimes: [],
// saleTimes: [[moment('22-02', 'HH:mm'), moment('23-02', 'HH:mm')]],
}); // 可售日期
const [timeType, setTimeType] = useState(0);
const [repertoryType, setRepertoryType] = useState('1');
......@@ -178,7 +177,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
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?.slice(item.unit.length - 1)?.toString();
}
if (item && !item.specGroupName) {
item.specGroupName = '份量';
......@@ -321,16 +320,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
tempMultiSpu.push(...temp);
setTempMultiSpu(tempMultiSpu);
setMultiSpu(temp);
console.log('33333========>', multiSpu, tempMultiSpu);
// if (intactData?.items.length) {
// intactData.items[+idx].serviceItem.productStock = productStock;
// intactData.items[+idx].serviceItem.autoStock = autoStock;
// intactData.items[+idx].serviceItem.maxStock = maxStock;
// console.log('index===2222', +idx, intactData);
// const temp = { ...intactData };
// setIntactData(temp);
// }
}
if (type === 'all') {
if (intactData?.items.length) {
......@@ -344,18 +333,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
setIntactData(temp);
}
}
return false;
};
const querGetShopDetail = async () => {
let params = {
id: '638899799727110',
shopId: 15,
};
const result = await apiGetShopDetail(params);
console.log('result', result);
};
const fileterBrandOptions = (input, options) => options.children.includes(input);
const filterCategoryOptions = (inputValue, path) =>
path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
......@@ -377,13 +356,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
detailImageList: imgList,
});
};
const radioChangeEvent = key => {
const value = form.getFieldValue(key);
setInitValue({
...initValue,
[key]: value,
});
};
// 自定义菜单下拉
const dropdownRender = menus => (
<div>
......@@ -409,7 +381,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
// 切换库存
const onChangeRepertory = e => {
setRepertoryType(`${e.target.value}`);
console.log("e,===",e);
console.log('e,===', e);
};
// 勾选库存设置
const onChangeSetRepertory = e => {
......@@ -473,8 +445,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const res = await apiUnits();
setUnitsList(res.data || []);
}
querGetShopDetail();
setTempMultiSpu([])
setTempMultiSpu([]);
return false;
};
useEffect(() => {
......@@ -556,32 +528,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item>
<Form.Item label="售卖时段">
<Form.List
name="saleTimes"
initialValue={[[]]}
// rules={[
// {
// validator: async (_, times) => {
// if (!times || times.length < 2) {
// return Promise.reject(new Error('At least 2 passengers'));
// }
// },
// },
// ]}
>
<Form.List name="saleTimes" initialValue={[[]]}>
{(fields, { add, remove }) => (
<>
{fields.map((field, index) => (
<Form.Item
// {...(index === 0 ? formItemLayout : formItemLayoutWithOutLabel)}
required={false}
key={field.key}
className={styles.deal}
>
<Form.Item required={false} key={field.key} className={styles.deal}>
<Form.Item
className={styles.deal}
{...field}
// validateTrigger={['onChange', 'onBlur']}
rules={[
{
required: true,
......@@ -636,11 +590,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item>
</>
)}
<Form.Item
name="label"
label="商品标签"
// rules={[{ type: 'array', required: true, message: '请输入售卖时间!' }]}
>
<Form.Item name="label" label="商品标签">
<Select
mode="multiple"
allowClear
......@@ -666,16 +616,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Radio.Group>
</Form.Item>
<Title title="规格信息" />
{/* <Form.Item label="限购" name="limitPurchase" valuePropName="checked">
<Checkbox onChange={() => radioChangeEvent('limitPurchase')}>
<b style={{ marginLeft: 10 }}>启用限购</b>
<span style={{ marginLeft: 10 }} className="ant-form-text">
限制每人可购买数量
</span>
</Checkbox>
</Form.Item> */}
<Form.Item label="库存" name="stock">
<Radio.Group
options={ENUM_REPERTORY}
......@@ -685,7 +625,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
optionType="button"
/>
</Form.Item>
{/* 单规格 */}
{repertoryType === '1' && (
<>
<Form.Item label="份量" className={styles.required}>
......@@ -791,41 +731,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</div>
</>
)}
{/* 多规格 */}
{repertoryType === '2' && (
<>
<Form.Item>
<div>份量(如大小/小份、微辣/特辣等)</div>
{/* <Form.List name="deal">
{(dealFields, { add, remove }) => (
<>
{dealFields.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="请输入名称"
style={{
width: '60%',
}}
/>
</Form.Item>
{dealFields.length > 1 ? (
<MinusCircleOutlined
className="dynamic-delete-button"
onClick={() => remove(field.name)}
/>
) : null} */}
<Form.List name="weight" initialValue={[{}]}>
{(weightFields, { add: weightAdd, remove: weightRemove }) => (
<>
......@@ -923,24 +833,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</>
)}
</Form.List>
{/* </Form.Item>
))} */}
{/* <Form.Item>
<Button
type="primary"
onClick={() => add()}
style={{
width: '400px',
}}
icon={<PlusOutlined />}
>
添加份量
</Button>
</Form.Item> */}
{/* </>
)}
</Form.List> */}
</Form.Item>
{takeawayData?.takeawayItem?.weight?.length > 0 && (
<>
......
......@@ -22,7 +22,7 @@ import {
getByProductType,
apiCreateDraft,
apiEditDraft,
apiAddTakeawayProducts,
apiGetShopDetail,
} from './service';
import { isUrl, filterSendData, clearCurrent, onAutoSaveValue, localAutoSaveKey } from './utils';
import { ServiceContext } from './context';
......@@ -35,12 +35,18 @@ import styles from './common.less';
* @returns ReactDOM
*/
const ServiceGoods = options => {
const { SourceData, categoryList, virtualCategoryList, specListData, permissions } = options;
const {
SourceData,
categoryList,
virtualCategoryList,
specListData,
permissions,
takeAway,
} = options;
const canAddService = permissions[GOOD_MANAGE.ADD_SERVICE_GOODS];
const canAddNormal = permissions[GOOD_MANAGE.ADD_NORMAL_GOODS];
// const canTakeawayService = permissions[GOOD_MANAGE.ADD_TAKEAWAY_GOODS];
// const canTakeawayService = true
const basicRef = useRef(null);
const stockRef = useRef(null);
const settingRef = useRef(null);
......@@ -111,10 +117,21 @@ const ServiceGoods = options => {
},
!0,
);
if (stockRef.current) {
stockRef.current.onFinish();
}
}, 1000);
};
// 查询外卖商品详情
const querGetShopDetail = async params => {
const { spuId, shopId } = params;
const temp = {
id: spuId,
shopId,
};
const { data } = await apiGetShopDetail(temp);
console.log(data, '=====外卖结果');
};
const onResetData = refresh => {
setPageId(null);
setIsEdit(false);
......@@ -195,7 +212,6 @@ const ServiceGoods = options => {
});
}
};
// 保存商品
const submitEvent = async () => {
const checkPromiseList = clearCurrent(checkFormList).map(({ current }) => current.onCheck());
......@@ -209,12 +225,10 @@ const ServiceGoods = options => {
return origin;
}, {});
// 外卖商品创建
if (+productType === 5) {
console.log('parmas', params);
const res = await sendMerchantProductHttpRequest(params?.takeawayItem?.intactData);
return false;
}
// if (+productType === 5) {
// console.log('parmas', params);
// const res = await sendMerchantProductHttpRequest(params?.takeawayItem?.intactData);
// }
const sendData = filterSendData(productType, params);
if (isEdit) {
sendData.id = pageId;
......@@ -302,6 +316,12 @@ const ServiceGoods = options => {
// 默认生成一条规格数据
stockRef.current.onFinish();
}
console.log('takeAway', takeAway);
if (takeAway && takeAway.spuId) {
productChange({ type: 5 });
querGetShopDetail(takeAway);
setIsEdit(true);
}
setPageLoading(false);
})();
}, [SourceData]);
......@@ -411,7 +431,6 @@ const ServiceGoods = options => {
},
});
};
console.log('productType', productType);
const providerValue = {
pageId,
isEdit,
......@@ -538,7 +557,8 @@ const ServiceGoods = options => {
<>
<FormTakeaway
ref={takeawayRef}
editData={editData.takeawayItem}
takeAway={takeAway}
editData={editData.takeaway}
infoMation={editData.infoMation}
supplierIdList={supplierIdList}
onValuesChange={onValuesChange}
......
......@@ -109,7 +109,8 @@ const filterItems = (type, props) => {
};
export const filterSendData = (type, params) => {
const { infoMation, infoImageData, attributeApplyList } = params;
// takeawayItem 外卖商品
const { infoMation, infoImageData, attributeApplyList, takeawayItem } = params;
const items = filterItems(type, params);
const commonImageList = type === 4 ? [] : infoImageData.commonImageList;
const obj = {
......@@ -128,6 +129,10 @@ export const filterSendData = (type, params) => {
if (attributeApplyList && attributeApplyList.attributeApplyList) {
obj.attributeApplyList = attributeApplyList.attributeApplyList;
}
// 外卖商品
if (type === 5) {
return takeawayItem?.intactData;
}
return obj;
};
......
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