import React, { Component } from 'react'; import { connect } from 'dva'; import vd from 'validator'; import { Form, Input, Row, Col, Button, Steps, Icon, Table, Modal, Notification, Breadcrumb, message, Alert } from 'antd'; import { Link } from 'dva/router'; import { gup } from '../../utils/utils'; import PMap from '../../components/Pro/PMap'; import bcx_utils from '../../common/bcx_utils'; import { taskAttendanceComAttendGroupInSecondStepAttendGroup, //进入内勤组设置-第二步页面 taskAttendanceComAttendGroupSaveSecondStepAttendGroup //新增或者修改内勤组-第二步-设置考勤地址 } from '../../services/api'; import './ThiftManagement.less'; const FormItem = Form.Item; const { Step } = Steps; const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 7 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 12 }, md: { span: 10 } } }; const submitFormLayout = { wrapperCol: { xs: { span: 24, offset: 0 }, sm: { span: 10, offset: 7 } } }; @connect(state => ({ profile: state.profile })) @Form.create() export default class Information extends Component { state = { point: [], address: '', visible: false, //添加地点 attendGroupId: gup('attendGroupId') || '', midAttendGroupId: gup('midAttendGroupId') + '' || '', addressRange: '300', comAttendAddressJson: [], pagenav: { current: 1, pageSize: 10, showQuickJumper: true, showSizeChanger: true, showTotal: total => `总共 ${total} 条`, onShowSizeChange: (current, pageSize) => { const pagenav = Object.assign({}, this.state.pagenav); pagenav.current = current; pagenav.pageSize = pageSize; this.setState({ pagenav }); setTimeout(() => { this.bbdExampersonPage(); }); }, onChange: (page, pageSize) => { const pagenav = Object.assign({}, this.state.pagenav); pagenav.current = page; pagenav.pageSize = pageSize; this.setState({ pagenav }); setTimeout(() => { this.bbdExampersonPage(); }); }, total: 0 } }; componentDidMount() { this.taskAttendanceComAttendGroupInSecondStepAttendGroup(); } taskAttendanceComAttendGroupSaveSecondStepAttendGroup = () => { const { midAttendGroupId, comAttendAddressJson, addressRange, attendGroupId } = this.state; taskAttendanceComAttendGroupSaveSecondStepAttendGroup({ midAttendGroupId, attendGroupId, comAttendAddressJson: JSON.stringify(comAttendAddressJson), addressRange }) .then(res => { this.props.history.push( `/attendancemanagement/newattendanceunit/settingupattendance?attendGroupId=${ res.data.attendGroupId }&midAttendGroupId=${res.data.midAttendGroupId}` ); }) .catch(err => console.log(err, '新增或者修改内勤组-第二步-设置考勤地址-err') ); }; taskAttendanceComAttendGroupInSecondStepAttendGroup = () => { taskAttendanceComAttendGroupInSecondStepAttendGroup({ midAttendGroupId: this.state.midAttendGroupId, attendGroupId: this.state.attendGroupId }) .then(res => { if (res.data) { const { addressRange, attendGroupId, midAttendGroupId } = res.data; let comAttendAddressJson = JSON.parse(res.data.comAttendAddressJson); comAttendAddressJson = comAttendAddressJson.map((val, i) => { const obj = { ...val }; obj.key = i; return obj; }); this.setState({ attendGroupId, midAttendGroupId, addressRange: addressRange || 300, comAttendAddressJson }); } }) .catch(err => console.log(err, '进入内勤组设置-第二步页面-err')); }; /* 考勤地点--drawer */ columns = [ { key: '1', title: '考勤地点', dataIndex: 'address', render: text => {text} }, { width: 60, title: '操作', dataIndex: 'b', render: (rext, record) => ( { const { comAttendAddressJson } = this.state; const newarr = comAttendAddressJson.filter(val => { return val.key !== record.key; }); this.setState({ comAttendAddressJson: newarr }); }} style={{ color: '#0F71FF' }} > 删除 ) } ]; handleSubmit = e => { e.preventDefault(); if (this.state.comAttendAddressJson.length === 0) { Notification.error({ message: '请选择考勤地点' }); return; } this.props.form.validateFieldsAndScroll(err => { if (!err) { this.taskAttendanceComAttendGroupSaveSecondStepAttendGroup(); } }); }; render() { const { submitting } = this.props; const { getFieldDecorator } = this.props.form; return (
内勤组管理 考勤方式
内勤组考勤地点,支持多个考勤地点,可点击“添加地点”进行新增;内勤组创建后,可再次编辑考勤地点。
} type="warning" showIcon style={{ marginBottom: '15px' }} />
可设置多个考勤地点 有效范围: {getFieldDecorator('addressRange', { initialValue: this.state.addressRange, rules: [ { required: true, message: '请输入' }, { validator: (rule, value, cb) => { if ( !vd.isNumeric(value + '') || value <= 0 || (value + '').length > 10 ) { cb('只能是正整数最长10位'); } // Note: 必须总是返回一个 callback,否则 validateFieldsAndScroll 无法响应 cb(); } } ] })( { this.setState({ addressRange: e.target.value }); }} addonAfter="米" placeholder="请输入" /> )} 提示:有效范围请勿设置过小,手机定位会受信号等因素影响偏移,造成无法打卡。 } type="warning" showIcon /> { let { comAttendAddressJson } = this.state; const { point, address } = this.state; if (address === '' || point.length === 0) { bcx_utils.preventRepeatAsync(callback => callback(resolve => { message.warning( '请填写详细的考勤地点信息,点击查询,并在地图上选择准确的地点', 1.5, () => { window.setTimeout(() => { resolve(); }, 500); } ); }) ); return; } comAttendAddressJson.push({ address, addressLongitude: point[0], addressLatitude: point[1] }); comAttendAddressJson = comAttendAddressJson.map((val, i) => { val.key = i; return val; }); this.setState({ comAttendAddressJson }); this.setState({ visible: false }); }} onCancel={() => { this.setState({ visible: false }); }} width={700} > { { console.log(point, address, 'point,address'); this.setState({ point, address }); }} ifProvince={false} taskCityName="" //添加当前任务城市名称,9-29,公用组件,暂时传空解决冲突 /> } ); } }