SendMeet.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /**
  2. * Created by FANGlh on 2018/11/6 15:47.
  3. */
  4. import React, {Component} from 'react';
  5. import nextArrowimg from '../../../style/imgs/next_arrow.png';
  6. import './SendMeet.css';
  7. import 'antd/dist/antd.css';
  8. import {Select, TreeSelect, Icon, Button} from 'antd';
  9. import moment from 'moment';
  10. import add_newimg from '../../../style/imgs/add_new.png';
  11. import {fetchPost, fetchGet, fetchGetNoSession} from '../../../utils/fetchRequest';
  12. import {API} from '../../../configs/api.config';
  13. import {Toast, Picker, List, DatePicker} from 'antd-mobile';
  14. import {getIntValue, getStrValue, isObjEmpty} from "../../../utils/common";
  15. import TargetSelect from '../../../components/TargetSelect';
  16. import {connect} from 'react-redux';
  17. import {clearListState} from "../../../redux/actions/listState";
  18. const Option = Select.Option;
  19. class SendMeet extends Component {
  20. componentWillMount() {
  21. document.title = '发起会议'
  22. }
  23. componentDidMount() {
  24. this.getOrganization()
  25. }
  26. componentWillUnmount() {
  27. Toast.hide()
  28. clearTimeout(this.backTask)
  29. }
  30. getOrganization = () => {
  31. Toast.loading('', 0)
  32. fetchGet(API.getAllTeacher, {
  33. schoolId: this.props.userInfo.user.schoolId,
  34. }).then(response => {
  35. Toast.hide()
  36. const {targetData} = this.state
  37. targetData.length = 0
  38. if (response && response.data) {
  39. // const schoolArray = response.data.schools
  40. const teacherArray = response.data
  41. if (!isObjEmpty(teacherArray)) {
  42. const teacherData = []
  43. teacherArray.forEach((teacherObj, index) => {
  44. if (teacherObj) {
  45. teacherData.push({
  46. title: getStrValue(teacherObj, 'teacherName'),
  47. userId: getIntValue(teacherObj, 'teacherId'),
  48. userPhone: getStrValue(teacherObj, 'userPhone'),
  49. value: getStrValue(teacherObj, 'teacherName') + `-0-${index}`,
  50. key: `1-${index}`,
  51. })
  52. }
  53. })
  54. targetData.push({
  55. title: `全体老师`,
  56. value: `0`,
  57. key: `0`,
  58. selectable:false,
  59. children: teacherData,
  60. })
  61. }
  62. }
  63. console.log('targetData', targetData)
  64. this.setState({
  65. targetData,
  66. })
  67. }).catch(error => {
  68. Toast.hide()
  69. if (typeof error === 'string') {
  70. Toast.fail(error, 2)
  71. } else {
  72. Toast.fail('请求异常', 2)
  73. }
  74. })
  75. }
  76. constructor() {
  77. super();
  78. this.state = {
  79. targetList: [],
  80. targetCount: 0,
  81. targetData: [],
  82. startValue: null,
  83. endValue: null,
  84. endOpen: false,
  85. titleValue: null,
  86. contentValue: null,
  87. earlyTime: null,
  88. meetPerson: [],
  89. meetAddress: null,
  90. noticeType: [{
  91. label: '创建即提醒',
  92. value: '0'
  93. }, {
  94. label: '会前5分钟',
  95. value: 5
  96. }, {
  97. label: '会前15分钟',
  98. value: 15
  99. }, {
  100. label: '会前25分钟',
  101. value: 25
  102. }, {
  103. label: '会前35分钟',
  104. value: 35
  105. }]
  106. };
  107. }
  108. render() {
  109. const targetProps = {
  110. targetData: this.state.targetData,
  111. targetValues: this.state.targetList,
  112. title: '与会人',
  113. targetCount: this.state.targetCount,
  114. onTargetChange: this.onTargetChange.bind(this),
  115. onTargetFocus: this.onTargetFocus.bind(this)
  116. }
  117. const defaultTargetProps = {
  118. targetData: [],
  119. targetValues: this.state.targetList,
  120. title: '与会人',
  121. targetCount: this.state.targetCount,
  122. onTargetChange: this.onTargetChange.bind(this),
  123. onTargetFocus: this.onTargetFocus.bind(this)
  124. }
  125. return (
  126. <div onChange={this.handelValueCom} style={{fontFamily: "PingFangSC-Regular", letterSpacing: 2.5}} className='common-column-layout'>
  127. {/*<p>{new Date().getTime()}</p>*/}
  128. <textarea autoFocus="autoFocus" ref='meetTitle' className="form-control textarea_sty" rows="2"
  129. placeholder="请填写会议主题…"></textarea>
  130. <textarea ref='meetAddress' className="form-control textarea_sty" rows="3"
  131. placeholder="请填写会议地址…"></textarea>
  132. <div className="comhline_sty"></div>
  133. <div className="common-column-layout" style={{fontSize: 15}}>
  134. <DatePicker
  135. value={this.state.startValue}
  136. locale={{
  137. okText: '确定',
  138. dismissText: '取消'
  139. }}
  140. onChange={date => this.setState({startValue: date})}>
  141. <List.Item arrow="horizontal">会议开始时间</List.Item>
  142. </DatePicker>
  143. <div className="comhline_sty1"></div>
  144. <DatePicker
  145. value={this.state.endValue}
  146. locale={{
  147. okText: '确定',
  148. dismissText: '取消'
  149. }}
  150. onChange={date => this.setState({endValue: date})}>
  151. <List.Item arrow="horizontal">会议结束时间</List.Item>
  152. </DatePicker>
  153. <div className="comhline_sty1"></div>
  154. <Picker
  155. data={this.state.noticeType} title='提醒时间' extra='请选择'
  156. value={this.state.earlyTime}
  157. onChange={this.handleSelectChange}
  158. onOk={this.handleSelectChange} cols={1}>
  159. <List.Item arrow="horizontal">提醒时间</List.Item>
  160. </Picker>
  161. </div>
  162. <div className="comhline_sty1"></div>
  163. {this.state.targetData.length > 0 ? <TargetSelect {...targetProps}/>
  164. : <TargetSelect {...defaultTargetProps}/>}
  165. {/*<center><Button type="button" className="btn btn-primary comBtn_sty"*/}
  166. {/*onClick={this.doSaveClick}>创建</Button></center>*/}
  167. <Button className='commonButton' type='primary' style={{margin: '35px'}}
  168. onClick={this.doSaveClick}>创建</Button>
  169. </div>
  170. )
  171. }
  172. doSaveClick = (event) => {
  173. if(this.isRequesting == true){
  174. return
  175. }
  176. console.log('state', this.state)
  177. if (this.state.titleValue == null || this.state.titleValue.trim().length == 0) {
  178. Toast.fail('请填写会议主题...')
  179. return
  180. }
  181. if (this.state.meetAddress == null || this.state.meetAddress.trim().length == 0) {
  182. Toast.fail('请填写会议地址...')
  183. return
  184. }
  185. if (this.state.startValue == null ) {
  186. Toast.fail('请选择开始时间...')
  187. return
  188. }
  189. if (this.state.endValue == null ) {
  190. Toast.fail('请选择结束时间...')
  191. return
  192. }
  193. if (this.state.earlyTime == null ){
  194. Toast.fail('请选择提醒时间...')
  195. return
  196. }
  197. if (this.state.targetList.length == 0) {
  198. Toast.fail('请选择与会人...')
  199. return
  200. }
  201. const userList = []
  202. if (!isObjEmpty(this.checkNodes)) {
  203. this.checkNodes.forEach((node, index) => {
  204. userList.push(node.userId)
  205. })
  206. }
  207. var nowT = new Date().getTime()
  208. var startT = new Date(this.state.startValue).getTime()
  209. var endT = new Date(this.state.endValue).getTime()
  210. console.log('startT', startT)
  211. if (nowT > startT) {
  212. Toast.show('开始时间不可小于当前时间', 1)
  213. return
  214. }
  215. if (startT > endT) {
  216. Toast.show('结束时间不可小于开始时间', 1)
  217. return
  218. }
  219. if (!isObjEmpty(this.checkNodes)) {
  220. this.checkNodes.forEach((node, index) => {
  221. this.state.meetPerson.push(node.userId)
  222. })
  223. }
  224. var noticeT = startT - this.state.earlyTime * 1000 * 60
  225. console.log('noticeT', noticeT)
  226. console.log('noticeT', new Date(noticeT))
  227. let params = {
  228. meetingCreator:this.props.userInfo.user.userFunId,
  229. meetingStatus: 1,
  230. meetingName: this.state.titleValue,
  231. meetingAddress: this.state.meetAddress,
  232. startDate: moment(this.state.startValue).format('YYYY-MM-DD HH:mm:ss'),
  233. endDate: moment(this.state.endValue).format('YYYY-MM-DD HH:mm:ss'),
  234. reminderDate: moment(new Date(noticeT)).format('YYYY-MM-DD HH:mm:ss'),
  235. meetingNotifier: JSON.stringify(userList),
  236. meetingRemarks: "会议备注",
  237. meetingFiles:"[]",
  238. meetingDetails: "一定要参加",
  239. }
  240. console.log('params', params)
  241. Toast.loading("会议创建中...", 0)
  242. this.isRequesting = true
  243. fetchPost(API.createMeeting, {
  244. jsonMeeting:JSON.stringify(params)
  245. }, {})
  246. .then((response) => {
  247. this.isRequesting = false
  248. Toast.hide()
  249. console.log('response', response)
  250. if (response.success) {
  251. this.isRequesting = true
  252. clearListState()()
  253. Toast.show('创建成功', 1)
  254. this.backTask = setTimeout(() => {
  255. this.props.history.goBack()
  256. }, 1000)
  257. }
  258. })
  259. .catch((error) => {
  260. this.isRequesting = false
  261. Toast.hide()
  262. console.log('error', error)
  263. console.log('error', error)
  264. if (typeof error === 'string') {
  265. Toast.fail(error, 2)
  266. } else {
  267. if (typeof error === 'string') {
  268. Toast.fail(error, 2)
  269. } else {
  270. Toast.fail('请求异常', 2)
  271. }
  272. }
  273. })
  274. }
  275. onTargetFocus = (e) => {
  276. if (isObjEmpty(this.state.targetData)) {
  277. this.getOrganization()
  278. }
  279. }
  280. onTargetChange = (value, label, checkNodes, count) => {
  281. this.checkNodes = checkNodes
  282. this.setState({
  283. targetList: value,
  284. targetCount: count
  285. });
  286. }
  287. selectPersononChange = (value) => {
  288. console.log('selectPersononChange ', value);
  289. this.setState({meetPerson: value});
  290. }
  291. disabledStartDate = (startValue) => {
  292. const endValue = this.state.endValue;
  293. if (!startValue || !endValue) {
  294. return false;
  295. }
  296. return startValue.valueOf() > endValue.valueOf();
  297. }
  298. handleSelectChange = (value) => {
  299. console.log(`selected ${value}`);
  300. this.setState({
  301. earlyTime: value
  302. })
  303. }
  304. handelValueCom = (event) => {
  305. //获取用户名的值
  306. let meetTitle = this.refs.meetTitle.value;
  307. //获得内容的值
  308. let meetAddress = this.refs.meetAddress.value;
  309. this.setState({
  310. titleValue: meetTitle,
  311. meetAddress: meetAddress
  312. })
  313. }
  314. }
  315. let mapStateToProps = (state) => ({
  316. userInfo: {...state.redUserInfo}
  317. })
  318. let mapDispatchToProps = (dispatch) => ({})
  319. export default connect(mapStateToProps, mapDispatchToProps)(SendMeet)