SendMeet.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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}}
  127. className='common-column-layout'>
  128. {/*<p>{new Date().getTime()}</p>*/}
  129. <textarea autoFocus="autoFocus" ref='meetTitle' className="form-control textarea_sty" rows="2"
  130. placeholder="请填写会议主题…" maxLength={20}></textarea>
  131. <textarea ref='meetAddress' className="form-control textarea_sty" rows="3"
  132. placeholder="请填写会议地址…" maxLength={50}></textarea>
  133. <div className="comhline_sty"></div>
  134. <div className="common-column-layout" style={{fontSize: 15}}>
  135. <DatePicker
  136. value={this.state.startValue}
  137. locale={{
  138. okText: '确定',
  139. dismissText: '取消'
  140. }}
  141. onChange={date => this.setState({startValue: date})}>
  142. <List.Item arrow="horizontal">会议开始时间</List.Item>
  143. </DatePicker>
  144. <div className="comhline_sty1"></div>
  145. <DatePicker
  146. value={this.state.endValue}
  147. locale={{
  148. okText: '确定',
  149. dismissText: '取消'
  150. }}
  151. onChange={date => this.setState({endValue: date})}>
  152. <List.Item arrow="horizontal">会议结束时间</List.Item>
  153. </DatePicker>
  154. <div className="comhline_sty1"></div>
  155. <Picker
  156. data={this.state.noticeType} title='提醒时间' extra='请选择'
  157. value={this.state.earlyTime}
  158. onChange={this.handleSelectChange}
  159. onOk={this.handleSelectChange} cols={1}>
  160. <List.Item arrow="horizontal">提醒时间</List.Item>
  161. </Picker>
  162. </div>
  163. <div className="comhline_sty1"></div>
  164. {this.state.targetData.length > 0 ? <TargetSelect {...targetProps}/>
  165. : <TargetSelect {...defaultTargetProps}/>}
  166. {/*<center><Button type="button" className="btn btn-primary comBtn_sty"*/}
  167. {/*onClick={this.doSaveClick}>创建</Button></center>*/}
  168. <Button className='commonButton' type='primary' style={{margin: '35px'}}
  169. onClick={this.doSaveClick}>创建</Button>
  170. </div>
  171. )
  172. }
  173. doSaveClick = (event) => {
  174. if (this.isRequesting == true) {
  175. return
  176. }
  177. console.log('state', this.state)
  178. if (this.state.titleValue == null || this.state.titleValue.trim().length == 0) {
  179. Toast.fail('请填写会议主题...')
  180. return
  181. }
  182. if (this.state.meetAddress == null || this.state.meetAddress.trim().length == 0) {
  183. Toast.fail('请填写会议地址...')
  184. return
  185. }
  186. if (this.state.startValue == null) {
  187. Toast.fail('请选择开始时间...')
  188. return
  189. }
  190. if (this.state.endValue == null) {
  191. Toast.fail('请选择结束时间...')
  192. return
  193. }
  194. if (this.state.earlyTime == null) {
  195. Toast.fail('请选择提醒时间...')
  196. return
  197. }
  198. if (this.state.targetList.length == 0) {
  199. Toast.fail('请选择与会人...')
  200. return
  201. }
  202. const userList = []
  203. if (!isObjEmpty(this.checkNodes)) {
  204. this.checkNodes.forEach((node, index) => {
  205. userList.push(node.userId)
  206. })
  207. if (!isObjEmpty(this.props.userInfo.user.userFunId) && userList.indexOf(this.props.userInfo.user.userFunId) === -1) {
  208. userList.push(this.props.userInfo.user.userFunId)
  209. }
  210. }
  211. var nowT = new Date().getTime()
  212. var startT = new Date(this.state.startValue).getTime()
  213. var endT = new Date(this.state.endValue).getTime()
  214. console.log('startT', startT)
  215. if (nowT > startT) {
  216. Toast.show('开始时间不可小于当前时间', 1)
  217. return
  218. }
  219. if (startT > endT) {
  220. Toast.show('结束时间不可小于开始时间', 1)
  221. return
  222. }
  223. if (!isObjEmpty(this.checkNodes)) {
  224. this.checkNodes.forEach((node, index) => {
  225. this.state.meetPerson.push(node.userId)
  226. })
  227. }
  228. var noticeT = startT - this.state.earlyTime * 1000 * 60
  229. console.log('noticeT', noticeT)
  230. console.log('noticeT', new Date(noticeT))
  231. let params = {
  232. meetingCreator: this.props.userInfo.user.userFunId,
  233. meetingStatus: 1,
  234. meetingName: this.state.titleValue,
  235. meetingAddress: this.state.meetAddress,
  236. startDate: moment(this.state.startValue).format('YYYY-MM-DD HH:mm:ss'),
  237. endDate: moment(this.state.endValue).format('YYYY-MM-DD HH:mm:ss'),
  238. reminderDate: moment(new Date(noticeT)).format('YYYY-MM-DD HH:mm:ss'),
  239. meetingNotifier: JSON.stringify(userList),
  240. meetingRemarks: "会议备注",
  241. meetingFiles: "[]",
  242. meetingDetails: "一定要参加",
  243. }
  244. console.log('params', params)
  245. Toast.loading("会议创建中...", 0)
  246. this.isRequesting = true
  247. fetchPost(API.createMeeting, {
  248. jsonMeeting: JSON.stringify(params)
  249. }, {})
  250. .then((response) => {
  251. this.isRequesting = false
  252. Toast.hide()
  253. console.log('response', response)
  254. if (response.success) {
  255. this.isRequesting = true
  256. clearListState()()
  257. Toast.show('创建成功', 1)
  258. this.backTask = setTimeout(() => {
  259. this.props.history.goBack()
  260. }, 1000)
  261. }
  262. })
  263. .catch((error) => {
  264. this.isRequesting = false
  265. Toast.hide()
  266. console.log('error', error)
  267. console.log('error', error)
  268. if (typeof error === 'string') {
  269. Toast.fail(error, 2)
  270. } else {
  271. if (typeof error === 'string') {
  272. Toast.fail(error, 2)
  273. } else {
  274. Toast.fail('请求异常', 2)
  275. }
  276. }
  277. })
  278. }
  279. onTargetFocus = (e) => {
  280. if (isObjEmpty(this.state.targetData)) {
  281. this.getOrganization()
  282. }
  283. }
  284. onTargetChange = (value, label, checkNodes, count) => {
  285. this.checkNodes = checkNodes
  286. this.setState({
  287. targetList: value,
  288. targetCount: count
  289. });
  290. }
  291. selectPersononChange = (value) => {
  292. console.log('selectPersononChange ', value);
  293. this.setState({meetPerson: value});
  294. }
  295. disabledStartDate = (startValue) => {
  296. const endValue = this.state.endValue;
  297. if (!startValue || !endValue) {
  298. return false;
  299. }
  300. return startValue.valueOf() > endValue.valueOf();
  301. }
  302. handleSelectChange = (value) => {
  303. console.log(`selected ${value}`);
  304. this.setState({
  305. earlyTime: value
  306. })
  307. }
  308. handelValueCom = (event) => {
  309. //获取用户名的值
  310. let meetTitle = this.refs.meetTitle.value;
  311. //获得内容的值
  312. let meetAddress = this.refs.meetAddress.value;
  313. this.setState({
  314. titleValue: meetTitle,
  315. meetAddress: meetAddress
  316. })
  317. }
  318. }
  319. let mapStateToProps = (state) => ({
  320. userInfo: {...state.redUserInfo}
  321. })
  322. let mapDispatchToProps = (dispatch) => ({})
  323. export default connect(mapStateToProps, mapDispatchToProps)(SendMeet)