/**
* Created by FANGlh on 2018/11/6 15:47.
*/
import React, {Component} from 'react';
import nextArrowimg from '../../../style/imgs/next_arrow.png';
import './SendMeet.css';
import 'antd/dist/antd.css';
import {Select, TreeSelect, Icon, Button} from 'antd';
import moment from 'moment';
import add_newimg from '../../../style/imgs/add_new.png';
import {fetchPost, fetchGet, fetchGetNoSession} from '../../../utils/fetchRequest';
import {API} from '../../../configs/api.config';
import {Toast, Picker, List, DatePicker} from 'antd-mobile';
import {getIntValue, getStrValue, isObjEmpty} from "../../../utils/common";
import TargetSelect from '../../../components/TargetSelect';
import {connect} from 'react-redux';
import {clearListState} from "../../../redux/actions/listState";
const Option = Select.Option;
class SendMeet extends Component {
componentWillMount() {
document.title = '发起会议'
}
componentDidMount() {
this.getOrganization()
}
componentWillUnmount() {
Toast.hide()
clearTimeout(this.backTask)
}
getOrganization = () => {
Toast.loading('', 0)
fetchGet(API.getAllTeacher, {
schoolId: this.props.userInfo.user.schoolId,
}).then(response => {
Toast.hide()
const {targetData} = this.state
targetData.length = 0
if (response && response.data) {
// const schoolArray = response.data.schools
const teacherArray = response.data
if (!isObjEmpty(teacherArray)) {
const teacherData = []
teacherArray.forEach((teacherObj, index) => {
if (teacherObj) {
teacherData.push({
title: getStrValue(teacherObj, 'teacherName'),
userId: getIntValue(teacherObj, 'teacherId'),
userPhone: getStrValue(teacherObj, 'userPhone'),
value: getStrValue(teacherObj, 'teacherName') + `-0-${index}`,
key: `1-${index}`,
})
}
})
targetData.push({
title: `全体老师`,
value: `0`,
key: `0`,
selectable: false,
children: teacherData,
})
}
}
console.log('targetData', targetData)
this.setState({
targetData,
})
}).catch(error => {
Toast.hide()
if (typeof error === 'string') {
Toast.fail(error, 2)
} else {
Toast.fail('请求异常', 2)
}
})
}
constructor() {
super();
this.state = {
targetList: [],
targetCount: 0,
targetData: [],
startValue: null,
endValue: null,
endOpen: false,
titleValue: null,
contentValue: null,
earlyTime: null,
meetPerson: [],
meetAddress: null,
noticeType: [{
label: '创建即提醒',
value: '0'
}, {
label: '会前5分钟',
value: 5
}, {
label: '会前15分钟',
value: 15
}, {
label: '会前25分钟',
value: 25
}, {
label: '会前35分钟',
value: 35
}]
};
}
render() {
const targetProps = {
targetData: this.state.targetData,
targetValues: this.state.targetList,
title: '与会人',
targetCount: this.state.targetCount,
onTargetChange: this.onTargetChange.bind(this),
onTargetFocus: this.onTargetFocus.bind(this)
}
const defaultTargetProps = {
targetData: [],
targetValues: this.state.targetList,
title: '与会人',
targetCount: this.state.targetCount,
onTargetChange: this.onTargetChange.bind(this),
onTargetFocus: this.onTargetFocus.bind(this)
}
return (
{/*
{new Date().getTime()}
*/}
this.setState({startValue: date})}>
会议开始时间
this.setState({endValue: date})}>
会议结束时间
提醒时间
{this.state.targetData.length > 0 ?
:
}
{/*
*/}
)
}
doSaveClick = (event) => {
if (this.isRequesting == true) {
return
}
console.log('state', this.state)
if (this.state.titleValue == null || this.state.titleValue.trim().length == 0) {
Toast.fail('请填写会议主题...')
return
}
if (this.state.meetAddress == null || this.state.meetAddress.trim().length == 0) {
Toast.fail('请填写会议地址...')
return
}
if (this.state.startValue == null) {
Toast.fail('请选择开始时间...')
return
}
if (this.state.endValue == null) {
Toast.fail('请选择结束时间...')
return
}
if (this.state.earlyTime == null) {
Toast.fail('请选择提醒时间...')
return
}
if (this.state.targetList.length == 0) {
Toast.fail('请选择与会人...')
return
}
const userList = []
if (!isObjEmpty(this.checkNodes)) {
this.checkNodes.forEach((node, index) => {
userList.push(node.userId)
})
if (!isObjEmpty(this.props.userInfo.user.userFunId) && userList.indexOf(this.props.userInfo.user.userFunId) === -1) {
userList.push(this.props.userInfo.user.userFunId)
}
}
var nowT = new Date().getTime()
var startT = new Date(this.state.startValue).getTime()
var endT = new Date(this.state.endValue).getTime()
console.log('startT', startT)
if (nowT > startT) {
Toast.show('开始时间不可小于当前时间', 1)
return
}
if (startT > endT) {
Toast.show('结束时间不可小于开始时间', 1)
return
}
if (!isObjEmpty(this.checkNodes)) {
this.checkNodes.forEach((node, index) => {
this.state.meetPerson.push(node.userId)
})
}
var noticeT = startT - this.state.earlyTime * 1000 * 60
console.log('noticeT', noticeT)
console.log('noticeT', new Date(noticeT))
let params = {
meetingCreator: this.props.userInfo.user.userFunId,
meetingStatus: 1,
meetingName: this.state.titleValue,
meetingAddress: this.state.meetAddress,
startDate: moment(this.state.startValue).format('YYYY-MM-DD HH:mm:ss'),
endDate: moment(this.state.endValue).format('YYYY-MM-DD HH:mm:ss'),
reminderDate: moment(new Date(noticeT)).format('YYYY-MM-DD HH:mm:ss'),
meetingNotifier: JSON.stringify(userList),
meetingRemarks: "会议备注",
meetingFiles: "[]",
meetingDetails: "一定要参加",
}
console.log('params', params)
Toast.loading("会议创建中...", 0)
this.isRequesting = true
fetchPost(API.createMeeting, {
jsonMeeting: JSON.stringify(params)
}, {})
.then((response) => {
this.isRequesting = false
Toast.hide()
console.log('response', response)
if (response.success) {
this.isRequesting = true
clearListState()()
Toast.show('创建成功', 1)
this.backTask = setTimeout(() => {
this.props.history.goBack()
}, 1000)
}
})
.catch((error) => {
this.isRequesting = false
Toast.hide()
console.log('error', error)
console.log('error', error)
if (typeof error === 'string') {
Toast.fail(error, 2)
} else {
if (typeof error === 'string') {
Toast.fail(error, 2)
} else {
Toast.fail('请求异常', 2)
}
}
})
}
onTargetFocus = (e) => {
if (isObjEmpty(this.state.targetData)) {
this.getOrganization()
}
}
onTargetChange = (value, label, checkNodes, count) => {
this.checkNodes = checkNodes
this.setState({
targetList: value,
targetCount: count
});
}
selectPersononChange = (value) => {
console.log('selectPersononChange ', value);
this.setState({meetPerson: value});
}
disabledStartDate = (startValue) => {
const endValue = this.state.endValue;
if (!startValue || !endValue) {
return false;
}
return startValue.valueOf() > endValue.valueOf();
}
handleSelectChange = (value) => {
console.log(`selected ${value}`);
this.setState({
earlyTime: value
})
}
handelValueCom = (event) => {
//获取用户名的值
let meetTitle = this.refs.meetTitle.value;
//获得内容的值
let meetAddress = this.refs.meetAddress.value;
this.setState({
titleValue: meetTitle,
meetAddress: meetAddress
})
}
}
let mapStateToProps = (state) => ({
userInfo: {...state.redUserInfo}
})
let mapDispatchToProps = (dispatch) => ({})
export default connect(mapStateToProps, mapDispatchToProps)(SendMeet)