import React, { Component } from "react";
import $ from "jquery/src/ajax";
import { Button, Form, Icon, Input, message, Modal, Spin, Table, Tabs, TimePicker, InputNumber, Popconfirm } from "antd";
import moment from 'moment';
import { getCondition } from "../../../tools";
import { data } from "jquery";
const { TabPane } = Tabs
const FormItem = Form.Item
class WorkeTimes extends Component {
constructor(props) {
super(props);
this.state = {
list: [],
loading: false,
timeTypeId: '',
start: '08:30',
restStart: '12:00',
restEnd: '13:30',
end: '17:30',
typeNum: '',
minHours: '4',
columns: [
{
title: '类型名称',
dataIndex: 'name',
key: 'name',
},
{
title: '类型代号',
dataIndex: 'type',
key: 'type',
},
{
title: '上班时间',
dataIndex: 'start',
key: 'start',
},
{
title: '下班时间',
dataIndex: 'end',
key: 'end',
},
{
title: '午休开始时间',
dataIndex: 'restStart',
key: 'restStart',
},
{
title: '午休结束时间',
dataIndex: 'restEnd',
key: 'restEnd',
},
{
title: '最小公出时长(小时)',
dataIndex: 'minHours',
key: 'minHours',
},
{
title: '操作',
dataIndex: 'id',
key: 'id',
render: (text, record) => {
return (
{
this.remove(text);
}}
okText="删除"
cancelText="不删除"
>
)
}
}
]
}
this.loadData = this.loadData.bind(this);
this.submit = this.submit.bind(this);
this.remove = this.remove.bind(this);
this.onCancel = this.onCancel.bind(this);
}
loadData() {
this.setState({
loading: true,
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + '/api/admin/department/workingHours/list',
data: {},
success: function (data) {
if (data.error.length === 0) {
this.setState({
list: data.data
})
} else {
message.warning(data.error[0].message)
}
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
}
submit() {
if (!this.state.typeName) {
message.warning('请填写类型名称')
return;
}
if (!this.state.typeNum && this.state.typeNum != 0) {
message.warning('请填写类型代号')
return;
}
if (!this.state.start) {
message.warning('请选择上班时间')
return;
}
if (!this.state.restStart) {
message.warning('请选择午休开始时间')
return;
}
if (!this.state.restEnd) {
message.warning('请选择午休结束时间')
return;
}
if (!this.state.end) {
message.warning('请选择下班时间')
return;
}
if (!this.state.minHours && this.state.minHours != 0) {
message.warning('请填写最小公出时长')
return;
}
this.setState({
addLoading: true
})
$.ajax({
method: "post",
dataType: "json",
crossDomain: false,
url: globalConfig.context +
(!this.state.timeTypeId
? '/api/admin/department/workingHours/add'
: '/api/admin/department/workingHours/update'),
data: {
id: !this.state.timeTypeId ? undefined : this.state.timeTypeId,
name: this.state.typeName,
start: this.state.start,
restStart: this.state.restStart,
restEnd: this.state.restEnd,
end: this.state.end,
type: this.state.typeNum,
minHours: this.state.minHours,
},
}).done(function (data) {
this.setState({
addLoading: false
});
if (data.error.length === 0) {
message.success('操作成功!');
this.onCancel();
this.loadData();
} else {
message.warning(data.error[0].message);
}
}.bind(this));
}
remove(id) {
this.setState({
removeLoading: true
})
$.ajax({
method: "post",
dataType: "json",
crossDomain: false,
url: globalConfig.context + '/api/admin/department/workingHours/delete',
data: {
id
}
}).done(function (data) {
this.setState({
removeLoading: false
});
if (data.error.length === 0) {
message.success('删除成功!');
this.loadData();
} else {
message.warning(data.error[0].message);
}
}.bind(this));
}
edit(obj) {
this.setState({
visible: true,
timeTypeId: obj.id,
typeName: obj.name,
typeNum: obj.type,
start: obj.start,
end: obj.end,
restStart: obj.restStart,
restEnd: obj.restEnd,
minHours: obj.minHours,
})
}
onCancel() {
this.setState({
visible: false,
typeName: '',
timeTypeId: '',
start: '08:30',
restStart: '12:00',
restEnd: '13:30',
end: '17:30',
typeNum: '',
minHours: '4',
})
}
componentDidMount() {
this.loadData();
}
render() {
return (
{
}} />
{ this.setState({ typeName: e.target.value }) }} />
{
this.setState({ typeNum: e })
}} />
{
this.setState({
start: timeString
})
}} />
{
this.setState({
end: timeString
})
}} />
{
this.setState({
restStart: timeString
})
}} />
{
this.setState({
restEnd: timeString
})
}} />
{
this.setState({ minHours: e })
}} />
)
}
}
export default WorkeTimes;