Commit 6957119a authored by 张子雨's avatar 张子雨

feat: 代码优化

parent 1a6bb192
...@@ -71,9 +71,9 @@ const NewEmployeeModal = props => { ...@@ -71,9 +71,9 @@ const NewEmployeeModal = props => {
<Modal <Modal
visible={visible} visible={visible}
title="添加新员工" title="添加新员工"
onCancel={handleCancel} onCancel={() => handleCancel(false)}
footer={[ footer={[
<Button key="cancel" onClick={handleCancel}> <Button key="cancel" onClick={() => handleCancel(false)}>
取消 取消
</Button>, </Button>,
<Button key="save" type="primary" onClick={handleSave}> <Button key="save" type="primary" onClick={handleSave}>
......
...@@ -49,9 +49,10 @@ const StoreManagement = () => { ...@@ -49,9 +49,10 @@ const StoreManagement = () => {
const [firstEnterprise, setFirstEnterprise] = useState(); const [firstEnterprise, setFirstEnterprise] = useState();
const [departmentList, setDepartmentList] = useState([]); const [departmentList, setDepartmentList] = useState([]);
const [generateLog, setGenerateLog] = useState([]); const [generateLog, setGenerateLog] = useState([]);
const [loading, setLoading] = useState(false);
const [page, setPage] = useState({ const [page, setPage] = useState({
page: 1, current: 1,
size: 10, pageSize: 10,
}); });
const [total, setTotal] = useState(0); const [total, setTotal] = useState(0);
const [searchForm, setSearchForm] = useState({}); const [searchForm, setSearchForm] = useState({});
...@@ -62,12 +63,20 @@ const StoreManagement = () => { ...@@ -62,12 +63,20 @@ const StoreManagement = () => {
const [repastId, setRepastId] = useState(null); const [repastId, setRepastId] = useState(null);
const shopList = async params => { const shopList = async params => {
setLoading(true);
const res = await apiStaffList(params); const res = await apiStaffList(params);
if (res.businessCode === '0000' && res.data?.records) { if (res?.businessCode === '0000') {
const list = res.data.records; const list = res.data?.records;
setTotal(res.data.total); setTotal(res.data.total);
setStaffList(list); setStaffList(list);
setLoading(false);
return;
} }
setTimeout(() => {
setLoading(false);
setStaffList([]);
setTotal(0);
}, 5000);
}; };
const rowSelection = { const rowSelection = {
selectedRowKeys, selectedRowKeys,
...@@ -180,8 +189,8 @@ const StoreManagement = () => { ...@@ -180,8 +189,8 @@ const StoreManagement = () => {
const onFinish = values => { const onFinish = values => {
setSearchForm(values); setSearchForm(values);
const pageInfo = { const pageInfo = {
page: 1, current: 1,
size: 10, pageSize: 10,
}; };
setPage(pageInfo); setPage(pageInfo);
shopList({ ...pageInfo, data: values }); shopList({ ...pageInfo, data: values });
...@@ -193,10 +202,10 @@ const StoreManagement = () => { ...@@ -193,10 +202,10 @@ const StoreManagement = () => {
shopList({ ...page, data: { enterpriseId: firstEnterprise } }); shopList({ ...page, data: { enterpriseId: firstEnterprise } });
}; };
// 分页 // 分页
const onChange = (pageNo, size) => { const onChange = (current, pageSize) => {
const pageInfo = { const pageInfo = {
page: pageNo, current,
size, pageSize,
}; };
setPage(pageInfo); setPage(pageInfo);
shopList({ data: searchForm, ...pageInfo }); shopList({ data: searchForm, ...pageInfo });
...@@ -221,7 +230,16 @@ const StoreManagement = () => { ...@@ -221,7 +230,16 @@ const StoreManagement = () => {
} }
}; };
const enterpriseOnChange = val => { const enterpriseOnChange = val => {
setFirstEnterprise(val);
getDepartmentList(val); getDepartmentList(val);
const pageInfo = {
current: 1,
pageSize: 10,
};
const values = formRef.current.getFieldsValue();
setPage(pageInfo);
setSearchForm(values);
shopList({ ...pageInfo, data: values });
}; };
const res = { const res = {
delEmployee, delEmployee,
...@@ -364,6 +382,7 @@ const StoreManagement = () => { ...@@ -364,6 +382,7 @@ const StoreManagement = () => {
bordered bordered
rowSelection={rowSelection} rowSelection={rowSelection}
pagination={pagination} pagination={pagination}
loading={loading}
/> />
</Card> </Card>
<NewEmployeeModal <NewEmployeeModal
......
...@@ -8,6 +8,10 @@ const { goodsApi, apiPrefix, roleApi } = config; ...@@ -8,6 +8,10 @@ const { goodsApi, apiPrefix, roleApi } = config;
// [企业员工]-列表查询 // [企业员工]-列表查询
// http://yapi.quantgroups.com/project/389/interface/api/65359 // http://yapi.quantgroups.com/project/389/interface/api/65359
export const apiStaffList = async params => { export const apiStaffList = async params => {
params.page = params.current;
params.size = params.pageSize;
delete params.current;
delete params.pageSize;
const data = await request.post(`${apiPrefix}/enterprise/staff/pageList`, { const data = await request.post(`${apiPrefix}/enterprise/staff/pageList`, {
prefix: roleApi, prefix: roleApi,
data: params, data: params,
......
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { Modal, Radio, Form, Space, message, Checkbox } from 'antd'; import { Modal, Radio, Form, Space, message, Checkbox } from 'antd';
import styles from '../index.less'; import styles from '../index.less';
import { apiShopUpdate, busineesTypeCheck } from '../service.js'; import { apiShopUpdate, busineesTypeCheck } from '../service.js';
const EditRepastModal = props => { const EditRepastModal = props => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const { editVisible, repastType, id, enterpriseId, isStore } = props; const { editVisible, repastType, id, enterpriseId, isStore, selectMealType } = props;
const handleCancel = status => { const handleCancel = status => {
form.resetFields(); form.resetFields();
props.onCancel(status, 'edit'); props.onCancel(status, 'edit');
}; };
useEffect(() => {
if (selectMealType.length) {
const mealTypeList = selectMealType.filter(item => item !== 4);
const store = selectMealType.includes(4) ? [4] : [];
form.setFieldsValue({ mealTypeList, store });
}
}, [selectMealType]);
const onOk = () => { const onOk = () => {
form.validateFields().then(async values => { form.validateFields().then(async values => {
console.log(values); console.log(values);
......
...@@ -18,8 +18,8 @@ import { ...@@ -18,8 +18,8 @@ import {
const { confirm } = Modal; const { confirm } = Modal;
const StoreManagement = () => { const StoreManagement = () => {
const [page, setPage] = useState({ const [page, setPage] = useState({
page: 1, current: 1,
size: 10, pageSize: 10,
}); });
const [total, setTotal] = useState(0); const [total, setTotal] = useState(0);
const [searchForm, setSearchForm] = useState({}); const [searchForm, setSearchForm] = useState({});
...@@ -34,12 +34,22 @@ const StoreManagement = () => { ...@@ -34,12 +34,22 @@ const StoreManagement = () => {
const [dataList, setDataList] = useState([]); const [dataList, setDataList] = useState([]);
const [name, setName] = useState(''); const [name, setName] = useState('');
const [isStore, setIsStore] = useState(false); const [isStore, setIsStore] = useState(false);
const [loading, setLoading] = useState(false);
const [selectMealType, setSelectMealType] = useState([]);
const shopList = async params => { const shopList = async params => {
setLoading(true);
const res = await setShopList(params); const res = await setShopList(params);
if (res.businessCode === '0000') { if (res?.businessCode === '0000') {
setLoading(false);
setDataList(res.data?.records); setDataList(res.data?.records);
setTotal(res.data?.total); setTotal(res.data?.total);
return;
} }
setTimeout(() => {
setLoading(false);
setDataList([]);
setTotal(0);
}, 5000);
}; };
// 企业查询 // 企业查询
...@@ -67,8 +77,8 @@ const StoreManagement = () => { ...@@ -67,8 +77,8 @@ const StoreManagement = () => {
const closeModal = (status, val) => { const closeModal = (status, val) => {
if (status) { if (status) {
const pageInfo = { const pageInfo = {
page: 1, current: 1,
size: 10, pageSize: 10,
}; };
setPage(pageInfo); setPage(pageInfo);
shopList({ data: searchForm, ...pageInfo }); shopList({ data: searchForm, ...pageInfo });
...@@ -77,12 +87,13 @@ const StoreManagement = () => { ...@@ -77,12 +87,13 @@ const StoreManagement = () => {
setIsStore(false); setIsStore(false);
setEditVisible(false); setEditVisible(false);
setRepastType([]); setRepastType([]);
setSelectMealType([]);
return; return;
} }
setName(false); setName(false);
setAddVisible(false); setAddVisible(false);
}; };
const setMealTypeList = async id => { const getMealTypeList = async id => {
const res = await mealTypeList({ id }); const res = await mealTypeList({ id });
if (res.businessCode === '0000') { if (res.businessCode === '0000') {
const resData = res.data; const resData = res.data;
...@@ -100,9 +111,10 @@ const StoreManagement = () => { ...@@ -100,9 +111,10 @@ const StoreManagement = () => {
} }
}; };
// 修改餐饮类型 // 修改餐饮类型
const editRepastType = ({ id }) => { const editRepastType = ({ id, mealType }) => {
setSelectMealType(mealType);
setRepastId(id); setRepastId(id);
setMealTypeList(id); getMealTypeList(id);
}; };
// 删除 // 删除
const editShop = async id => { const editShop = async id => {
...@@ -126,6 +138,15 @@ const StoreManagement = () => { ...@@ -126,6 +138,15 @@ const StoreManagement = () => {
}); });
}; };
const onChange = (value, option) => { const onChange = (value, option) => {
setFirstEnterprise(value);
const values = formRef.current.getFieldsValue();
const pageInfo = {
current: 1,
pageSize: 10,
};
setPage(pageInfo);
setSearchForm(values);
shopList({ ...pageInfo, data: values });
setEnterprise(option); setEnterprise(option);
}; };
// 添加商户 // 添加商户
...@@ -140,8 +161,8 @@ const StoreManagement = () => { ...@@ -140,8 +161,8 @@ const StoreManagement = () => {
const onFinish = async values => { const onFinish = async values => {
setSearchForm(values); setSearchForm(values);
const pageInfo = { const pageInfo = {
page: 1, current: 1,
size: 10, pageSize: 10,
}; };
setPage(pageInfo); setPage(pageInfo);
shopList({ data: values, ...pageInfo }); shopList({ data: values, ...pageInfo });
...@@ -150,18 +171,18 @@ const StoreManagement = () => { ...@@ -150,18 +171,18 @@ const StoreManagement = () => {
const onReset = () => { const onReset = () => {
formRef.current.resetFields(); formRef.current.resetFields();
const pageInfo = { const pageInfo = {
page: 1, current: 1,
size: 10, pageSize: 10,
}; };
setPage(pageInfo); setPage(pageInfo);
setSearchForm({ enterpriseId: firstEnterprise }); setSearchForm({ enterpriseId: firstEnterprise });
shopList({ data: { enterpriseId: firstEnterprise }, ...pageInfo }); shopList({ data: { enterpriseId: firstEnterprise }, ...pageInfo });
}; };
// 分页 // 分页
const handleTableChange = (pageNo, size) => { const handleTableChange = (current, pageSize) => {
const pageInfo = { const pageInfo = {
page: pageNo, current,
size, pageSize,
}; };
setPage(pageInfo); setPage(pageInfo);
shopList({ data: searchForm, ...pageInfo }); shopList({ data: searchForm, ...pageInfo });
...@@ -249,6 +270,7 @@ const StoreManagement = () => { ...@@ -249,6 +270,7 @@ const StoreManagement = () => {
rowKey={r => r.id} rowKey={r => r.id}
bordered bordered
pagination={pagination} pagination={pagination}
loading={loading}
/> />
</Card> </Card>
<EditRepastModal <EditRepastModal
...@@ -258,7 +280,9 @@ const StoreManagement = () => { ...@@ -258,7 +280,9 @@ const StoreManagement = () => {
onCancel={closeModal} onCancel={closeModal}
enterpriseId={searchForm.enterpriseId} enterpriseId={searchForm.enterpriseId}
isStore={isStore} isStore={isStore}
selectMealType={selectMealType}
/> />
<AddModal <AddModal
addVisible={addVisible} addVisible={addVisible}
enterpriseId={searchForm.enterpriseId} enterpriseId={searchForm.enterpriseId}
......
...@@ -2,12 +2,17 @@ import request from '@/utils/request'; ...@@ -2,12 +2,17 @@ import request from '@/utils/request';
import config from '../../../config/env.config'; import config from '../../../config/env.config';
import { stringify } from 'qs'; import { stringify } from 'qs';
import _ from 'lodash'; import _ from 'lodash';
import { de } from 'date-fns/locale';
const { goodsApi, apiPrefix, roleApi } = config; const { goodsApi, apiPrefix, roleApi } = config;
console.log(apiPrefix, 'apiPrefix'); console.log(apiPrefix, 'apiPrefix');
// [企业店铺]-列表查询 // [企业店铺]-列表查询
// http://yapi.quantgroups.com/project/389/interface/api/65284 // http://yapi.quantgroups.com/project/389/interface/api/65284
export const setShopList = async params => { export const setShopList = async params => {
params.page = params.current;
params.size = params.pageSize;
delete params.current;
delete params.pageSize;
const data = await request.post(`${apiPrefix}/enterprise/shop/list`, { const data = await request.post(`${apiPrefix}/enterprise/shop/list`, {
prefix: roleApi, prefix: roleApi,
data: params, data: params,
......
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