index.jsx 13 KB

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