|
@@ -0,0 +1,386 @@
|
|
|
+import React,{Component} from 'react';
|
|
|
+import Taro,{getCurrentInstance } from '@tarojs/taro';
|
|
|
+import {Text, View} from '@tarojs/components'
|
|
|
+import dayjs from 'dayjs';
|
|
|
+import './index.less';
|
|
|
+import DateTimePicker from '../../components/common/DateTimePicker';
|
|
|
+
|
|
|
+import ImagePicker from '../../components/common/imagePicker'
|
|
|
+import {resourceAddress} from '../../utils/config';
|
|
|
+
|
|
|
+import { AtButton,AtTextarea ,AtIcon,AtCalendar } from 'taro-ui'
|
|
|
+import {updatePublicRelease} from '../../utils/servers/servers';
|
|
|
+
|
|
|
+import 'taro-ui/dist/style/components/form.scss';
|
|
|
+import 'taro-ui/dist/style/components/button.scss';
|
|
|
+import 'taro-ui/dist/style/components/loading.scss';
|
|
|
+import 'taro-ui/dist/style/components/icon.scss';
|
|
|
+import 'taro-ui/dist/style/components/icon.scss';
|
|
|
+import 'taro-ui/dist/style/components/textarea.scss';
|
|
|
+import 'taro-ui/dist/style/components/calendar.scss';
|
|
|
+
|
|
|
+import './publicContent.less';
|
|
|
+
|
|
|
+class PublicContent extends Component{
|
|
|
+ constructor(props) {
|
|
|
+ super(props);
|
|
|
+ this.state={
|
|
|
+ rangeStartVal:'',
|
|
|
+ rangeEndVal:'',
|
|
|
+ rangeEndMinuteVal:'',
|
|
|
+ rangeStartMinuteVal:'',
|
|
|
+ reason:'',
|
|
|
+ imgs:[],
|
|
|
+ validDates:[],
|
|
|
+ totalDuration:0,
|
|
|
+ loading:false,
|
|
|
+ }
|
|
|
+ this.onSubmit = this.onSubmit.bind(this);
|
|
|
+ this.selectArrder = this.selectArrder.bind(this);
|
|
|
+ this.onChange = this.onChange.bind(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ componentWillReceiveProps(props){
|
|
|
+ if(props.isOpened){
|
|
|
+ this.rangeStartRef.setInitialState({current:props.dtails.releaseStarts})
|
|
|
+ this.rangeEndRef.setInitialState({current:props.dtails.releaseEnds});
|
|
|
+ let arr = [];
|
|
|
+ console.log(props.dtails.annexUrl,'props.dtails.annexUrl')
|
|
|
+ for(let i of props.dtails.annexUrl){
|
|
|
+ arr.push(i.url.split(resourceAddress).join(""))
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ imgs:arr,
|
|
|
+ totalDuration:props.dtails.duration,
|
|
|
+ reason:props.dtails.remarks,
|
|
|
+ validDates:JSON.parse(props.dtails.validDate),
|
|
|
+ rangeEndVal:dayjs(props.dtails.releaseEnds).format('YYYY-MM-DD'),
|
|
|
+ rangeEndMinuteVal: dayjs(props.dtails.releaseEnds).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ rangeStartVal:dayjs(props.dtails.releaseStarts).format('YYYY-MM-DD'),
|
|
|
+ rangeStartMinuteVal: dayjs(props.dtails.releaseStarts).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ this.rangeEndRef && this.rangeEndRef.clear();
|
|
|
+ this.rangeStartRef && this.rangeStartRef.clear();
|
|
|
+ this.imagePickerRef && this.imagePickerRef.clear();
|
|
|
+ this.setState({
|
|
|
+ rangeStartVal:'',
|
|
|
+ rangeEndVal:'',
|
|
|
+ rangeEndMinuteVal:'',
|
|
|
+ rangeStartMinuteVal:'',
|
|
|
+ reason:'',
|
|
|
+ imgs:[],
|
|
|
+ validDates:[],
|
|
|
+ totalDuration:0,
|
|
|
+ loading:false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ componentDidMount() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ getHours(startTime,endTime){
|
|
|
+ let a1 = dayjs(startTime);
|
|
|
+ let b1 = dayjs(endTime);
|
|
|
+ let c1 = b1.diff(a1,'minutes');
|
|
|
+ let hourse = parseInt(c1/60);
|
|
|
+ let minutes = c1%60
|
|
|
+ let minutes1 = parseInt(minutes / 30)*0.5
|
|
|
+ if(
|
|
|
+ a1.isBefore(dayjs(a1.format('YYYY-MM-DD')+' 13:30'))
|
|
|
+ &&
|
|
|
+ a1.isAfter(dayjs(a1.format('YYYY-MM-DD')+' 12:00'))
|
|
|
+ ){
|
|
|
+ this.getHours(dayjs(a1.format('YYYY-MM-DD')+' 13:30'),endTime);
|
|
|
+ }else if(
|
|
|
+ a1.isBefore(dayjs(a1.format('YYYY-MM-DD')+' 12:00'))
|
|
|
+ &&
|
|
|
+ b1.isAfter(dayjs(a1.format('YYYY-MM-DD')+' 13:30'))
|
|
|
+ ){
|
|
|
+ return hourse+minutes1-1.5
|
|
|
+ }else{
|
|
|
+ return hourse+minutes1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ getNumHourse(startTime,endTime){
|
|
|
+ if(dayjs(dayjs(startTime).format('YYYY-MM-DD')).isSame(dayjs(dayjs(endTime).format('YYYY-MM-DD')))){
|
|
|
+ this.setState({
|
|
|
+ totalDuration:this.getHours(startTime,endTime)
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ let a = this.getHours(startTime,dayjs(startTime.format('YYYY-MM-DD')+' 17:30'));
|
|
|
+ let b = this.getHours(dayjs(endTime.format('YYYY-MM-DD')+' 8:30'),endTime);
|
|
|
+ let c = (this.state.validDates.length-2)*7.5;
|
|
|
+ this.setState({
|
|
|
+ totalDuration:a+b+c
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ onSubmit(){
|
|
|
+ if(!this.state.rangeStartMinuteVal){
|
|
|
+ Taro.showToast({title:'请选择公出开始时间',icon:'none'})
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if(!this.state.rangeEndMinuteVal){
|
|
|
+ Taro.showToast({title:'请选择公出结束时间',icon:'none'})
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if(!(this.props.locationInfor.longitude && this.props.locationInfor.latitude)){
|
|
|
+ Taro.showToast({title:'请选择公出地点',icon:'none'})
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if(!this.state.reason){
|
|
|
+ Taro.showToast({title:'请输入公出事由',icon:'none'})
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if(this.state.totalDuration === 0){
|
|
|
+ Taro.showToast({title:'公出时间不足0小时',icon:'none'})
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ loading:true
|
|
|
+ })
|
|
|
+ updatePublicRelease({
|
|
|
+ id:this.props.dtails.id,
|
|
|
+ releaseStarts:this.state.rangeStartMinuteVal,
|
|
|
+ releaseEnds:this.state.rangeEndMinuteVal,
|
|
|
+ remarks:this.state.reason,
|
|
|
+ userName: this.props.locationInfor.name,
|
|
|
+ longitude: this.props.locationInfor.longitude,
|
|
|
+ latitude: this.props.locationInfor.latitude,
|
|
|
+ annexUrl: this.state.imgs.length === 0 ? '' : this.state.imgs.join(','),
|
|
|
+ duration: this.state.totalDuration,
|
|
|
+ validDate: JSON.stringify(this.state.validDates)
|
|
|
+ }).then(v=>{
|
|
|
+ this.setState({
|
|
|
+ loading:false
|
|
|
+ })
|
|
|
+ if(v.error.length === 0){
|
|
|
+ Taro.showToast({
|
|
|
+ title:'修改成功',
|
|
|
+ })
|
|
|
+ this.props.onClose();
|
|
|
+ }else{
|
|
|
+ Taro.showToast({
|
|
|
+ title:v.error[0].message,
|
|
|
+ icon:'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch(()=>{
|
|
|
+ this.setState({
|
|
|
+ loading:false
|
|
|
+ })
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ selectArrder(){
|
|
|
+ const key = 'AWBBZ-GRAC2-JFYUO-CLA7I-JAHXK-YFFGT'; //使用在腾讯位置服务申请的key
|
|
|
+ const referer = '科德打卡定位'; //调用插件的app的名称
|
|
|
+ const location = JSON.stringify({
|
|
|
+ latitude: 39.89631551,
|
|
|
+ longitude: 116.323459711
|
|
|
+ });
|
|
|
+ const category = '生活服务,娱乐休闲';
|
|
|
+
|
|
|
+ Taro.navigateTo({
|
|
|
+ url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&location=' + location + '&category=' + category
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ onChange(value,type){
|
|
|
+ let arr = this.state.imgs.concat([]);
|
|
|
+ if(type === 'add'){
|
|
|
+ arr.push(value)
|
|
|
+ }else if(type === 'remove'){
|
|
|
+ arr.splice(value,1)
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ imgs: arr,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const {dtails} = this.props;
|
|
|
+ return (
|
|
|
+ <View className='publicContent'>
|
|
|
+ <View className='formItem'>
|
|
|
+ <View className='formName'>公出企业:</View>
|
|
|
+ <View className='formValue'>{dtails.nickname}</View>
|
|
|
+ </View>
|
|
|
+ <View className='formItem'>
|
|
|
+ <View className='formName'>公出开始时间:</View>
|
|
|
+ <View className='formValue'>
|
|
|
+ <DateTimePicker ref={ref=>this.rangeStartRef = ref} onOk={(current)=>{
|
|
|
+ let arr = [];
|
|
|
+ if(this.state.rangeEndVal){
|
|
|
+ let str = dayjs(current.current).format('YYYY-MM-DD');
|
|
|
+ arr.push({value:str});
|
|
|
+ let a = dayjs(this.state.rangeEndVal.split('-'));
|
|
|
+ let b = dayjs(str.split('-'));
|
|
|
+ let num = a.diff(b, 'days');
|
|
|
+ let strAdd = str;
|
|
|
+ for(let i = 0;i<num;i++){
|
|
|
+ let time = dayjs(strAdd).add(1, 'days').format('YYYY-MM-DD');
|
|
|
+ strAdd = time
|
|
|
+ arr.push({value:time});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ rangeStartVal:dayjs(current.current).format('YYYY-MM-DD'),
|
|
|
+ rangeStartMinuteVal: dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ validDates:arr
|
|
|
+ },()=>{
|
|
|
+ if(this.state.rangeEndVal){
|
|
|
+ let a1 = dayjs(dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'));
|
|
|
+ let b1 = dayjs(dayjs(this.state.rangeEndMinuteVal).format('YYYY-MM-DD HH:mm:ss'));
|
|
|
+ this.getNumHourse(a1,b1)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }} onClear={()=>{
|
|
|
+ this.setState({
|
|
|
+ rangeStartVal:'',
|
|
|
+ rangeStartMinuteVal: '',
|
|
|
+ validDates:[],
|
|
|
+ totalDuration:0
|
|
|
+ })
|
|
|
+ }} initValue={dayjs().format('YYYY-MM-DD HH:mm:ss')} wrap-class="my-class" select-item-class="mySelector" />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View className='formItem'>
|
|
|
+ <View className='formName'>公出结束时间:</View>
|
|
|
+ <View className='formValue'>
|
|
|
+ <DateTimePicker ref={ref=>this.rangeEndRef = ref} onOk={(current)=>{
|
|
|
+ let arr = [];
|
|
|
+ if(this.state.rangeStartVal){
|
|
|
+ let str = dayjs(current.current).format('YYYY-MM-DD');
|
|
|
+ arr.push({value:this.state.rangeStartVal});
|
|
|
+ let a = dayjs(this.state.rangeStartVal.split('-'));
|
|
|
+ let b = dayjs(str.split('-'));
|
|
|
+ let num = b.diff(a, 'days');
|
|
|
+ let strAdd = this.state.rangeStartVal;
|
|
|
+ for(let i = 0;i<num;i++){
|
|
|
+ let time = dayjs(strAdd).add(1, 'days').format('YYYY-MM-DD');
|
|
|
+ strAdd = time
|
|
|
+ arr.push({value:time});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ rangeEndVal:dayjs(current.current).format('YYYY-MM-DD'),
|
|
|
+ rangeEndMinuteVal: dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ validDates:arr,
|
|
|
+ },()=>{
|
|
|
+ if(this.state.rangeStartVal){
|
|
|
+ let a1 = dayjs(dayjs(current.current).format('YYYY-MM-DD HH:mm:ss'));
|
|
|
+ let b1 = dayjs(dayjs(this.state.rangeStartMinuteVal).format('YYYY-MM-DD HH:mm:ss'));
|
|
|
+ this.getNumHourse(b1,a1)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }} onClear={()=>{
|
|
|
+ this.setState({
|
|
|
+ rangeEndVal:'',
|
|
|
+ rangeEndMinuteVal: '',
|
|
|
+ validDates:[],
|
|
|
+ totalDuration:0
|
|
|
+ })
|
|
|
+ }} initValue={dayjs().format('YYYY-MM-DD HH:mm:ss')} wrap-class="my-class" select-item-class="mySelector" />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View className='formItem'>
|
|
|
+ <View className='formName'>总时长:</View>
|
|
|
+ <View className='formValue'>
|
|
|
+ {this.state.totalDuration}小时
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ {this.state.validDates.length !== 0? <View className='formItem' style={{display:'block',paddingTop:'15px'}}>
|
|
|
+ <View className='formName'>去除放假时间:</View>
|
|
|
+ <AtCalendar
|
|
|
+ minDate={this.state.rangeStartVal}
|
|
|
+ maxDate={this.state.rangeEndVal}
|
|
|
+ isSwiper={false}
|
|
|
+ validDates={this.state.validDates}
|
|
|
+ onDayLongClick={(item)=>{
|
|
|
+ if(!(dayjs(item.value.split('-')).isSame(this.state.rangeStartVal.split('-')) || dayjs(item.value.split('-')).isSame(this.state.rangeEndVal.split('-')))){
|
|
|
+ if(!(dayjs(item.value.split('-')).isAfter(this.state.rangeStartVal.split('-')) && dayjs(item.value.split('-')).isBefore(this.state.rangeEndVal.split('-')))){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ Taro.showToast({title:'开始结束时间不能取消',icon:'none'})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let index = this.state.validDates.findIndex(v=>{
|
|
|
+ let lv = dayjs(v.value.split('-')).isSame(item.value.split('-'));
|
|
|
+ return lv
|
|
|
+ })
|
|
|
+ if(index<0){
|
|
|
+ let arr = item.value.split('-');
|
|
|
+ this.state.validDates.push({value:arr.join('-')})
|
|
|
+ this.setState({
|
|
|
+ validDates:this.state.validDates,
|
|
|
+ totalDuration: this.state.totalDuration + 7.5
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ this.state.validDates.splice(index,1)
|
|
|
+ this.setState({
|
|
|
+ validDates:this.state.validDates,
|
|
|
+ totalDuration: this.state.totalDuration - 7.5
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </View> : null}
|
|
|
+ <View className='formItem'>
|
|
|
+ <View className='formName'>公出地点:</View>
|
|
|
+ <View className='formValue' onClick={this.selectArrder}>
|
|
|
+ <Text className='formValueText'>{this.props.locationInfor.name}</Text>
|
|
|
+ <AtIcon value='chevron-right' size='30' color='#bbbbbb'/>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View className='tips'>地址选择错误,将影响打卡定位,选择后请认真核对</View>
|
|
|
+ <View className='formItem' style={{display:'block',paddingTop:'15px'}}>
|
|
|
+ <View className='formName'>公出事由:</View>
|
|
|
+ <View className='formValue' style={{paddingTop:'10px',textAlign:'left'}}>
|
|
|
+ <AtTextarea
|
|
|
+ value={this.state.reason}
|
|
|
+ onChange={(v)=>{
|
|
|
+ this.setState({
|
|
|
+ reason:v
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ maxLength={200}
|
|
|
+ placeholder='请输入公出事由'
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View className='formItem' style={{display:'block'}}>
|
|
|
+ <View className='formName'>附件:</View>
|
|
|
+ <View className='formValue' style={{paddingTop:'10px',textAlign:'left'}}>
|
|
|
+ {dtails.annexUrl && this.props.isOpened ? <ImagePicker
|
|
|
+ files={dtails.annexUrl}
|
|
|
+ showAddBtn={true}
|
|
|
+ ref={ref => this.imagePickerRef = ref}
|
|
|
+ url='/api/admin/release/upload'
|
|
|
+ onChange={this.onChange}
|
|
|
+ /> : null }
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View className='operation'>
|
|
|
+ <AtButton disabled={this.state.loading} type='secondary' circle onClick={()=>{
|
|
|
+ this.props.onClose();
|
|
|
+ }}>
|
|
|
+ 取消
|
|
|
+ </AtButton>
|
|
|
+ <AtButton type='primary' loading={this.state.loading} circle onClick={this.onSubmit}>
|
|
|
+ 提交申请
|
|
|
+ </AtButton>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export default PublicContent;
|