index.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. import React, { Component } from "react";
  2. import $ from "jquery/src/ajax";
  3. import { Button, Form, Icon, Input, message, Modal, Spin, Table, Tabs, TimePicker, InputNumber, Popconfirm } from "antd";
  4. import moment from 'moment';
  5. import { getCondition } from "../../../tools";
  6. import { data } from "jquery";
  7. const { TabPane } = Tabs
  8. const FormItem = Form.Item
  9. class WorkeTimes extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. list: [],
  14. loading: false,
  15. timeTypeId: '',
  16. start: '08:30',
  17. restStart: '12:00',
  18. restEnd: '13:30',
  19. end: '17:30',
  20. typeNum: '',
  21. minHours: '4',
  22. columns: [
  23. {
  24. title: '类型名称',
  25. dataIndex: 'name',
  26. key: 'name',
  27. },
  28. {
  29. title: '类型代号',
  30. dataIndex: 'type',
  31. key: 'type',
  32. },
  33. {
  34. title: '上班时间',
  35. dataIndex: 'start',
  36. key: 'start',
  37. },
  38. {
  39. title: '下班时间',
  40. dataIndex: 'end',
  41. key: 'end',
  42. },
  43. {
  44. title: '午休开始时间',
  45. dataIndex: 'restStart',
  46. key: 'restStart',
  47. },
  48. {
  49. title: '午休结束时间',
  50. dataIndex: 'restEnd',
  51. key: 'restEnd',
  52. },
  53. {
  54. title: '最小公出时长(小时)',
  55. dataIndex: 'minHours',
  56. key: 'minHours',
  57. },
  58. {
  59. title: '操作',
  60. dataIndex: 'id',
  61. key: 'id',
  62. render: (text, record) => {
  63. return (
  64. <div>
  65. <Popconfirm
  66. title="是否删除?"
  67. onConfirm={_ => {
  68. this.remove(text);
  69. }}
  70. okText="删除"
  71. cancelText="不删除"
  72. >
  73. <Button loading={this.state.removeLoading} type='dashed' onClick={(e) => { e.stopPropagation() }}>删除</Button>
  74. </Popconfirm>
  75. <Button style={{ marginLeft: 20 }} type='primary' onClick={(e) => { e.stopPropagation(), this.edit(record) }}>修改</Button>
  76. </div>
  77. )
  78. }
  79. }
  80. ]
  81. }
  82. this.loadData = this.loadData.bind(this);
  83. this.submit = this.submit.bind(this);
  84. this.remove = this.remove.bind(this);
  85. this.onCancel = this.onCancel.bind(this);
  86. }
  87. loadData() {
  88. this.setState({
  89. loading: true,
  90. });
  91. $.ajax({
  92. method: "get",
  93. dataType: "json",
  94. crossDomain: false,
  95. url: globalConfig.context + '/api/admin/department/workingHours/list',
  96. data: {},
  97. success: function (data) {
  98. if (data.error.length === 0) {
  99. this.setState({
  100. list: data.data
  101. })
  102. } else {
  103. message.warning(data.error[0].message)
  104. }
  105. }.bind(this),
  106. }).always(function () {
  107. this.setState({
  108. loading: false
  109. });
  110. }.bind(this));
  111. }
  112. submit() {
  113. if (!this.state.typeName) {
  114. message.warning('请填写类型名称')
  115. return;
  116. }
  117. if (!this.state.typeNum && this.state.typeNum != 0) {
  118. message.warning('请填写类型代号')
  119. return;
  120. }
  121. if (!this.state.start) {
  122. message.warning('请选择上班时间')
  123. return;
  124. }
  125. if (!this.state.restStart) {
  126. message.warning('请选择午休开始时间')
  127. return;
  128. }
  129. if (!this.state.restEnd) {
  130. message.warning('请选择午休结束时间')
  131. return;
  132. }
  133. if (!this.state.end) {
  134. message.warning('请选择下班时间')
  135. return;
  136. }
  137. if (!this.state.minHours && this.state.minHours != 0) {
  138. message.warning('请填写最小公出时长')
  139. return;
  140. }
  141. this.setState({
  142. addLoading: true
  143. })
  144. $.ajax({
  145. method: "post",
  146. dataType: "json",
  147. crossDomain: false,
  148. url: globalConfig.context +
  149. (!this.state.timeTypeId
  150. ? '/api/admin/department/workingHours/add'
  151. : '/api/admin/department/workingHours/update'),
  152. data: {
  153. id: !this.state.timeTypeId ? undefined : this.state.timeTypeId,
  154. name: this.state.typeName,
  155. start: this.state.start,
  156. restStart: this.state.restStart,
  157. restEnd: this.state.restEnd,
  158. end: this.state.end,
  159. type: this.state.typeNum,
  160. minHours: this.state.minHours,
  161. },
  162. }).done(function (data) {
  163. this.setState({
  164. addLoading: false
  165. });
  166. if (data.error.length === 0) {
  167. message.success('操作成功!');
  168. this.onCancel();
  169. this.loadData();
  170. } else {
  171. message.warning(data.error[0].message);
  172. }
  173. }.bind(this));
  174. }
  175. remove(id) {
  176. this.setState({
  177. removeLoading: true
  178. })
  179. $.ajax({
  180. method: "post",
  181. dataType: "json",
  182. crossDomain: false,
  183. url: globalConfig.context + '/api/admin/department/workingHours/delete',
  184. data: {
  185. id
  186. }
  187. }).done(function (data) {
  188. this.setState({
  189. removeLoading: false
  190. });
  191. if (data.error.length === 0) {
  192. message.success('删除成功!');
  193. this.loadData();
  194. } else {
  195. message.warning(data.error[0].message);
  196. }
  197. }.bind(this));
  198. }
  199. edit(obj) {
  200. this.setState({
  201. visible: true,
  202. timeTypeId: obj.id,
  203. typeName: obj.name,
  204. typeNum: obj.type,
  205. start: obj.start,
  206. end: obj.end,
  207. restStart: obj.restStart,
  208. restEnd: obj.restEnd,
  209. minHours: obj.minHours,
  210. })
  211. }
  212. onCancel() {
  213. this.setState({
  214. visible: false,
  215. typeName: '',
  216. timeTypeId: '',
  217. start: '08:30',
  218. restStart: '12:00',
  219. restEnd: '13:30',
  220. end: '17:30',
  221. typeNum: '',
  222. minHours: '4',
  223. })
  224. }
  225. componentDidMount() {
  226. this.loadData();
  227. }
  228. render() {
  229. return (
  230. <div className="user-content" >
  231. <div className="content-title">
  232. <Tabs
  233. defaultActiveKey="1"
  234. className="test">
  235. <TabPane tab="操作" key="1">
  236. <div className="user-search">
  237. <Button
  238. type="primary"
  239. className="addButton"
  240. onClick={() => {
  241. this.setState({
  242. visible: true,
  243. timeTypeId: '',
  244. })
  245. }}
  246. style={{ marginBottom: '10px', float: 'left' }}>
  247. 新增
  248. <Icon type="plus" />
  249. </Button>
  250. </div>
  251. </TabPane>
  252. </Tabs>
  253. </div>
  254. <div className="patent-table">
  255. <Spin spinning={this.state.loading}>
  256. <Table size="middle" columns={this.state.columns}
  257. dataSource={this.state.list}
  258. style={{
  259. cursor: 'pointer',
  260. }}
  261. pagination={null}
  262. onRowClick={() => {
  263. }} />
  264. </Spin>
  265. </div>
  266. <Modal
  267. maskClosable={false}
  268. visible={this.state.visible}
  269. onOk={this.onCancel}
  270. onCancel={this.onCancel}
  271. width='600px'
  272. title={this.state.timeTypeId ? '编辑作息时间' : '增加作息时间'}
  273. footer=''
  274. className="admin-desc-content">
  275. <div>
  276. <div className="clearfix">
  277. <FormItem
  278. labelCol={{ span: 7 }}
  279. wrapperCol={{ span: 12 }}
  280. label="类型名称" >
  281. <Input placeholder="请填写组织名称" value={this.state.typeName}
  282. onChange={(e) => { this.setState({ typeName: e.target.value }) }} />
  283. </FormItem>
  284. </div>
  285. <div className="clearfix">
  286. <FormItem
  287. labelCol={{ span: 7 }}
  288. wrapperCol={{ span: 12 }}
  289. label="类型代号" >
  290. <InputNumber
  291. style={{ width: '100px' }}
  292. min={0}
  293. placeholder="请填写类型代号"
  294. value={this.state.typeNum}
  295. onChange={(e) => {
  296. this.setState({ typeNum: e })
  297. }} />
  298. </FormItem>
  299. </div>
  300. <div className="clearfix">
  301. <FormItem
  302. labelCol={{ span: 7 }}
  303. wrapperCol={{ span: 12 }}
  304. label="上班时间" >
  305. <TimePicker defaultValue={moment('8:30', 'HH:mm')} value={moment(this.state.start, 'HH:mm')} format='HH:mm' onChange={(time, timeString) => {
  306. this.setState({
  307. start: timeString
  308. })
  309. }} />
  310. </FormItem>
  311. </div>
  312. <div className="clearfix">
  313. <FormItem
  314. labelCol={{ span: 7 }}
  315. wrapperCol={{ span: 12 }}
  316. label="下班时间" >
  317. <TimePicker defaultValue={moment('17:30', 'HH:mm')} value={moment(this.state.end, 'HH:mm')} format='HH:mm' onChange={(time, timeString) => {
  318. this.setState({
  319. end: timeString
  320. })
  321. }} />
  322. </FormItem>
  323. </div>
  324. <div className="clearfix">
  325. <FormItem
  326. labelCol={{ span: 7 }}
  327. wrapperCol={{ span: 12 }}
  328. label="午休开始时间" >
  329. <TimePicker defaultValue={moment('12:00', 'HH:mm')} value={moment(this.state.restStart, 'HH:mm')} format='HH:mm' onChange={(time, timeString) => {
  330. this.setState({
  331. restStart: timeString
  332. })
  333. }} />
  334. </FormItem>
  335. </div>
  336. <div className="clearfix">
  337. <FormItem
  338. labelCol={{ span: 7 }}
  339. wrapperCol={{ span: 12 }}
  340. label="午休结束时间" >
  341. <TimePicker
  342. format='HH:mm'
  343. defaultValue={moment('13:30', 'HH:mm')}
  344. value={moment(this.state.restEnd, 'HH:mm')}
  345. onChange={(time, timeString) => {
  346. this.setState({
  347. restEnd: timeString
  348. })
  349. }} />
  350. </FormItem>
  351. </div>
  352. <div className="clearfix">
  353. <FormItem
  354. labelCol={{ span: 7 }}
  355. wrapperCol={{ span: 12 }}
  356. label="最小公出时长" >
  357. <InputNumber
  358. style={{ width: '100px' }}
  359. min={0}
  360. placeholder="请填写最小公出时长(小时)"
  361. value={this.state.minHours}
  362. onChange={(e) => {
  363. this.setState({ minHours: e })
  364. }} />
  365. </FormItem>
  366. </div>
  367. <div className="clearfix" style={{ display: 'flex', justifyContent: 'center' }}>
  368. <Button type="primary" onClick={this.submit} loading={this.state.addLoading}>
  369. 确定添加
  370. </Button>
  371. </div>
  372. </div>
  373. </Modal>
  374. </div>
  375. )
  376. }
  377. }
  378. export default WorkeTimes;