Commit 47ad8c79 authored by 武广's avatar 武广

fix: 处理批量操作接口参数

parent 822b7558
...@@ -3,7 +3,7 @@ import { Button, Dropdown, Menu, message, Modal } from 'antd'; ...@@ -3,7 +3,7 @@ import { Button, Dropdown, Menu, message, Modal } from 'antd';
import { PlusOutlined, DownOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { PlusOutlined, DownOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
import { batchAction } from '../../staticdata'; import { batchAction } from '../../staticdata';
import styles from '../../style.less'; import styles from '../../style.less';
import { apiChangeStateGoods } from '../../service'; import { apiGoodsActionBatch } from '../../service';
const ActionBar = options => { const ActionBar = options => {
// 上下架 // 上下架
...@@ -12,8 +12,9 @@ const ActionBar = options => { ...@@ -12,8 +12,9 @@ const ActionBar = options => {
icon: <ExclamationCircleOutlined />, icon: <ExclamationCircleOutlined />,
content: `确认${+state === 6 ? '下架' : '上架'}商品?`, content: `确认${+state === 6 ? '下架' : '上架'}商品?`,
onOk: async () => { onOk: async () => {
const res = await apiChangeStateGoods({ const res = await apiGoodsActionBatch({
ids: options.selectedRowKeys, ids: options.selectedRowKeys,
type: 2,
productState: +state === 6 ? 7 : 6, // 6:上架,7:下架 productState: +state === 6 ? 7 : 6, // 6:上架,7:下架
}); });
if (res.businessCode === '0000' && res.code === '0000') { if (res.businessCode === '0000' && res.code === '0000') {
......
...@@ -9,6 +9,10 @@ const MinimumPurchase = forwardRef(options => { ...@@ -9,6 +9,10 @@ const MinimumPurchase = forwardRef(options => {
const handleOk = async () => { const handleOk = async () => {
const values = await form.validateFields(); const values = await form.validateFields();
console.log('values :>> ', values); console.log('values :>> ', values);
options.confirm({
type: 5,
...values,
});
}; };
return ( return (
...@@ -17,6 +21,7 @@ const MinimumPurchase = forwardRef(options => { ...@@ -17,6 +21,7 @@ const MinimumPurchase = forwardRef(options => {
title="修改最少购买数量" title="修改最少购买数量"
onOk={handleOk} onOk={handleOk}
maskClosable={false} maskClosable={false}
confirmLoading={options.loading}
destroyOnClose destroyOnClose
onCancel={handleCancel} onCancel={handleCancel}
> >
......
...@@ -9,6 +9,10 @@ const SendModal = forwardRef(options => { ...@@ -9,6 +9,10 @@ const SendModal = forwardRef(options => {
const handleOk = async () => { const handleOk = async () => {
const values = await form.validateFields(); const values = await form.validateFields();
console.log('values :>> ', values); console.log('values :>> ', values);
options.confirm({
type: 6,
...values,
});
}; };
const radioOptions = [{ label: '', value: 1 }, { label: '', value: 0 }]; const radioOptions = [{ label: '', value: 1 }, { label: '', value: 0 }];
...@@ -20,6 +24,7 @@ const SendModal = forwardRef(options => { ...@@ -20,6 +24,7 @@ const SendModal = forwardRef(options => {
title="设置单点不送" title="设置单点不送"
onOk={handleOk} onOk={handleOk}
maskClosable={false} maskClosable={false}
confirmLoading={options.loading}
destroyOnClose destroyOnClose
onCancel={handleCancel} onCancel={handleCancel}
> >
......
import React, { forwardRef, useState } from 'react'; import React, { forwardRef, useState, useEffect } from 'react';
import { Modal, Form } from 'antd'; import { Modal, Form, Input, Checkbox, Radio, Switch } from 'antd';
import { deepClone } from '@/utils/utils';
import styles from '../../style.less';
const StockModal = forwardRef(options => { const StockModal = forwardRef(options => {
const [stockType, setStockType] = useState(0);
const [maxStock, setMaxStock] = useState(0);
const [form] = Form.useForm(); const [form] = Form.useForm();
const onChangeType = v => {
setStockType(v === stockType ? 0 : v);
if (v === 1) {
form.setFieldsValue({
productStock: 0,
});
}
};
const onChangeMaxStock = ({ target: { value } }) => {
setMaxStock(value);
};
const handleCancel = () => { const handleCancel = () => {
options.cancel(false); options.cancel(false);
}; };
const handleOk = async () => { const handleOk = async () => {
const values = await form.validateFields(); const values = await form.validateFields();
const params = deepClone(values);
params.autoStock = values.autoStock ? 1 : 0;
console.log('values :>> ', values); console.log('values :>> ', values);
options.confirm({
type: 7,
...values,
});
}; };
const initialValues = Object.assign( const initialValues = Object.assign(
{ {
saleTimeType: 1, productStock: '',
saleDates: [], autoStockStep: '',
saleTimes: [[]], autoStock: false,
}, },
options.initialValues, options.initialValues,
); );
useEffect(() => {
if (stockType === 2) {
form.setFieldsValue({
productStock: maxStock,
});
}
}, [maxStock, stockType]);
return ( return (
<Modal <Modal
visible={options.visible} visible={options.visible}
title="售卖时间" title="修改库存"
onOk={handleOk} onOk={handleOk}
maskClosable={false} maskClosable={false}
confirmLoading={options.loading}
destroyOnClose destroyOnClose
onCancel={handleCancel} onCancel={handleCancel}
> >
...@@ -36,15 +69,37 @@ const StockModal = forwardRef(options => { ...@@ -36,15 +69,37 @@ const StockModal = forwardRef(options => {
wrapperCol={{ span: 16 }} wrapperCol={{ span: 16 }}
initialValues={initialValues} initialValues={initialValues}
autoComplete="off" autoComplete="off"
className={styles['stock-box']}
> >
<Form.Item <Form.Item
label="剩余库存" label="剩余库存"
name="saleTimeType" name="productStock"
labelCol={{ span: 6 }}
wrapperCol={{ span: 8 }}
rules={[{ required: true, message: '请输入剩余库存!' }]} rules={[{ required: true, message: '请输入剩余库存!' }]}
> >
<div>1</div> <Input type="number" disabled={stockType > 0} />
</Form.Item>
<div className={styles['stock-box--btns']}>
<Checkbox checked={stockType === 1} onChange={() => onChangeType(1)}>
清零
</Checkbox>
<Checkbox checked={stockType === 2} onChange={() => onChangeType(2)}>
最大
</Checkbox>
</div>
<Form.Item
label="最大库存"
name="autoStockStep"
rules={[{ required: true, message: '请输入最大库存!' }]}
>
<Input type="number" onChange={onChangeMaxStock} />
</Form.Item>
<Form.Item label="自动补足" name="autoStock">
<Switch checkedChildren="开启" unCheckedChildren="关闭" />
</Form.Item> </Form.Item>
</Form> </Form>
<div className={styles['stock-box--red']}>修改成功后,原库存将被替换,请谨慎操作</div>
</Modal> </Modal>
); );
}); });
......
...@@ -9,6 +9,11 @@ const SwitchGroupModal = forwardRef(options => { ...@@ -9,6 +9,11 @@ const SwitchGroupModal = forwardRef(options => {
const handleOk = async () => { const handleOk = async () => {
const values = await form.validateFields(); const values = await form.validateFields();
console.log('values :>> ', values); console.log('values :>> ', values);
options.confirm({
type: 3,
...values,
});
}; };
const radioOptions = [{ label: '', value: 1 }, { label: '', value: 0 }]; const radioOptions = [{ label: '', value: 1 }, { label: '', value: 0 }];
...@@ -20,6 +25,7 @@ const SwitchGroupModal = forwardRef(options => { ...@@ -20,6 +25,7 @@ const SwitchGroupModal = forwardRef(options => {
title="更改分组" title="更改分组"
onOk={handleOk} onOk={handleOk}
maskClosable={false} maskClosable={false}
confirmLoading={options.loading}
destroyOnClose destroyOnClose
onCancel={handleCancel} onCancel={handleCancel}
> >
......
import React, { forwardRef, useState } from 'react'; import React, { forwardRef, useState } from 'react';
import { Modal, Radio, Form, TimePicker, Checkbox } from 'antd'; import { Modal, Radio, Form, TimePicker, Checkbox } from 'antd';
import { MinusSquareOutlined, PlusSquareOutlined } from '@ant-design/icons'; import { MinusSquareOutlined, PlusSquareOutlined } from '@ant-design/icons';
import moment from 'moment';
import { deepClone } from '@/utils/utils';
import { saleWeeks } from '../../staticdata'; import { saleWeeks } from '../../staticdata';
import styles from '../../style.less'; import styles from '../../style.less';
...@@ -35,9 +37,22 @@ const WeekTime = forwardRef(options => { ...@@ -35,9 +37,22 @@ const WeekTime = forwardRef(options => {
options.cancel(false); options.cancel(false);
}; };
const handleOk = async () => { const handleOk = async () => {
console.log('111 :>> ', 111);
const values = await form.validateFields(); const values = await form.validateFields();
console.log('values :>> ', values); const params = deepClone(values);
if (params.saleTimes && params.saleTimes.length) {
params.saleTimes = values.saleTimes.map(item => {
if (item && item.length > 1) {
item[0] = moment(item[0]).format('HH:mm');
item[1] = moment(item[1]).format('HH:mm');
}
return item;
});
}
options.confirm({
type: 4,
...params,
});
}; };
const initialValues = Object.assign( const initialValues = Object.assign(
...@@ -55,6 +70,7 @@ const WeekTime = forwardRef(options => { ...@@ -55,6 +70,7 @@ const WeekTime = forwardRef(options => {
title="售卖时间" title="售卖时间"
onOk={handleOk} onOk={handleOk}
maskClosable={false} maskClosable={false}
confirmLoading={options.loading}
destroyOnClose destroyOnClose
onCancel={handleCancel} onCancel={handleCancel}
> >
......
...@@ -4,7 +4,7 @@ import { MenuOutlined, HolderOutlined, FormOutlined, CloseCircleOutlined } from ...@@ -4,7 +4,7 @@ import { MenuOutlined, HolderOutlined, FormOutlined, CloseCircleOutlined } from
import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc'; import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';
import { arrayMoveImmutable } from 'array-move'; import { arrayMoveImmutable } from 'array-move';
import GoodsGroup from './components/GoodsGroup'; import GoodsGroup from './components/GoodsGroup';
import { searchList } from '../service'; import { searchList, apiGoodsActionBatch } from '../service';
import styles from '../style.less'; import styles from '../style.less';
import { takeawayColumn } from '../staticdata'; import { takeawayColumn } from '../staticdata';
// import VirtualTable from './components/VirtualTable'; // import VirtualTable from './components/VirtualTable';
...@@ -13,11 +13,14 @@ import WeekTime from './components/WeekTime'; ...@@ -13,11 +13,14 @@ import WeekTime from './components/WeekTime';
import StockModal from './components/StockModal'; import StockModal from './components/StockModal';
import SendModal from './components/SendModal'; import SendModal from './components/SendModal';
import MinimumPurchaseModal from './components/MinimumPurchase'; import MinimumPurchaseModal from './components/MinimumPurchase';
import SwitchGroupModal from './components/SwitchGroupModal';
const Takeaway = options => { const Takeaway = options => {
const [tableData, setTableData] = useState([]); const [tableData, setTableData] = useState([]);
const [selectedRowKeys, setSelectedRowKeys] = useState([]); const [selectedRowKeys, setSelectedRowKeys] = useState([]);
const [shopId, setShopId] = useState(0);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [actionLoading, setActionLoading] = useState(false);
const [visibleWeekTime, setVisibleWeekTime] = useState(false); const [visibleWeekTime, setVisibleWeekTime] = useState(false);
const [visibleStock, setVisibleStock] = useState(false); const [visibleStock, setVisibleStock] = useState(false);
const [visibleBuy, setVisibleBuy] = useState(false); const [visibleBuy, setVisibleBuy] = useState(false);
...@@ -64,6 +67,24 @@ const Takeaway = options => { ...@@ -64,6 +67,24 @@ const Takeaway = options => {
} }
}; };
// 批量操作 type 1-是否列出 2-修改上下架 3-改货架 4-售卖时间更新 5-调整商品起购数量 6-调整商品是否单点不送 7-修改库存
const handleBatchAction = async params => {
const json = {
skuIds: selectedRowKeys,
shopId,
};
// setActionLoading(true);
// const params2 = {
// ...json,
// ...params,
// };
// console.log('params2 :>> ', params2);
// const res = await apiGoodsActionBatch(Object.assign({}, json, params));
// setActionLoading(false);
// getDataList();
message.success('处理成功!');
};
// 显示弹窗 // 显示弹窗
const openModal = type => { const openModal = type => {
type === 'time' && setVisibleWeekTime(true); type === 'time' && setVisibleWeekTime(true);
...@@ -73,19 +94,39 @@ const Takeaway = options => { ...@@ -73,19 +94,39 @@ const Takeaway = options => {
type === 'send' && setVisibleSend(true); type === 'send' && setVisibleSend(true);
}; };
// 单商品修改库存
const onShowStockModal = ({ skuId }) => {
setSelectedRowKeys([skuId]);
openModal('stock');
};
// 编辑
const onEdit = row => {};
// 置顶
const toTop = row => {};
useEffect(() => { useEffect(() => {
getDataList(); getDataList();
}, []); }, []);
const actions = {
onShowStockModal,
toTop,
onEdit,
};
return ( return (
<div className={styles.takeawayBox}> <div className={styles.takeawayBox}>
<Spin spinning={loading}> <Spin spinning={loading}>
<GoodsGroup /> <GoodsGroup />
<ActionBar selectedRowKeys={selectedRowKeys} openModal={openModal} /> <ActionBar
selectedRowKeys={selectedRowKeys}
handleSearch={getDataList}
openModal={openModal}
/>
<Table <Table
dataSource={tableData} dataSource={tableData}
bordered bordered
columns={takeawayColumn.call(this)} columns={takeawayColumn(actions)}
rowKey={record => record.skuId} rowKey={record => record.skuId}
pagination={false} pagination={false}
scroll={{ x: '100%', y: 1000 }} scroll={{ x: '100%', y: 1000 }}
...@@ -98,10 +139,36 @@ const Takeaway = options => { ...@@ -98,10 +139,36 @@ const Takeaway = options => {
}} }}
/> />
</Spin> </Spin>
<WeekTime visible={visibleWeekTime} cancel={setVisibleWeekTime} /> <WeekTime
<StockModal visible={visibleStock} cancel={setVisibleStock} /> visible={visibleWeekTime}
<SendModal visible={visibleSend} cancel={setVisibleSend} /> loading={actionLoading}
<MinimumPurchaseModal visible={visibleBuy} cancel={setVisibleBuy} /> confirm={handleBatchAction}
cancel={setVisibleWeekTime}
/>
<StockModal
visible={visibleStock}
loading={actionLoading}
confirm={handleBatchAction}
cancel={setVisibleStock}
/>
<SendModal
visible={visibleSend}
loading={actionLoading}
confirm={handleBatchAction}
cancel={setVisibleSend}
/>
<MinimumPurchaseModal
visible={visibleBuy}
loading={actionLoading}
confirm={handleBatchAction}
cancel={setVisibleBuy}
/>
<SwitchGroupModal
visible={visibleSwitchGroup}
loading={actionLoading}
confirm={handleBatchAction}
cancel={setVisibleSwitchGroup}
/>
</div> </div>
); );
}; };
......
...@@ -289,3 +289,11 @@ export async function apiDraftList(data) { ...@@ -289,3 +289,11 @@ export async function apiDraftList(data) {
data, data,
}); });
} }
// 批量操作
export async function apiGoodsActionBatch(data) {
return request.post('/api/merchants/products/sku/batchOperation', {
prefix: goodsApi,
data,
});
}
...@@ -325,7 +325,12 @@ export function takeawayColumn(actions) { ...@@ -325,7 +325,12 @@ export function takeawayColumn(actions) {
render: (_, row, index) => ( render: (_, row, index) => (
<div className={styles.actionBtn}> <div className={styles.actionBtn}>
{(row.state === 4 || (row.state >= 5 && row.updateState !== 1)) && ( {(row.state === 4 || (row.state >= 5 && row.updateState !== 1)) && (
<Button key="edit" type="primary" className={styles.button}> <Button
key="edit"
type="primary"
className={styles.button}
onClick={() => actions.onEdit(row)}
>
编辑 编辑
</Button> </Button>
)} )}
...@@ -341,12 +346,12 @@ export function takeawayColumn(actions) { ...@@ -341,12 +346,12 @@ export function takeawayColumn(actions) {
key="log" key="log"
type="primary" type="primary"
className={styles.button} className={styles.button}
onClick={() => this.onShowStockModal(row)} onClick={() => actions.onShowStockModal(row)}
> >
修改库存 修改库存
</Button> </Button>
{index > 0 && ( {index > 0 && (
<Button key="top" className={styles.button}> <Button key="top" className={styles.button} onClick={() => actions.toTop(row)}>
置顶 置顶
</Button> </Button>
)} )}
......
...@@ -259,3 +259,17 @@ ...@@ -259,3 +259,17 @@
.error { .error {
color: #ff4d4f; color: #ff4d4f;
} }
.stock-box {
position: relative;
&--btns {
position: absolute;
top: 0;
right: 0;
height: 32px;
padding-right: 8%;
line-height: 32px;
}
&--red {
color: #ff1616;
}
}
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