Commit a68f202a authored by 武广's avatar 武广

feat: 添加草稿编辑功能

parent 973f3c7c
const isProduction = process.env.NODE_ENV === 'production'; const isProduction = process.env.NODE_ENV === 'production';
const isPre = process.env.PRE_ENV === 'pre'; const isPre = process.env.PRE_ENV === 'pre';
const environment = 'xyqb'; const environment = 'sc';
const envAPi = { const envAPi = {
api: `https://security-${environment}.liangkebang.net`, //'https://security-xyqb.liangkebang.net', api: `https://security-${environment}.liangkebang.net`, //'https://security-xyqb.liangkebang.net',
kdspOpApi: `https://sc-merchant-api-${environment}.liangkebang.net`, kdspOpApi: `https://sc-merchant-api-${environment}.liangkebang.net`,
......
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { Modal, Table } from 'antd'; import { Modal, Table, message } from 'antd';
import { columns } from './staticdata'; import { columns } from './staticdata';
import { apiDraftList, apiDraftDetail, apiDeleteDraft } from '../service';
const DraftModal = props => { const DraftModal = props => {
const [pageInfo, setPageInfo] = useState({ const [pageInfo, setPageInfo] = useState({
current: 1, current: 1,
pageSize: 4, pageSize: 4,
total: 100,
}); });
const [total, setTotal] = useState(0);
const [dataSource, setdataSource] = useState([]); const [dataSource, setdataSource] = useState([]);
const onClose = () => props.onCancel();
const onEdit = async record => {
const res = await apiDraftDetail(record.id);
if (res && res.data) {
const data = JSON.parse(res.data.content);
data.id = record.id;
props.onToDetail(data);
onClose();
}
};
const getDraftList = async params => {
const res = await apiDraftList(params);
if (res && res.data && res.data.records) {
setdataSource(res.data.records);
setTotal(res.data.total);
}
};
const onRefresh = () => {
getDraftList({
pageSize: pageInfo.pageSize,
pageNo: pageInfo.current,
});
};
const onDel = record => {
Modal.confirm({
title: '确认提示',
content: '操作后不可更改,确认是否删除?',
onOk: async () => {
console.log('record :>> ', record);
await apiDeleteDraft(record.id);
message.success('删除成功!');
onRefresh();
},
});
};
const onChange = (current, pageSize) => { const onChange = (current, pageSize) => {
setPageInfo({ const json = {
current, current,
pageSize, pageSize,
}); };
setPageInfo(json);
json.pageNo = current;
getDraftList(json);
}; };
const onClose = () => props.onCancel();
const pagination = { const pagination = {
...pageInfo, ...pageInfo,
total,
showTotal: t => `共 ${t} 项数据`,
onChange, onChange,
pageSizeOptions: [4, 20, 50, 100],
showSizeChanger: !0,
onShowSizeChange: onChange, onShowSizeChange: onChange,
}; };
useEffect(() => {
if (props.visible) {
onRefresh();
}
}, [props.visible]);
const res = {
onDel,
onEdit,
};
return ( return (
<Modal <Modal
visible={props.visible} visible={props.visible}
...@@ -32,8 +88,14 @@ const DraftModal = props => { ...@@ -32,8 +88,14 @@ const DraftModal = props => {
onCancel={onClose} onCancel={onClose}
maskClosable={false} maskClosable={false}
width="1000px" width="1000px"
footer={[]}
> >
<Table columns={columns} pagination={pagination} dataSource={dataSource} /> <Table
columns={columns(res)}
pagination={pagination}
rowKey={record => record.id}
dataSource={dataSource}
/>
</Modal> </Modal>
); );
}; };
......
import React from 'react'; import React from 'react';
import { Button } from 'antd'; import { Button } from 'antd';
import styles from '../style.less';
export const columns = [ const productType = {
1: '普通商品',
2: '虚拟商品',
3: '电子卡卷',
4: '服务商品',
};
export const columns = ({ onDel, onEdit }) => [
{ {
title: '草稿ID', title: '草稿ID',
dataIndex: 'skuId', dataIndex: 'id',
width: 85, width: 85,
align: 'center', align: 'center',
}, },
{ {
title: '商品名称', title: '商品名称',
dataIndex: 'skuName', dataIndex: 'productName',
width: 125,
align: 'center', align: 'center',
render(text) {
return <div className={styles.draftName}>{text}</div>;
},
}, },
{ {
title: '所属类目', title: '所属类目',
dataIndex: 'skuId', dataIndex: 'leimu',
width: 125, width: 240,
align: 'center', align: 'center',
render(text, record) {
if (record.firstCategoryName) {
return `${record.firstCategoryName}>${record.secondCategoryName}>${record.thirdCategoryName}`;
}
return '-';
},
}, },
{ {
title: '商品类型', title: '商品类型',
dataIndex: 'skuId', dataIndex: 'productType',
width: 125, width: 100,
align: 'center', align: 'center',
render(text) {
return productType[text];
},
}, },
{ {
title: '创建时间', title: '创建时间',
dataIndex: 'skuId', dataIndex: 'createdAt',
width: 125, width: 120,
align: 'center', align: 'center',
}, },
{ {
title: '操作', title: '操作',
dataIndex: 'action', dataIndex: 'action',
width: 120, width: 130,
align: 'center', align: 'center',
render: () => ( render: (text, record) => (
<> <>
<Button key="edit" type="link" size="small"> <Button key="edit" type="link" size="small" onClick={() => onEdit(record)}>
修改 修改
</Button> </Button>
<Button key="viewP" type="link" size="small" onClick={() => {}}> <Button key="viewP" type="link" size="small" onClick={() => onDel(record)}>
删除 删除
</Button> </Button>
</> </>
......
...@@ -53,11 +53,12 @@ class goodsManage extends Component { ...@@ -53,11 +53,12 @@ class goodsManage extends Component {
stockSkuIds: [], stockSkuIds: [],
isType: '', isType: '',
serviceVisble: true, serviceVisble: false,
serviceData: {}, serviceData: {},
visibleAuditModal: false, visibleAuditModal: false,
auditRow: {}, // 查看审核信息使用 auditRow: {}, // 查看审核信息使用
isVisibleDraft: false, // 显示隐藏草稿箱 isVisibleDraft: false, // 显示隐藏草稿箱
isEditDraft: false, // 是否编辑草稿
}; };
currentLog = null; currentLog = null;
...@@ -308,6 +309,7 @@ class goodsManage extends Component { ...@@ -308,6 +309,7 @@ class goodsManage extends Component {
serviceData: SourceData, serviceData: SourceData,
serviceVisble: true, serviceVisble: true,
createloading: false, createloading: false,
isEditDraft: false,
}); });
} else { } else {
this.setState({ this.setState({
...@@ -319,9 +321,20 @@ class goodsManage extends Component { ...@@ -319,9 +321,20 @@ class goodsManage extends Component {
} }
}; };
// 编辑草稿
editDraft = data => {
this.setState({
serviceData: data,
serviceVisble: true,
isEditDraft: true,
});
};
// 显示新增商品弹窗
serviceVisbleClose = (flag, refresh) => { serviceVisbleClose = (flag, refresh) => {
this.setState({ this.setState({
serviceVisble: flag, serviceVisble: flag,
isEditDraft: false,
serviceData: {}, serviceData: {},
}); });
if (refresh) { if (refresh) {
...@@ -475,6 +488,7 @@ class goodsManage extends Component { ...@@ -475,6 +488,7 @@ class goodsManage extends Component {
virtualCategoryList={this.state.virtualTreeData} virtualCategoryList={this.state.virtualTreeData}
specListData={this.state.specListData} specListData={this.state.specListData}
permissions={permissions} permissions={permissions}
isDraft={this.state.isEditDraft}
/> />
)} )}
</Spin> </Spin>
...@@ -490,7 +504,11 @@ class goodsManage extends Component { ...@@ -490,7 +504,11 @@ class goodsManage extends Component {
/> />
)} )}
{this.state.isVisibleDraft && ( {this.state.isVisibleDraft && (
<DraftModal visible={this.state.isVisibleDraft} onCancel={this.openDraftModal} /> <DraftModal
visible={this.state.isVisibleDraft}
onCancel={this.openDraftModal}
onToDetail={this.editDraft}
/>
)} )}
</PageHeaderWrapper> </PageHeaderWrapper>
); );
......
...@@ -269,3 +269,23 @@ export const apiQueryLastAuditRecord = skuId => ...@@ -269,3 +269,23 @@ export const apiQueryLastAuditRecord = skuId =>
request.get(`/api/kdsp/sku/last/audit/record?skuId=${skuId}`, { request.get(`/api/kdsp/sku/last/audit/record?skuId=${skuId}`, {
prefix: goodsApi, prefix: goodsApi,
}); });
// 商品草稿详情
export const apiDraftDetail = draftId =>
request.get(`/api/merchants/drafts/detail?id=${draftId}`, {
prefix: goodsApi,
});
// 删除商品草稿
export const apiDeleteDraft = draftId =>
request.get(`/api/merchants/drafts/delete?id=${draftId}`, {
prefix: goodsApi,
});
// 商品草稿列表
export async function apiDraftList(data) {
return request.post('/api/merchants/drafts/list', {
prefix: goodsApi,
data,
});
}
...@@ -126,3 +126,7 @@ ...@@ -126,3 +126,7 @@
.attrboxMore { .attrboxMore {
max-height: max-content; max-height: max-content;
} }
.draftName {
text-align: left;
word-break: break-all;
}
...@@ -228,7 +228,6 @@ const CreateBatchFormItems = ({ specInitValue, batchChange, editRef, defaultColu ...@@ -228,7 +228,6 @@ const CreateBatchFormItems = ({ specInitValue, batchChange, editRef, defaultColu
}; };
const FormPriceOrStock = forwardRef((props, ref) => { const FormPriceOrStock = forwardRef((props, ref) => {
console.log('props :>> ', props);
const { specList, editData, skuList = [], onSpecChange } = props; const { specList, editData, skuList = [], onSpecChange } = props;
const editRef = useRef(null); const editRef = useRef(null);
......
...@@ -20,6 +20,7 @@ import { ...@@ -20,6 +20,7 @@ import {
merchantProductEdit, merchantProductEdit,
getByProductType, getByProductType,
apiCreateDraft, apiCreateDraft,
apiEditDraft,
} from './service'; } from './service';
import { isUrl, filterSendData, clearCurrent, onAutoSaveValue, localAutoSaveKey } from './utils'; import { isUrl, filterSendData, clearCurrent, onAutoSaveValue, localAutoSaveKey } from './utils';
import { ServiceContext } from './context'; import { ServiceContext } from './context';
...@@ -163,6 +164,7 @@ const ServiceGoods = options => { ...@@ -163,6 +164,7 @@ const ServiceGoods = options => {
const shopGetByProductType = async type => { const shopGetByProductType = async type => {
if (!newCategoryList[type]?.length) { if (!newCategoryList[type]?.length) {
const result = await getByProductType(type); const result = await getByProductType(type);
console.log('result :>> ', result);
setNewCategoryList({ setNewCategoryList({
...newCategoryList, ...newCategoryList,
[type]: result.data || [], [type]: result.data || [],
...@@ -185,6 +187,9 @@ const ServiceGoods = options => { ...@@ -185,6 +187,9 @@ const ServiceGoods = options => {
if (isEdit) { if (isEdit) {
sendData.id = pageId; sendData.id = pageId;
} }
if (options.isDraft) {
sendData.productDraftId = SourceData.id;
}
console.log('sendData :>> ', sendData); console.log('sendData :>> ', sendData);
sendMerchantProductHttpRequest(sendData); sendMerchantProductHttpRequest(sendData);
} }
...@@ -206,6 +211,36 @@ const ServiceGoods = options => { ...@@ -206,6 +211,36 @@ const ServiceGoods = options => {
} }
}; };
const onSetData = info => {
if (info.serviceItem) {
const ptime = info.serviceItem.purchaseTime;
const utime = info.serviceItem.useTime;
if (ptime && ptime.length === 2) {
ptime[0] = moment(ptime[0]);
ptime[1] = moment(ptime[1]);
}
if (utime && utime.length === 2) {
utime[0] = moment(utime[0]);
utime[1] = moment(utime[1]);
}
}
setProductType(info.type);
setEditData(info);
if (info.infoMation && info.infoMation.categoryId && info.infoMation.categoryId.length) {
setCategoryIds(info.infoMation.categoryId);
}
};
// 继续编辑(使用缓存数据)
const onContinueEdit = () => {
setVisibleCacheEdit(false);
setIsUseCache(true);
const info = localStorage.get(localAutoSaveKey);
if (info) {
onSetData(info);
}
};
useEffect(() => { useEffect(() => {
(async () => { (async () => {
if (!options.visible) { if (!options.visible) {
...@@ -217,11 +252,23 @@ const ServiceGoods = options => { ...@@ -217,11 +252,23 @@ const ServiceGoods = options => {
await getAfterSalesAddrsPage(); await getAfterSalesAddrsPage();
await getMerchantSpecList(); await getMerchantSpecList();
if (Object.keys(SourceData).length) { if (Object.keys(SourceData).length) {
setEditData(SourceData); console.log('SourceData :>> ', SourceData);
setPageId(SourceData.id); // 从编辑草稿进入 执行以下代码
setProductType(SourceData.productType); if (options.isDraft) {
setCategoryIds(SourceData.infoMation.categoryId || []); setIsUseCache(true);
setIsEdit(true); setVisibleCacheEdit(false);
onSetData(SourceData);
onValuesChange(SourceData, !0);
} else {
setEditData(SourceData);
setPageId(SourceData.id);
setProductType(SourceData.productType);
setCategoryIds(SourceData.infoMation.categoryId || []);
setIsEdit(true);
}
} else {
// 默认生成一条规格数据
stockRef.current.onFinish();
} }
setPageLoading(false); setPageLoading(false);
})(); })();
...@@ -278,37 +325,52 @@ const ServiceGoods = options => { ...@@ -278,37 +325,52 @@ const ServiceGoods = options => {
const onCategoryChange = e => { const onCategoryChange = e => {
setCategoryIds(e); setCategoryIds(e);
}; };
// 保存草稿 // 保存草稿
const onSaveDraft = () => { const onSaveDraft = async () => {
console.log('newCategoryList :>> ', newCategoryList);
const info = localStorage.get(localAutoSaveKey); const info = localStorage.get(localAutoSaveKey);
if (info) { if (info) {
localStorage.remove(localAutoSaveKey); if (
} !info.infoMation ||
}; !info.infoMation.name ||
// 继续编辑(使用缓存数据) !info.infoMation.categoryId ||
const onContinueEdit = () => { info.infoMation.categoryId.length !== 3
setVisibleCacheEdit(false); ) {
setIsUseCache(true); message.warning('请添加商品类目和名称');
const info = localStorage.get(localAutoSaveKey); return;
if (info) {
console.log('info :>> ', info);
if (info.serviceItem) {
const ptime = info.serviceItem.purchaseTime;
const utime = info.serviceItem.useTime;
if (ptime && ptime.length === 2) {
ptime[0] = moment(ptime[0]);
ptime[1] = moment(ptime[1]);
}
if (utime && utime.length === 2) {
utime[0] = moment(utime[0]);
utime[1] = moment(utime[1]);
}
} }
setProductType(info.type); info.type = productType;
setEditData(info); let arr = newCategoryList[info.type];
if (info.infoMation && info.infoMation.categoryId && info.infoMation.categoryId.length) { const first = arr.find(item => item.id === info.infoMation.categoryId[0]);
setCategoryIds(info.infoMation.categoryId); arr = first.children;
const second = arr.find(item => item.id === info.infoMation.categoryId[1]);
arr = second.children;
const third = arr.find(item => item.id === info.infoMation.categoryId[2]);
const params = {
productName: info.infoMation.name,
productType: info.type,
firstCategoryId: info.infoMation.categoryId[0],
firstCategoryName: first.name,
secondCategoryId: info.infoMation.categoryId[1],
secondCategoryName: second.name,
thirdCategoryId: info.infoMation.categoryId[2],
thirdCategoryName: third.name,
content: JSON.stringify(info),
};
console.log('params :>> ', params);
setPageLoading(true);
let api = apiCreateDraft;
if (options.isDraft) {
params.id = SourceData.id;
api = apiEditDraft;
} }
await api(params);
localStorage.remove(localAutoSaveKey);
setPageLoading(false);
message.success('草稿保存成功!');
handleCancel(true);
} }
}; };
......
...@@ -106,7 +106,14 @@ export const apiGetAttribute = categoryId => ...@@ -106,7 +106,14 @@ export const apiGetAttribute = categoryId =>
// 新建草稿 // 新建草稿
export const apiCreateDraft = data => export const apiCreateDraft = data =>
request.post('/product/draft/add', { request.post('/api/merchants/drafts/add', {
prefix: goodsApi,
data,
});
// 编辑草稿
export const apiEditDraft = data =>
request.post('/api/merchants/drafts/edit', {
prefix: goodsApi, prefix: goodsApi,
data, data,
}); });
...@@ -262,7 +262,7 @@ export const onAutoSaveValue = (e, isClear) => { ...@@ -262,7 +262,7 @@ export const onAutoSaveValue = (e, isClear) => {
localStorage.set(localAutoSaveKey, Object.assign({}, e)); localStorage.set(localAutoSaveKey, Object.assign({}, e));
} else { } else {
const info = localStorage.get(localAutoSaveKey) || {}; const info = localStorage.get(localAutoSaveKey) || {};
localStorage.set(localAutoSaveKey, Object.assign({}, info, e)); localStorage.set(localAutoSaveKey, Object.assign({ type: 1 }, info, e));
} }
}; };
......
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