Commit 0dee35f8 authored by 武广's avatar 武广

fix: 修改分组

parent 31551664
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 = 'sc1';
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`,
......
...@@ -143,6 +143,7 @@ class goodsManage extends Component { ...@@ -143,6 +143,7 @@ class goodsManage extends Component {
<Form <Form
ref={this.formRef} ref={this.formRef}
name="horizontal_login" name="horizontal_login"
initialValues={{ productType: 1 }}
layout="inline" layout="inline"
className={styles.searchForm} className={styles.searchForm}
> >
......
...@@ -7,20 +7,13 @@ import styles from '../../style.less'; ...@@ -7,20 +7,13 @@ import styles from '../../style.less';
const ItemTypes = { const ItemTypes = {
CARD: 'card', CARD: 'card',
}; };
const DragTag = ({ text, id, index, changePosition }) => { const DragTag = ({ text, id, index, changePosition, endChangePosition, edit }) => {
const [isEdit, setIsEdit] = useState(false); const [isEdit, setIsEdit] = useState(false);
const [inputValue, setInputValue] = useState(''); const [inputValue, setInputValue] = useState('');
const refInput = useRef(); const refInput = useRef();
const handleEdit = () => { const handleEdit = () => {
setIsEdit(true); edit(id);
setInputValue(text || '');
const timer = setTimeout(() => {
if (refInput.current) {
refInput.current.focus();
}
clearTimeout(timer);
}, 1);
}; };
const handleInputChange = e => { const handleInputChange = e => {
setInputValue(e.target.value); setInputValue(e.target.value);
...@@ -46,7 +39,12 @@ const DragTag = ({ text, id, index, changePosition }) => { ...@@ -46,7 +39,12 @@ const DragTag = ({ text, id, index, changePosition }) => {
changePosition(dragIndex, hoverIndex); // 调用传入的方法完成交换 changePosition(dragIndex, hoverIndex); // 调用传入的方法完成交换
item.index = hoverIndex; // 将当前当前移动到Box的index赋值给当前拖动的box,不然会出现两个盒子疯狂抖动! item.index = hoverIndex; // 将当前当前移动到Box的index赋值给当前拖动的box,不然会出现两个盒子疯狂抖动!
}, },
drop: (item, monitor) => {}, drop: (item, monitor) => {
const dragIndex = item.index;
const hoverIndex = index;
if (dragIndex === hoverIndex) return; // 如果回到自己的坑,那就什么都不做
endChangePosition(dragIndex, hoverIndex); // 调用传入的方法完成交换
},
}); });
const [{ isDragging }, drag] = useDrag({ const [{ isDragging }, drag] = useDrag({
......
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { Button, Select, Tag } from 'antd'; import { Button, Select, Tag } from 'antd';
import { DndProvider } from 'react-dnd'; import { DndProvider } from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend'; import HTML5Backend from 'react-dnd-html5-backend';
...@@ -6,42 +6,60 @@ import styles from '../../style.less'; ...@@ -6,42 +6,60 @@ import styles from '../../style.less';
import DragTag from './DragTag'; import DragTag from './DragTag';
import InsertTag from './InsertTag'; import InsertTag from './InsertTag';
import GroupInfo from './GroupInfo'; import GroupInfo from './GroupInfo';
import {
apiDelStorage,
apiSortStorage,
apiStorageList,
apiSupplierShopList,
apiStorageInfo,
} from '../../service';
const GoodsGroup = options => { const GoodsGroup = options => {
const [groupEdit, setGroupEdit] = useState(false); const [groupEdit, setGroupEdit] = useState(false);
const [selected, setSelected] = useState(0); const [selected, setSelected] = useState(0);
const [storageId, setStorageId] = useState(0);
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
const [shops, setShops] = useState([]); const [shops, setShops] = useState([]);
const [tags, setTags] = useState([]);
const [tags, setTags] = useState([ const getShopList = async () => {
{ const user = localStorage.getItem('user');
id: 0, const json = JSON.parse(user);
text: '000', const res = await apiSupplierShopList(json.id);
}, if (res && res.data && res.data.length > 0) {
{ setShops(
id: 1, res.data.map(item => ({
text: '111', label: item.name,
}, value: +item.id,
{ })),
id: 2, );
text: '000', options.changeShop(+res.data[0].id);
}, }
{ };
id: 3,
text: '111', const getGroupList = async () => {
}, const res = await apiStorageList({
{ shopId: options.shopId,
id: 4, });
text: '000', if (res && res.data && res.data.length > 0) {
}, const arr = res.data
{ .sort((x, y) => x.priority - y.priority)
id: 5, .map(item => ({
text: '111', text: item.name,
}, id: item.rackId,
]); }));
setTags(arr);
setSelected(res.data[0].rackId);
}
};
const handelEdit = async id => {
setStorageId(id || 0);
setIsModalOpen(true);
};
// 更换位置 // 更换位置
const changePosition = (dragIndex, hoverIndex) => { const changePosition = async (dragIndex, hoverIndex) => {
const data = tags.slice(); const data = tags.slice();
const temp = data[dragIndex]; const temp = data[dragIndex];
// 交换位置 // 交换位置
...@@ -49,21 +67,58 @@ const GoodsGroup = options => { ...@@ -49,21 +67,58 @@ const GoodsGroup = options => {
data[hoverIndex] = temp; data[hoverIndex] = temp;
setTags(data); setTags(data);
}; };
const endChangePosition = async (dragIndex, hoverIndex) => {
const data = tags.slice();
const temp = data[dragIndex];
// 交换位置
data[dragIndex] = data[hoverIndex];
data[hoverIndex] = temp;
const storageRankList = data.map((item, i) => ({
id: item.id,
priority: i + 1,
}));
const params = {
shopId: options.shopId,
storageRankList,
};
await apiSortStorage(params);
getGroupList();
};
const onSelect = i => {
setSelected(i);
};
useEffect(() => {
if (options.shopId) {
getGroupList();
}
}, [options.shopId]);
useEffect(() => {
getShopList();
}, []);
useEffect(() => {
options.changeGroup(selected);
}, [selected]);
return ( return (
<div className={styles.groupBox}> <div className={styles.groupBox}>
<div className={styles['groupBox-title']}> {(shops && shops.length && (
<div className={styles['groupBox-title--name']}>所属门店</div> <div className={styles['groupBox-title']}>
<Select <div className={styles['groupBox-title--name']}>所属门店</div>
showSearch <Select
placeholder="请选择所属门店" showSearch
onChange={options.changeShop} value={options.shopId}
filterOption={(input, option) => placeholder="请选择所属门店"
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()) onChange={options.changeShop}
} filterOption={(input, option) =>
options={shops} (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
/> }
</div> options={shops}
/>
</div>
)) ||
''}
<div className={styles['groupBox-title']}> <div className={styles['groupBox-title']}>
<div className={styles['groupBox-title--name']}>商品分组</div> <div className={styles['groupBox-title--name']}>商品分组</div>
<Button onClick={() => setGroupEdit(!groupEdit)}>{groupEdit ? '完成' : '编辑分组'}</Button> <Button onClick={() => setGroupEdit(!groupEdit)}>{groupEdit ? '完成' : '编辑分组'}</Button>
...@@ -75,35 +130,41 @@ const GoodsGroup = options => { ...@@ -75,35 +130,41 @@ const GoodsGroup = options => {
{tags.map((item, index) => ( {tags.map((item, index) => (
<DragTag <DragTag
changePosition={changePosition} changePosition={changePosition}
endChangePosition={endChangePosition}
index={index} index={index}
{...item} {...item}
selected={selected} selected={selected}
changeGroup={e => setSelected(e)} edit={handelEdit}
key={item.id} key={item.id}
/> />
))} ))}
<InsertTag handleOpen={setIsModalOpen} /> <InsertTag handleOpen={handelEdit} />
</div> </div>
</DndProvider> </DndProvider>
) : ( ) : (
<div className={styles['groupBox-body--dragbox']}> <div className={styles['groupBox-body--dragbox']}>
{tags.map((item, index) => ( {tags.map(item => (
<Tag <Tag
key={item.id} key={item.id}
onClick={() => setSelected(index)} onClick={() => onSelect(item.id)}
className={[ className={[
styles['groupBox-body--tag-normal'], styles['groupBox-body--tag-normal'],
selected === index ? styles['groupBox-body--tag__cur'] : '', selected === item.id ? styles['groupBox-body--tag__cur'] : '',
]} ]}
> >
<span className={styles['groupBox-body--tag__text']}>{item.text}</span> <span className={styles['groupBox-body--tag__text']}>{item.text}</span>
</Tag> </Tag>
))} ))}
<InsertTag handleOpen={setIsModalOpen} /> <InsertTag key="insert" handleOpen={setIsModalOpen} />
</div> </div>
)} )}
</div> </div>
<GroupInfo isModalOpen={isModalOpen} handleClose={setIsModalOpen} /> <GroupInfo
isModalOpen={isModalOpen}
id={storageId}
shopId={options.shopId}
handleClose={setIsModalOpen}
/>
</div> </div>
); );
}; };
......
import React from 'react'; import React, { useEffect } from 'react';
import { Form, Modal, Input, Checkbox, Alert } from 'antd'; import { Form, Modal, Input, Checkbox, Alert, message } from 'antd';
import { apiCreateStorage, apiEditStorage, apiStorageInfo } from '../../service';
const GroupInfo = options => { const GroupInfo = options => {
const [form] = Form.useForm(); const [form] = Form.useForm();
...@@ -12,10 +13,34 @@ const GroupInfo = options => { ...@@ -12,10 +13,34 @@ const GroupInfo = options => {
// 提交分组 // 提交分组
const handleConfirm = async () => { const handleConfirm = async () => {
const values = await form.validateFields(); const values = await form.validateFields();
console.log('values :>> ', values); const api = options.id ? apiEditStorage : apiCreateStorage;
const res = await api({
...values,
shopId: options.shopId,
id: options.id,
});
handleCancel(); handleCancel();
options.search();
}; };
const getInfo = async id => {
const res = await apiStorageInfo({
shopId: options.shopId,
id,
});
if (res && res.data && res.data.id) {
form.setFieldsValue({
name: res.data.name,
});
}
};
useEffect(() => {
if (options.id && options.isModalOpen) {
getInfo(options.id);
}
}, [options.id, options.isModalOpen]);
const extra = ( const extra = (
<Alert <Alert
message="选中后,顾客下单需至少选择1个“下单必选分组”商品每店仅可设置1个必点分组" message="选中后,顾客下单需至少选择1个“下单必选分组”商品每店仅可设置1个必点分组"
......
...@@ -5,7 +5,7 @@ import styles from '../../style.less'; ...@@ -5,7 +5,7 @@ import styles from '../../style.less';
const InsertTag = options => { const InsertTag = options => {
const showInput = () => { const showInput = () => {
options.handleOpen(true); options.handleOpen();
}; };
return ( return (
......
...@@ -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, apiGoodsActionBatch } from '../service'; import { apiTakeawayGoods, 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';
...@@ -19,6 +19,7 @@ const Takeaway = options => { ...@@ -19,6 +19,7 @@ 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 [shopId, setShopId] = useState(0);
const [groupId, setGroupId] = useState(0);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [actionLoading, setActionLoading] = useState(false); const [actionLoading, setActionLoading] = useState(false);
const [visibleWeekTime, setVisibleWeekTime] = useState(false); const [visibleWeekTime, setVisibleWeekTime] = useState(false);
...@@ -60,7 +61,13 @@ const Takeaway = options => { ...@@ -60,7 +61,13 @@ const Takeaway = options => {
const getDataList = async () => { const getDataList = async () => {
setLoading(true); setLoading(true);
const res = await searchList({ productType: 1 }); const params = {
pageNo: 1,
productType: 5,
pageSize: 100000,
storageRackId: groupId,
};
const res = await apiTakeawayGoods(params);
setLoading(false); setLoading(false);
if (res && res.data) { if (res && res.data) {
setTableData(res.data.records); setTableData(res.data.records);
...@@ -117,7 +124,7 @@ const Takeaway = options => { ...@@ -117,7 +124,7 @@ const Takeaway = options => {
return ( return (
<div className={styles.takeawayBox}> <div className={styles.takeawayBox}>
<Spin spinning={loading}> <Spin spinning={loading}>
<GoodsGroup changeShop={setShopId} /> <GoodsGroup shopId={shopId} changeShop={setShopId} changeGroup={setGroupId} />
<ActionBar <ActionBar
selectedRowKeys={selectedRowKeys} selectedRowKeys={selectedRowKeys}
handleSearch={getDataList} handleSearch={getDataList}
......
...@@ -61,7 +61,7 @@ class goodsManage extends Component { ...@@ -61,7 +61,7 @@ class goodsManage extends Component {
auditRow: {}, // 查看审核信息使用 auditRow: {}, // 查看审核信息使用
isVisibleDraft: false, // 显示隐藏草稿箱 isVisibleDraft: false, // 显示隐藏草稿箱
isEditDraft: false, // 是否编辑草稿 isEditDraft: false, // 是否编辑草稿
productType: 5, // 商品类型 productType: 1, // 商品类型
}; };
currentLog = null; currentLog = null;
...@@ -77,6 +77,7 @@ class goodsManage extends Component { ...@@ -77,6 +77,7 @@ class goodsManage extends Component {
this.categoryList(); this.categoryList();
this.getVirtualCategory(); this.getVirtualCategory();
this.specList(); this.specList();
this.setState({ productType: 5 });
} }
handleSearch = page => { handleSearch = page => {
......
...@@ -297,3 +297,68 @@ export async function apiGoodsActionBatch(data) { ...@@ -297,3 +297,68 @@ export async function apiGoodsActionBatch(data) {
data, data,
}); });
} }
// 外卖商品列表
export async function apiTakeawayGoods(params) {
return request.post('/product/api/merchant/page', {
prefix: goodsApi,
data: stringify(params),
headers,
});
}
// 外卖商品排序
export async function apiSortTakeawayGoods(data) {
return request.post('/v1/channels/products/sku/batchSort', {
prefix: goodsApi,
data,
});
}
// 获取供应商门店列表
export async function apiSupplierShopList() {
return request.get('/api/merchants/shops/getBySupplierId?state=1', {
prefix: goodsApi,
});
}
// 分组创建(货架—创建货架)
export async function apiCreateStorage(data) {
return request.post('/api/merchants/products/storageRack/create', {
prefix: goodsApi,
data,
});
}
// 编辑分组(货架—编辑货架)
export async function apiEditStorage(data) {
return request.post('/api/merchants/products/storageRack/edit', {
prefix: goodsApi,
data,
});
}
// 分组详情(货架—货架详情)
export async function apiStorageInfo(params) {
return request.post('/api/merchants/products/storageRack/queryByShopIdAndStorageRackId', {
prefix: goodsApi,
data: stringify(params),
headers,
});
}
// 删除分组(货架—删除货架)
export async function apiDelStorage(data) {
return request.post('/api/merchants/products/storageRack/removeByShopIdAndId', {
prefix: goodsApi,
data,
});
}
// 分组排序(货架—排序货架)
export async function apiSortStorage(data) {
return request.post('/api/merchants/products/storageRack/batchSort', {
prefix: goodsApi,
data,
});
}
// 分组列表(货架—货架列表)
export async function apiStorageList(params) {
return request.post('/api/merchants/products/storageRack/listByShopIdAndStorageRackIds', {
prefix: goodsApi,
data: stringify(params),
headers,
});
}
...@@ -399,15 +399,15 @@ export const batchAction = event => [ ...@@ -399,15 +399,15 @@ export const batchAction = event => [
</a> </a>
), ),
}, },
{ // {
key: 'group', // key: 'group',
type: '3', // type: '3',
label: ( // label: (
<a type="text" onClick={() => event.onChangeState('group')}> // <a type="text" onClick={() => event.onChangeState('group')}>
修改分组 // 修改分组
</a> // </a>
), // ),
}, // },
{ {
key: 'send', key: 'send',
type: '6', type: '6',
......
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