Commit e95e3d78 authored by beisir's avatar beisir

fix: TS

parent 8869885b
...@@ -295,8 +295,8 @@ class goodsManage extends Component { ...@@ -295,8 +295,8 @@ class goodsManage extends Component {
serviceVisbleChange = visble => { serviceVisbleChange = visble => {
this.setState({ this.setState({
serviceVisble: visble, serviceVisble: visble,
}) });
} };
render() { render() {
const { const {
...@@ -311,7 +311,9 @@ class goodsManage extends Component { ...@@ -311,7 +311,9 @@ class goodsManage extends Component {
<PageHeaderWrapper> <PageHeaderWrapper>
<Spin spinning={this.state.createloading}> <Spin spinning={this.state.createloading}>
<Card> <Card>
<Button type="primary" onClick={() => this.serviceVisbleChange(true)}>new 新增商品</Button> <Button type="primary" onClick={() => this.serviceVisbleChange(true)}>
new 新增商品
</Button>
<SearchForm <SearchForm
handleSearch={this.handleSearch} handleSearch={this.handleSearch}
onReset={this.onReset} onReset={this.onReset}
...@@ -408,7 +410,11 @@ class goodsManage extends Component { ...@@ -408,7 +410,11 @@ class goodsManage extends Component {
templateList={this.state.templateList} templateList={this.state.templateList}
/> />
{/* '894048258062' */} {/* '894048258062' */}
<ServiceGoods visible={this.state.serviceVisble} onChange={this.serviceVisbleChange} id={894048258062} /> <ServiceGoods
visible={this.state.serviceVisble}
onChange={this.serviceVisbleChange}
id={894048258062}
/>
</Spin> </Spin>
</PageHeaderWrapper> </PageHeaderWrapper>
); );
......
...@@ -10,10 +10,7 @@ const CreateSelectOption = optionList => ...@@ -10,10 +10,7 @@ const CreateSelectOption = optionList =>
</Select.Option> </Select.Option>
)); ));
const fileterBrandOptions = ( const fileterBrandOptions = (input, options) => options.children.includes(input);
input,
options,
) => options.children.includes(input);
const filterCategoryOptions = (inputValue, path) => const filterCategoryOptions = (inputValue, path) =>
path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1); path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
...@@ -102,13 +99,15 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -102,13 +99,15 @@ const FormInformationBasic = forwardRef((props, ref) => {
/> />
</Form.Item> </Form.Item>
{customer.isCard ? <Form.Item {customer.isCard ? (
<Form.Item
name="description" name="description"
label="描述" label="描述"
rules={[{ required: true, message: '请输入描述!' }]} rules={[{ required: true, message: '请输入描述!' }]}
> >
<Input.TextArea showCount maxLength={100} placeholder="请输入描述!" /> <Input.TextArea showCount maxLength={100} placeholder="请输入描述!" />
</Form.Item> : null} </Form.Item>
) : null}
</Form> </Form>
); );
}); });
......
import { ConsoleSqlOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import { ConsoleSqlOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Form, Input, Select, Space, Modal, InputNumber, notification } from 'antd'; import { Button, Form, Input, Select, Space, Modal, InputNumber, notification } from 'antd';
import React, { useState, forwardRef, useImperativeHandle, useRef, useEffect, useContext } from 'react'; import React, {
useState,
forwardRef,
useImperativeHandle,
useRef,
useEffect,
useContext,
} from 'react';
import { formItemLayout, StaticColumns } from '../config'; import { formItemLayout, StaticColumns } from '../config';
import EditFormTable from './EditFormTable'; import EditFormTable from './EditFormTable';
import { createProductData, cleanArray } from '../utils'; import { createProductData, cleanArray } from '../utils';
...@@ -40,7 +47,7 @@ const SpecificationTemplate = (props, _) => { ...@@ -40,7 +47,7 @@ const SpecificationTemplate = (props, _) => {
if (event.target.value) { if (event.target.value) {
onChange(); onChange();
} }
} };
const bundlePlusAddSpecEvent = addCallback => { const bundlePlusAddSpecEvent = addCallback => {
console.log(name); console.log(name);
...@@ -57,9 +64,9 @@ const SpecificationTemplate = (props, _) => { ...@@ -57,9 +64,9 @@ const SpecificationTemplate = (props, _) => {
}; };
const bundlePlusRemoveSpecEvent = (removeCallback, fieldName) => { const bundlePlusRemoveSpecEvent = (removeCallback, fieldName) => {
removeCallback(fieldName) removeCallback(fieldName);
onChange(); onChange();
} };
return ( return (
<> <>
...@@ -108,7 +115,9 @@ const SpecificationTemplate = (props, _) => { ...@@ -108,7 +115,9 @@ const SpecificationTemplate = (props, _) => {
/> />
</Form.Item> </Form.Item>
{!(specDataList[index] && specDataList[index].id) && ( {!(specDataList[index] && specDataList[index].id) && (
<MinusCircleOutlined onClick={() => bundlePlusRemoveSpecEvent(remove, field.name)} /> <MinusCircleOutlined
onClick={() => bundlePlusRemoveSpecEvent(remove, field.name)}
/>
)} )}
</Space> </Space>
)} )}
...@@ -139,7 +148,6 @@ const originItems = { ...@@ -139,7 +148,6 @@ const originItems = {
secondDuplicate: [], secondDuplicate: [],
}; };
// 编辑回显示时只获取用到的数据 // 编辑回显示时只获取用到的数据
const filterItem = skuItem => { const filterItem = skuItem => {
const { serviceItem, ...argsItem } = skuItem; const { serviceItem, ...argsItem } = skuItem;
...@@ -171,18 +179,26 @@ const CreateBatchFormItems = ({ batchChange, editRef, defaultColumns }) => { ...@@ -171,18 +179,26 @@ const CreateBatchFormItems = ({ batchChange, editRef, defaultColumns }) => {
noStyle noStyle
key={item.dataIndex} key={item.dataIndex}
name={['batchItem', item.dataIndex]} name={['batchItem', item.dataIndex]}
initialValue={null}> initialValue={null}
>
<InputNumber placeholder={item.title} /> <InputNumber placeholder={item.title} />
</Form.Item> </Form.Item>
)); ));
return <> return (
{formItems.length ? <Space style={{ marginBottom: 20 }}> <>
{formItems.concat(<Button key="batch" type="primary" onClick={batchChange}>批量设置</Button>)} {formItems.length ? (
</Space> : null } <Space style={{ marginBottom: 20 }}>
</>; {formItems.concat(
<Button key="batch" type="primary" onClick={batchChange}>
批量设置
</Button>,
)}
</Space>
) : null}
</>
);
}; };
const FormPriceOrStock = forwardRef((props, ref) => { const FormPriceOrStock = forwardRef((props, ref) => {
const { specList, editData, onSpecChange } = props; const { specList, editData, onSpecChange } = props;
const editRef = useRef(null); const editRef = useRef(null);
...@@ -226,12 +242,9 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -226,12 +242,9 @@ const FormPriceOrStock = forwardRef((props, ref) => {
}); });
} }
const dynamicColumns = [ const dynamicColumns = [...columsData, ...StaticColumns];
...columsData,
...StaticColumns,
];
setDefaultColumns(dynamicColumns); setDefaultColumns(dynamicColumns);
} };
const onFinish = async () => { const onFinish = async () => {
try { try {
...@@ -255,11 +268,10 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -255,11 +268,10 @@ const FormPriceOrStock = forwardRef((props, ref) => {
const firstSpecValue = form.getFieldValue('firstSpecValue'); const firstSpecValue = form.getFieldValue('firstSpecValue');
const firstSpecValueList = cleanArray(firstSpecValue).map(item => item.firstSpecValue); const firstSpecValueList = cleanArray(firstSpecValue).map(item => item.firstSpecValue);
onSpecChange(firstSpecValueList); onSpecChange(firstSpecValueList);
} };
const batchChange = () => { const batchChange = () => {
const batchItem = form.getFieldValue('batchItem') const batchItem = form.getFieldValue('batchItem');
const batchItemKey = Object.keys(batchItem); const batchItemKey = Object.keys(batchItem);
const resetObject = tableData.map((item, index) => { const resetObject = tableData.map((item, index) => {
console.log(item); console.log(item);
...@@ -273,8 +285,7 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -273,8 +285,7 @@ const FormPriceOrStock = forwardRef((props, ref) => {
console.log(resetObject); console.log(resetObject);
// editRef.current.form.setFieldsValue(resetObject); // editRef.current.form.setFieldsValue(resetObject);
// form.setFieldsValue(resetObject); // form.setFieldsValue(resetObject);
} };
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
onCheck, onCheck,
...@@ -303,7 +314,6 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -303,7 +314,6 @@ const FormPriceOrStock = forwardRef((props, ref) => {
} }
}, [customer.isEdit, editData]); }, [customer.isEdit, editData]);
return ( return (
<Form <Form
form={form} form={form}
......
...@@ -7,7 +7,6 @@ import { ServiceContext } from '../context'; ...@@ -7,7 +7,6 @@ import { ServiceContext } from '../context';
const { Option } = Select; const { Option } = Select;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const WeekCheckBox = () => const WeekCheckBox = () =>
WeeksList.map(item => ( WeeksList.map(item => (
<Checkbox key={item.value} value={item.value} style={{ lineHeight: '32px' }}> <Checkbox key={item.value} value={item.value} style={{ lineHeight: '32px' }}>
...@@ -100,7 +99,6 @@ const FormRuleSetting = forwardRef((props, ref) => { ...@@ -100,7 +99,6 @@ const FormRuleSetting = forwardRef((props, ref) => {
imageList, imageList,
commonImageList, commonImageList,
detailImageList, detailImageList,
}} }}
scrollToFirstError scrollToFirstError
> >
......
...@@ -13,7 +13,7 @@ const FormRuleVPictures = forwardRef((props, ref) => { ...@@ -13,7 +13,7 @@ const FormRuleVPictures = forwardRef((props, ref) => {
const customer = useContext(ServiceContext); const customer = useContext(ServiceContext);
useEffect(() => { useEffect(() => {
if (customer.isEdit) { if (customer.isEdit) {
console.log('==============>图片', editData) console.log('==============>图片', editData);
if (!Object.keys(editData).length) return; if (!Object.keys(editData).length) return;
setCommonImageList(editData.commonImageList); // 编辑状态下设置公共图 setCommonImageList(editData.commonImageList); // 编辑状态下设置公共图
setDetailImageList(editData.detailImageList); // 编辑状态下设置详情图 setDetailImageList(editData.detailImageList); // 编辑状态下设置详情图
...@@ -41,13 +41,12 @@ const FormRuleVPictures = forwardRef((props, ref) => { ...@@ -41,13 +41,12 @@ const FormRuleVPictures = forwardRef((props, ref) => {
return origin; return origin;
}, {}); }, {});
setImageList(newImageList); setImageList(newImageList);
}, [specKeyItem]) }, [specKeyItem]);
const onCheck = async () => { const onCheck = async () => {
try { try {
const values = await form.validateFields(); const values = await form.validateFields();
console.log(values) console.log(values);
return values; return values;
} catch (errorInfo) { } catch (errorInfo) {
return null; return null;
...@@ -67,7 +66,7 @@ const FormRuleVPictures = forwardRef((props, ref) => { ...@@ -67,7 +66,7 @@ const FormRuleVPictures = forwardRef((props, ref) => {
...imageList, ...imageList,
[key]: imgList, [key]: imgList,
}); });
} };
return ( return (
<> <>
<Form <Form
...@@ -98,14 +97,19 @@ const FormRuleVPictures = forwardRef((props, ref) => { ...@@ -98,14 +97,19 @@ const FormRuleVPictures = forwardRef((props, ref) => {
/> />
</Form.Item> </Form.Item>
{Object.keys(imageList).map(key => {Object.keys(imageList).map(key => (
<Form.Item <Form.Item
key={key} key={key}
label={`商品图片(${key})`} label={`商品图片(${key})`}
name={['imageList', key]} name={['imageList', key]}
extra={`建议尺寸: ##宽##高 (${imageList[key].length} / 11) `} extra={`建议尺寸: ##宽##高 (${imageList[key].length} / 11) `}
rules={[ rules={[
{ required: true, type: 'array', message: '请输入温馨提示', validateTrigger: 'submit' }, {
required: true,
type: 'array',
message: '请输入温馨提示',
validateTrigger: 'submit',
},
]} ]}
> >
<UploadImage <UploadImage
...@@ -114,7 +118,8 @@ const FormRuleVPictures = forwardRef((props, ref) => { ...@@ -114,7 +118,8 @@ const FormRuleVPictures = forwardRef((props, ref) => {
pictures={imageList[key]} pictures={imageList[key]}
setPictureList={list => onPictureSuccessEvent(list, key)} setPictureList={list => onPictureSuccessEvent(list, key)}
/> />
</Form.Item>)} </Form.Item>
))}
<Form.Item <Form.Item
label="商品详情图" label="商品详情图"
name="detailImageList" name="detailImageList"
......
...@@ -9,7 +9,7 @@ export const TaskTypeSelect = props => { ...@@ -9,7 +9,7 @@ export const TaskTypeSelect = props => {
if (!customer.isEdit) { if (!customer.isEdit) {
props.onChange(task); props.onChange(task);
} }
} };
return ( return (
<div className={commonStyle.prodcutContent}> <div className={commonStyle.prodcutContent}>
...@@ -28,4 +28,4 @@ export const TaskTypeSelect = props => { ...@@ -28,4 +28,4 @@ export const TaskTypeSelect = props => {
})} })}
</div> </div>
); );
} };
...@@ -46,14 +46,14 @@ const UploadImage = props => { ...@@ -46,14 +46,14 @@ const UploadImage = props => {
})); }));
fileListRef.current = [...newPictures]; fileListRef.current = [...newPictures];
setFileList([...newPictures]); setFileList([...newPictures]);
}, [pictures]); }, [pictures]);
const handleCancel = () => setPreviewVisible(false); const handleCancel = () => setPreviewVisible(false);
const handlePreview = async file => { const handlePreview = async file => {
setPreviewImage(file.url); setPreviewImage(file.url);
setPreviewVisible(true); setPreviewVisible(true);
setPreviewTitle(file.name || (file.url).substring(file.url.lastIndexOf('/') + 1)); setPreviewTitle(file.name || file.url.substring(file.url.lastIndexOf('/') + 1));
}; };
const bundleChange = imgFile => { const bundleChange = imgFile => {
...@@ -65,7 +65,7 @@ const UploadImage = props => { ...@@ -65,7 +65,7 @@ const UploadImage = props => {
const handleRemove = file => { const handleRemove = file => {
const freshFiles = fileList?.filter(ele => ele.uid !== file.uid); const freshFiles = fileList?.filter(ele => ele.uid !== file.uid);
bundleChange(freshFiles); bundleChange(freshFiles);
} };
// const saveFiles = (file, ret) => { // const saveFiles = (file, ret) => {
// return new Promise((resolve) => { // return new Promise((resolve) => {
// const reader = new FileReader(); // const reader = new FileReader();
...@@ -105,7 +105,8 @@ const UploadImage = props => { ...@@ -105,7 +105,8 @@ const UploadImage = props => {
// } // }
// }; // };
const checkFile = file => new Promise(resolve => { const checkFile = file =>
new Promise(resolve => {
const curType = file.name.substr(file.name.lastIndexOf('.') + 1).toLowerCase(); const curType = file.name.substr(file.name.lastIndexOf('.') + 1).toLowerCase();
const fileType = ['jpg', 'jpeg', 'png']; const fileType = ['jpg', 'jpeg', 'png'];
if (!fileType.includes(curType)) { if (!fileType.includes(curType)) {
...@@ -123,12 +124,14 @@ const UploadImage = props => { ...@@ -123,12 +124,14 @@ const UploadImage = props => {
return resolve(null); return resolve(null);
} }
return resolve(file); return resolve(file);
}) });
const imageLoading = (file, ret) => new Promise(resolve => { const imageLoading = (file, ret) =>
new Promise(resolve => {
const reader = new FileReader(); const reader = new FileReader();
// 监听图片转换完成 // 监听图片转换完成
reader.addEventListener('load', reader.addEventListener(
'load',
() => { () => {
const temFile = { uid: file.uid, status: 'done', name: file.name, url: ret }; const temFile = { uid: file.uid, status: 'done', name: file.name, url: ret };
resolve(temFile); resolve(temFile);
...@@ -136,12 +139,13 @@ const UploadImage = props => { ...@@ -136,12 +139,13 @@ const UploadImage = props => {
false, false,
); );
reader.readAsDataURL(file); reader.readAsDataURL(file);
}) });
const defaultBeforeUpload = lodash.debounce((file, fileArray) => const defaultBeforeUpload = lodash.debounce(
(file, fileArray) =>
// 文件显示 // 文件显示
new Promise(async () => { new Promise(async () => {
if ((fileListRef.current.length + fileArray.length) > limit) { if (fileListRef.current.length + fileArray.length > limit) {
Modal.warning({ Modal.warning({
maskClosable: true, maskClosable: true,
title: '超出上传个数', title: '超出上传个数',
...@@ -154,7 +158,9 @@ const UploadImage = props => { ...@@ -154,7 +158,9 @@ const UploadImage = props => {
if (checkFiles.length) { if (checkFiles.length) {
setUploadLoading(true); setUploadLoading(true);
const res = await merchantUpload(checkFiles); const res = await merchantUpload(checkFiles);
const proFiles = (res.data || []).map((urlItem, urlIndex) => imageLoading(checkFiles[urlIndex], urlItem)); const proFiles = (res.data || []).map((urlItem, urlIndex) =>
imageLoading(checkFiles[urlIndex], urlItem),
);
const imagList = await Promise.all(proFiles); const imagList = await Promise.all(proFiles);
const newFiles = [...fileListRef.current, ...imagList]; const newFiles = [...fileListRef.current, ...imagList];
bundleChange(newFiles); bundleChange(newFiles);
......
...@@ -41,22 +41,18 @@ const ServiceGoods = options => { ...@@ -41,22 +41,18 @@ const ServiceGoods = options => {
const [specKeyList, setSpecKeyList] = useState([]); // 记录一级规格key字段 const [specKeyList, setSpecKeyList] = useState([]); // 记录一级规格key字段
const changeCheckList = proType => { const changeCheckList = proType => {
const newBaseCheckList = proType === 3 ? [ const newBaseCheckList =
...baseCheckList, proType === 3 ? [...baseCheckList, settingRef, settleOtrRef] : baseCheckList;
settingRef,
settleOtrRef,
] : baseCheckList;
setCheckFormList(newBaseCheckList); setCheckFormList(newBaseCheckList);
} };
useEffect(() => { useEffect(() => {
const timer = setTimeout(() => { const timer = setTimeout(() => {
checkFormList.forEach(({ current }) => { checkFormList.forEach(({ current }) => {
current.reset() current.reset();
}); });
clearTimeout(timer); clearTimeout(timer);
}); });
}, [checkFormList]) }, [checkFormList]);
const productChange = task => { const productChange = task => {
setProductType(task.type); setProductType(task.type);
...@@ -117,24 +113,26 @@ const ServiceGoods = options => { ...@@ -117,24 +113,26 @@ const ServiceGoods = options => {
})(); })();
}, [options.visible, options.id]); }, [options.visible, options.id]);
const handleOk = () => { const handleOk = () => {};
}
const handleCancel = () => { const handleCancel = () => {
options.onChange(false); options.onChange(false);
} };
const onSpecCommonImgEvent = useCallback(keys => { const onSpecCommonImgEvent = useCallback(
keys => {
setSpecKeyList(keys); setSpecKeyList(keys);
}, [specKeyList]) },
[specKeyList],
);
return ( return (
<Modal visible={options.visible} onOk={handleOk} onCancel={handleCancel} width={1366}> <Modal visible={options.visible} onOk={handleOk} onCancel={handleCancel} width={1366}>
<Spin tip="正在加载..." spinning={pageLoading} delay={100}> <Spin tip="正在加载..." spinning={pageLoading} delay={100}>
<WrapperContainer> <WrapperContainer>
<ServiceContext.Provider value={{ pageId, isEdit, productType, isCard: productType === 3 }}> <ServiceContext.Provider
value={{ pageId, isEdit, productType, isCard: productType === 3 }}
>
<Title title="商品类型" /> <Title title="商品类型" />
<TaskTypeSelect productType={productType} onChange={productChange} /> <TaskTypeSelect productType={productType} onChange={productChange} />
...@@ -147,7 +145,12 @@ const ServiceGoods = options => { ...@@ -147,7 +145,12 @@ const ServiceGoods = options => {
/> />
<Title title="价格与库存" /> <Title title="价格与库存" />
<FormPriceOrStock ref={stockRef} specList={specList} onSpecChange={onSpecCommonImgEvent} editData={editData} /> <FormPriceOrStock
ref={stockRef}
specList={specList}
onSpecChange={onSpecCommonImgEvent}
editData={editData}
/>
<Title title="规则设置" /> <Title title="规则设置" />
{productType === 3 && <FormRuleSetting ref={settingRef} editData={editData} />} {productType === 3 && <FormRuleSetting ref={settingRef} editData={editData} />}
......
...@@ -37,6 +37,7 @@ export const merchantBrandList = () => ...@@ -37,6 +37,7 @@ export const merchantBrandList = () =>
}); });
// 获取规格列表 // 获取规格列表
export const merchantSpecList = () => request.post('/product/spec/api/merchant/list', { export const merchantSpecList = () =>
request.post('/product/spec/api/merchant/list', {
prefix: goodsApi, prefix: goodsApi,
}); });
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