Commit 3326caed authored by lvxiaowu's avatar lvxiaowu

x

parent 6416f980
export default function(t) {
let y = t.getFullYear()
let mm = t.getMonth()
let dd = t.getDate()
let m = mm+1 < 10 ? `0${mm+1}` : mm+1
let d = dd < 10 ? `0${dd}` : dd
return {y, m, d, mm, dd}
}
\ No newline at end of file
import moment from 'moment';
export function getTime(t) {
let y = t.getFullYear();
let mm = t.getMonth();
let dd = t.getDate();
let m = mm + 1 < 10 ? `0${mm + 1}` : mm + 1;
let d = dd < 10 ? `0${dd}` : dd;
return { y, m, d, mm, dd };
}
export function fixedZero(val) {
return val * 1 < 10 ? `0${val}` : val;
}
export function getTimeDistance(type) {
const now = new Date();
const oneDay = 1000 * 60 * 60 * 24;
if (type === 'today') {
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
return [moment(now), moment(now.getTime() + (oneDay - 1000))];
}
if (type === 'week') {
let day = now.getDay();
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
if (day === 0) {
day = 6;
} else {
day -= 1;
}
const beginTime = now.getTime() - day * oneDay;
return [moment(beginTime), moment(beginTime + (7 * oneDay - 1000))];
}
if (type === 'month') {
const year = now.getFullYear();
const month = now.getMonth();
const nextDate = moment(now).add(1, 'months');
const nextYear = nextDate.year();
const nextMonth = nextDate.month();
return [
moment(`${year}-${fixedZero(month + 1)}-01 00:00:00`),
moment(
moment(
`${nextYear}-${fixedZero(nextMonth + 1)}-01 00:00:00`
).valueOf() - 1000
)
];
}
const year = now.getFullYear();
return [moment(`${year}-01-01 00:00:00`), moment(`${year}-12-31 23:59:59`)];
}
......@@ -4,7 +4,7 @@ import { Menu, Dropdown, Modal, Input, message, Button } from 'antd';
import { DownOutlined } from '@ant-design/icons';
import { api } from '../common/fetch';
const AccountName: React.FC = props => {
const AccountName: React.FC = () => {
const [pwdModal, set_pwdModal] = useState(false);
const [logout, set_logout] = useState(false);
const [confirm_password, set_confirm_password] = useState('');
......@@ -19,7 +19,7 @@ const AccountName: React.FC = props => {
const { Item } = Menu;
const menu = (
<Menu>
<Item onClick={() => set_logout(true)}>修改密码</Item>
{/* <Item onClick={() => set_logout(true)}>修改密码</Item> */}
<Item onClick={() => set_pwdModal(true)}>退出登录</Item>
</Menu>
);
......
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { Layout, Menu } from 'antd';
import { Link } from 'react-router-dom';
......@@ -14,30 +14,40 @@ interface ConfigI {
const MenuBar: React.FC<ConfigI> = props => {
const [defKey, set_defKey] = useState('1');
const [openKey, set_openKey] = useState('');
useEffect(() => {
let menu_defKey = window.sessionStorage.getItem('menu_defKey') || '1';
let menu_openKey = window.sessionStorage.getItem('menu_openKey') || '1';
// console.log('menu_defKey', menu_defKey);
// console.log('menu_openKey', menu_openKey);
set_defKey(menu_defKey);
set_openKey(menu_openKey);
}, []);
const routerConf = [
{
path: '/orderList',
title: '订单列表',
key: '1',
title: '订单列表',
path: '/orderList',
icon: <PieChartOutlined />
},
{
key: '2',
title: '兑换码',
path: '',
key: 'sub1',
icon: <UserOutlined />,
subs: [
{
key: '2',
path: '/exchangeCode',
key: '3',
title: '兑换码列表',
path: '/exchangeCode',
icon: ''
},
{
key: '3',
path: '/generateCode',
key: '4',
title: '兑换码生成',
path: '/generateCode',
icon: ''
}
]
......@@ -68,6 +78,10 @@ const MenuBar: React.FC<ConfigI> = props => {
const handleClick = (data: any) => {
set_defKey(data.key);
let keyPath = data.keyPath[data.keyPath.length - 1];
set_openKey(keyPath);
window.sessionStorage.setItem('menu_defKey', data.key);
window.sessionStorage.setItem('menu_openKey', keyPath);
};
return (
......@@ -93,7 +107,9 @@ const MenuBar: React.FC<ConfigI> = props => {
)}
<Menu
theme="dark"
defaultSelectedKeys={['1']}
defaultSelectedKeys={[defKey]}
// defaultOpenKeys={['2']}
defaultOpenKeys={[openKey]}
selectedKeys={[defKey]}
mode="inline"
onClick={handleClick}
......
import React, { useState } from 'react';
import moment from 'moment';
import React, { useState, useEffect } from 'react';
import { Input, Button, Form, Row, Col } from 'antd';
import { Link } from 'react-router-dom';
import 'moment/locale/zh-cn';
import BasicPage from '../../layout/basicPage';
import List from './list';
// import { api } from '../../common/fetch';
import List from './list';
import excelFn from '../../common/excel';
import { api } from '../../common/fetch';
import BasicPage from '../../layout/basicPage';
// style
import './index.scss';
const FormItem = Form.Item;
moment.locale('zh-cn');
const PAGE_SIZE = 10;
const Order: React.FC = () => {
const ExchangeCode: React.FC = () => {
const [courseName, set_courseName] = useState('');
const [current, set_current] = useState(1);
const [pageSize, set_pageSize] = useState(PAGE_SIZE);
const [form] = Form.useForm();
useEffect(() => {
getList(courseName, current, pageSize);
}, []);
console.log(courseName);
// useEffect(() => {}, []);
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 10 },
md: { span: 10 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 },
md: { span: 16 }
const getList = (courseName: string, current: number, pageSize: number) => {
api(`/yizhi_server/api/account/analyse`, {
type: 'GET',
data: {
courseName: courseName,
pageSize: pageSize,
page: current
}
}).then(r => {
console.log(r);
});
};
const download = () => {
console.log('xiazai');
};
const onFinish = (values: any) => {
for (let i in values) {
if (!values[i]) delete values[i];
}
console.log('Success:', values);
api('/yizhi_server/api/account/analyse/download', {
type: 'GET',
data: {
product: 'JSON.stringify(info.product)'
},
responseType: 'arrayBuffer'
}).then(r => {
excelFn(r, `分析明细`);
});
};
const onFinishFailed = (errorInfo: any) => {
console.log('Failed:', errorInfo);
const submitData = () => {
getList(courseName, 1, pageSize);
};
const resetData = () => {
form.resetFields();
set_courseName('');
// set_current(1);
// set_pageSize(pageSize);
// set_courseName('');
getList('', 1, pageSize);
};
const handleTableChange = (args: any) => {
console.log(args);
// set_current(args.current);
// set_pageSize(args.pageSize);
getList(courseName, args.current, args.pageSize);
};
let dataSource = [];
......@@ -71,17 +76,12 @@ const Order: React.FC = () => {
return (
<BasicPage>
<div className="analy-content">
<Form
{...formItemLayout}
form={form}
onFinish={onFinish}
onFinishFailed={onFinishFailed}
>
<div className="content">
<Row {...{ gutter: { xs: 8, sm: 16, md: 24 } }}>
<Col>
<FormItem label="已购课程名称:" name="courseName">
<Col md={6} sm={12}>
<FormItem label="已购课程名称:">
<Input
value={courseName}
placeholder="请输入"
onChange={e => {
set_courseName(e.target.value);
......@@ -89,11 +89,10 @@ const Order: React.FC = () => {
/>
</FormItem>
</Col>
<Col md={12} sm={24}>
<Form.Item>
<Col md={6} sm={12}>
<Button
type="primary"
htmlType="submit"
onClick={submitData}
style={{ marginRight: '12px' }}
>
查询
......@@ -101,7 +100,6 @@ const Order: React.FC = () => {
<Button htmlType="button" onClick={resetData}>
重置
</Button>
</Form.Item>
</Col>
</Row>
<Row
......@@ -121,11 +119,15 @@ const Order: React.FC = () => {
</Button>
</Col>
</Row>
</Form>
</div>
<List dataSource={dataSource} handleTableChange={handleTableChange} />
<List
dataSource={dataSource}
handleTableChange={handleTableChange}
pageSize={pageSize}
current={current}
/>
</BasicPage>
);
};
export default Order;
export default ExchangeCode;
......@@ -18,6 +18,8 @@ interface ColsI {
interface DataSourceI {
dataSource: DeatilI[];
pageSize: number;
current: number;
handleTableChange: any;
}
......@@ -63,7 +65,8 @@ const List: React.FC<DataSourceI> = props => {
rowKey={record => record.id || 'key'}
onChange={props.handleTableChange}
pagination={{
pageSize: 1,
pageSize: props.pageSize,
current: props.current,
showSizeChanger: true,
showTotal: (total, range) =>
`${range[1] - range[0] + 1} of ${total} items`
......
import React from 'react';
import { Table } from 'antd';
const { Column } = Table;
interface DeatilI {
id: string | number;
courseName: string | number;
code: string | number;
status: string | number;
date: string;
}
interface ColsI {
title: string;
dataIndex: string;
key: string | number;
}
interface DataSourceI {
dataSource: DeatilI[];
handleTableChange: any;
}
const columns = [
{
title: '课程ID',
dataIndex: 'id',
key: 'id'
},
{
title: '课程名称',
dataIndex: 'courseName',
key: 'courseName'
},
{
title: '兑换码',
dataIndex: 'code',
key: 'code'
},
{
title: '兑换情况',
dataIndex: 'status',
key: 'status'
},
{
title: '兑换时间',
dataIndex: 'date',
key: 'date'
}
];
const Cols = (list: ColsI[]) => {
return list.map((item: any) => {
return <Column {...item} key={item.key} />;
});
};
const List: React.FC<DataSourceI> = props => {
return (
<div style={{ padding: '30px' }}>
<Table
dataSource={props.dataSource}
onChange={props.handleTableChange}
pagination={{
pageSize: 1,
showSizeChanger: true,
showTotal: (total, range) =>
`${range[1] - range[0] + 1} of ${total} items`
}}
>
{Cols(columns)}
</Table>
</div>
);
};
export default List;
......@@ -63,7 +63,7 @@ const Login: React.FC<RouteComponentProps> = () => {
if (res) {
window.sessionStorage.setItem('token', res.token);
window.sessionStorage.setItem('user', passport);
history.push('/home');
history.push('/orderList');
}
})
.catch(e => {
......@@ -104,7 +104,7 @@ const Login: React.FC<RouteComponentProps> = () => {
fontWeight: 'bold'
}}
>
趣选课合作机构平
趣选课供销后
</h3>
</div>
<div className="loginItem">
......
import React, { useState } from 'react';
import BasicPage from '../../layout/basicPage';
import React, { useState, useEffect, useRef } from 'react';
import locale from 'antd/es/date-picker/locale/zh_CN';
import moment from 'moment';
import List from './list';
// import excelFn from '../../common/excel';
import { Input, Button, Form, DatePicker, Row, Col } from 'antd';
import 'moment/locale/zh-cn';
// import { api } from '../../common/fetch';
import List from './list';
import BasicPage from '../../layout/basicPage';
import excelFn from '../../common/excel';
import { api } from '../../common/fetch';
// style
import './index.scss';
......@@ -15,16 +15,27 @@ const FormItem = Form.Item;
const { RangePicker } = DatePicker;
moment.locale('zh-cn');
const Order: React.FC = () => {
const PAGE_SIZE = 10;
interface FilterData {
courseName?: string;
userName?: string;
start_date?: string;
end_date?: string;
current?: number;
pageSize?: number;
}
const OrderList: React.FC = () => {
const [courseName, set_courseName] = useState('');
const [userName, set_userName] = useState('');
const [dates, setDates] = useState([] as any);
const [start_date, set_startDate] = useState('');
const [end_date, set_endDate] = useState('');
console.log(courseName, userName, dates);
const [form] = Form.useForm();
// useEffect(() => {}, []);
const [current, set_current] = useState(1);
const [pageSize, set_pageSize] = useState(PAGE_SIZE);
const [form] = Form.useForm();
const formItemLayout = {
labelCol: {
xs: { span: 24 },
......@@ -33,42 +44,101 @@ const Order: React.FC = () => {
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 },
md: { span: 16 }
sm: { span: 18 },
md: { span: 18 }
}
};
useEffect(() => {
getList({ courseName, userName, start_date, end_date, current, pageSize });
}, []);
const getList = ({
courseName = '',
userName = '',
start_date = '',
end_date = '',
current = 1,
pageSize = PAGE_SIZE
}: FilterData) => {
api(`/yizhi_server/api/account/analyse`, {
type: 'GET',
data: {
courseName,
userName,
start_date,
end_date,
page: current,
pageSize: pageSize
}
}).then(r => {
console.log(r);
});
};
const download = () => {
console.log('xiazai');
// excelFn()
api('/yizhi_server/api/account/analyse/download', {
type: 'GET',
data: {
courseName,
userName,
start_date,
end_date,
product: 'JSON.stringify(info.product)'
},
responseType: 'arrayBuffer'
}).then(r => {
excelFn(r, `分析明细${start_date}_${end_date}`);
});
};
const onFinish = (values: any) => {
for (let i in values) {
if (!values[i]) delete values[i];
if (values[i] && Array.isArray(values[i]) && values[i].length === 2) {
let date = values[i];
values.start_time = moment(date[0]).format('YYYY-MM-DD');
values.end_time = moment(date[1]).format('YYYY-MM-DD');
delete values[i];
}
const changeValue = (type: string, val: any) => {
let obj: any = {
courseName: () => set_courseName(val),
userName: () => set_userName(val),
dates: () => {
let start_date = (val && moment(val[0]).format('YYYY-MM-DD')) || '';
let end_date = (val && moment(val[1]).format('YYYY-MM-DD')) || '';
set_startDate(start_date);
set_endDate(end_date);
}
console.log('Success:', values);
};
const onFinishFailed = (errorInfo: any) => {
console.log('Failed:', errorInfo);
obj[type] && obj[type]();
};
const resetData = () => {
form.resetFields();
set_courseName('');
set_userName('');
setDates([]);
changeValue('courseName', '');
changeValue('userName', '');
set_current(1);
set_pageSize(PAGE_SIZE);
getList({});
};
const handleTableChange = (args: any) => {
console.log(args);
set_current(args.current);
set_pageSize(args.pageSize);
getList({
courseName,
userName,
start_date,
end_date,
current: args.current,
pageSize: args.pageSize
});
};
const onFinish = () => {
set_current(1);
set_pageSize(PAGE_SIZE);
getList({
courseName,
userName,
start_date,
end_date,
current: 1,
pageSize: PAGE_SIZE
});
};
let dataSource = [];
......@@ -88,39 +158,34 @@ const Order: React.FC = () => {
return (
<BasicPage>
<div className="analy-content">
<Form
{...formItemLayout}
form={form}
onFinish={onFinish}
onFinishFailed={onFinishFailed}
>
<Form {...formItemLayout} form={form} onFinish={onFinish}>
<Row {...{ gutter: { xs: 8, sm: 16, md: 24 } }}>
<Col>
<Col span="6">
<FormItem label="已购课程名称:" name="courseName">
<Input
placeholder="请输入"
onChange={e => {
set_courseName(e.target.value);
changeValue('courseName', e.target.value);
}}
/>
</FormItem>
</Col>
<Col>
<Col span="6">
<FormItem label="用户姓名:" name="userName">
<Input
placeholder="请输入"
onChange={e => {
set_userName(e.target.value);
changeValue('userName', e.target.value);
}}
/>
</FormItem>
</Col>
<Col>
<Col span="6">
<FormItem label="下单时间:" name="dates">
<RangePicker
locale={locale}
onCalendarChange={value => {
setDates(value);
changeValue('dates', value);
}}
/>
</FormItem>
......@@ -156,9 +221,14 @@ const Order: React.FC = () => {
</Row>
</Form>
</div>
<List dataSource={dataSource} handleTableChange={handleTableChange} />
<List
dataSource={dataSource}
pageSize={pageSize}
current={current}
handleTableChange={handleTableChange}
/>
</BasicPage>
);
};
export default Order;
export default OrderList;
......@@ -21,6 +21,8 @@ interface ColsI {
interface DataSourceI {
dataSource: DeatilI[];
pageSize: number;
current: number;
handleTableChange: any;
}
......@@ -29,37 +31,37 @@ const columns = [
title: '订单号',
dataIndex: 'orderNumber',
key: 'orderNumber'
},
{
title: '已购课程名称',
dataIndex: 'courseName',
key: 'courseName'
},
{
title: '用户姓名',
dataIndex: 'userName',
key: 'userName'
},
{
title: '收货地址',
dataIndex: 'address',
key: 'address'
},
{
title: '联系电话',
dataIndex: 'phone',
key: 'phone'
},
{
title: '付款金额(元)',
dataIndex: 'money',
key: 'money'
},
{
title: '下单时间',
dataIndex: 'date',
key: 'date'
}
// {
// title: '已购课程名称',
// dataIndex: 'courseName',
// key: 'courseName'
// },
// {
// title: '用户姓名',
// dataIndex: 'userName',
// key: 'userName'
// },
// {
// title: '收货地址',
// dataIndex: 'address',
// key: 'address'
// },
// {
// title: '联系电话',
// dataIndex: 'phone',
// key: 'phone'
// },
// {
// title: '付款金额(元)',
// dataIndex: 'money',
// key: 'money'
// },
// {
// title: '下单时间',
// dataIndex: 'date',
// key: 'date'
// }
];
const Cols = (list: ColsI[]) => {
......@@ -76,7 +78,8 @@ const List: React.FC<DataSourceI> = props => {
dataSource={props.dataSource}
onChange={props.handleTableChange}
pagination={{
pageSize: 1,
pageSize: props.pageSize,
current: props.current,
showSizeChanger: true,
showTotal: (total, range) =>
`${range[1] - range[0] + 1} of ${total} items`
......
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