publicContent.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. import React, { Component } from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { Text, View } from '@tarojs/components'
  4. import dayjs from 'dayjs';
  5. import './index.less';
  6. import ImagePicker from '../../components/common/imagePicker'
  7. import { resourceAddress } from '../../utils/config';
  8. import { AtButton, AtTextarea, AtIcon, AtCalendar } from 'taro-ui'
  9. import { updatePublicRelease, getWorkingHoursList } from '../../utils/servers/servers';
  10. import { getHours, getNumHourse, getUserWordTimes } from '../../utils/tools';
  11. import 'taro-ui/dist/style/components/form.scss';
  12. import 'taro-ui/dist/style/components/button.scss';
  13. import 'taro-ui/dist/style/components/loading.scss';
  14. import 'taro-ui/dist/style/components/icon.scss';
  15. import 'taro-ui/dist/style/components/icon.scss';
  16. import 'taro-ui/dist/style/components/textarea.scss';
  17. import 'taro-ui/dist/style/components/calendar.scss';
  18. import './publicContent.less';
  19. import InquiryModal from "../../components/common/inquiryModal";
  20. class PublicContent extends Component {
  21. constructor(props) {
  22. super(props);
  23. this.state = {
  24. rangeStartVal: '',
  25. rangeEndVal: '',
  26. rangeEndMinuteVal: '',
  27. rangeStartMinuteVal: '',
  28. reason: '',
  29. plan: '',
  30. expectedEffect: '',
  31. imgs: [],
  32. validDates: [],
  33. totalDuration: 0,
  34. loading: false,
  35. workTypeList: [],
  36. workType: 0,
  37. isPickerRender: false,
  38. }
  39. this.onSubmit = this.onSubmit.bind(this);
  40. this.selectArrder = this.selectArrder.bind(this);
  41. this.onChange = this.onChange.bind(this);
  42. this.getWorkingHoursList = this.getWorkingHoursList.bind(this);
  43. this.onPickerHide = this.onPickerHide.bind(this);
  44. this.onSetPickerTime = this.onSetPickerTime.bind(this);
  45. this.getNumHourse = this.getNumHourse.bind(this);
  46. }
  47. componentDidMount() {
  48. let arr = [];
  49. for (let i of this.props.dtails.annexUrl) {
  50. arr.push(i.url.split(resourceAddress).join(""))
  51. }
  52. this.setState({
  53. imgs: arr,
  54. totalDuration: this.props.dtails.duration,
  55. reason: this.props.dtails.remarks,
  56. validDates: JSON.parse(this.props.dtails.validDate),
  57. rangeEndVal: dayjs(this.props.dtails.releaseEnds).format('YYYY-MM-DD'),
  58. rangeEndMinuteVal: dayjs(this.props.dtails.releaseEnds).format('YYYY-MM-DD HH:mm:ss'),
  59. rangeStartVal: dayjs(this.props.dtails.releaseStarts).format('YYYY-MM-DD'),
  60. rangeStartMinuteVal: dayjs(this.props.dtails.releaseStarts).format('YYYY-MM-DD HH:mm:ss'),
  61. plan: this.props.dtails.plan,
  62. expectedEffect: this.props.dtails.expectedEffect,
  63. })
  64. this.getWorkingHoursList();
  65. }
  66. componentWillUnmount() {
  67. this.imagePickerRef && this.imagePickerRef.clear();
  68. this.setState({
  69. rangeStartVal: '',
  70. rangeEndVal: '',
  71. rangeEndMinuteVal: '',
  72. rangeStartMinuteVal: '',
  73. reason: '',
  74. plan: '',
  75. expectedEffect: '',
  76. imgs: [],
  77. validDates: [],
  78. totalDuration: 0,
  79. loading: false,
  80. })
  81. }
  82. getWorkingHoursList() {
  83. getWorkingHoursList({}).then((v) => {
  84. if (v.error.length === 0) {
  85. let obj = Taro.getStorageSync('userInfor');
  86. let index = v.data.findIndex(value => value.type === obj.workTimeInfor.type);
  87. this.setState({
  88. workType: index !== -1 ? index : 0
  89. })
  90. this.setState({
  91. workTypeList: v.data
  92. })
  93. } else {
  94. Taro.showToast({
  95. title: v.error[0].message,
  96. icon: 'none'
  97. })
  98. }
  99. }).catch(err => {
  100. console.log(err)
  101. })
  102. }
  103. getNumHourse(startTime, endTime) {
  104. this.setState({
  105. totalDuration: getNumHourse(startTime, endTime, this.state.validDates.length)
  106. })
  107. }
  108. onSubmit() {
  109. if (!this.state.rangeStartMinuteVal) {
  110. Taro.showToast({ title: '请选择公出时间', icon: 'none' })
  111. return;
  112. }
  113. if (!this.state.rangeEndMinuteVal) {
  114. Taro.showToast({ title: '请选择公出时间', icon: 'none' })
  115. return;
  116. }
  117. if (!(this.props.locationInfor.longitude && this.props.locationInfor.latitude)) {
  118. Taro.showToast({ title: '请选择公出地点', icon: 'none' })
  119. return;
  120. }
  121. if (!this.state.reason) {
  122. Taro.showToast({ title: '请输入公出目标', icon: 'none' })
  123. return;
  124. }
  125. if (!this.state.plan) {
  126. Taro.showToast({ title: '请输入公出计划', icon: 'none' })
  127. return;
  128. }
  129. if (!this.state.expectedEffect) {
  130. Taro.showToast({ title: '请输入预计效果', icon: 'none' })
  131. return;
  132. }
  133. if (this.state.totalDuration === 0) {
  134. Taro.showToast({ title: '公出时间不足0小时', icon: 'none' })
  135. return;
  136. }
  137. this.setState({
  138. loading: true
  139. })
  140. let datas;
  141. if (this.props.dtails.type == 0) {
  142. datas = {
  143. id: this.props.dtails.id,
  144. uid: this.props.dtails.uid,
  145. releaseStarts: this.state.rangeStartMinuteVal,
  146. releaseEnds: this.state.rangeEndMinuteVal,
  147. remarks: this.state.reason,
  148. plan: this.state.plan,
  149. expectedEffect: this.state.expectedEffect,
  150. userName: this.props.locationInfor.name,
  151. longitude: this.props.locationInfor.longitude,
  152. latitude: this.props.locationInfor.latitude,
  153. annexUrl: this.state.imgs.length === 0 ? '' : this.state.imgs.join(','),
  154. duration: this.state.totalDuration,
  155. validDate: JSON.stringify(this.state.validDates),
  156. type: this.props.dtails.type,
  157. }
  158. } else {
  159. datas = {
  160. id: this.props.dtails.id,
  161. uid: this.props.dtails.uid,
  162. releaseStarts: this.state.rangeStartMinuteVal,
  163. releaseEnds: this.state.rangeEndMinuteVal,
  164. remarks: this.state.reason,
  165. plan: this.state.plan,
  166. expectedEffect: this.state.expectedEffect,
  167. userName: this.props.locationInfor.name,
  168. longitude: this.props.locationInfor.longitude,
  169. latitude: this.props.locationInfor.latitude,
  170. annexUrl: this.state.imgs.length === 0 ? '' : this.state.imgs.join(','),
  171. duration: this.state.totalDuration,
  172. validDate: JSON.stringify(this.state.validDates),
  173. type: this.props.dtails.type,
  174. orderNo: this.props.dtails.orderNo,
  175. }
  176. }
  177. updatePublicRelease(datas).then(v => {
  178. this.setState({
  179. loading: false
  180. })
  181. if (v.error.length === 0) {
  182. Taro.showToast({
  183. title: '修改成功',
  184. })
  185. Taro.eventCenter.trigger('listOperation', {
  186. type: this.props.permission,
  187. index: this.props.index,
  188. status: 1,
  189. userName: this.props.locationInfor.name,
  190. releaseStarts: this.state.rangeStartMinuteVal,
  191. releaseEnds: this.state.rangeEndMinuteVal,
  192. })
  193. this.props.onClose();
  194. } else {
  195. Taro.showToast({
  196. title: v.error[0].message,
  197. icon: 'none'
  198. })
  199. }
  200. }).catch(() => {
  201. this.setState({
  202. loading: false
  203. })
  204. });
  205. }
  206. selectArrder() {
  207. const key = 'AWBBZ-GRAC2-JFYUO-CLA7I-JAHXK-YFFGT'; //使用在腾讯位置服务申请的key
  208. const referer = '科德打卡定位'; //调用插件的app的名称
  209. const category = '公司企业,房产小区';
  210. Taro.navigateTo({
  211. url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&category=' + category
  212. });
  213. }
  214. onChange(value, type) {
  215. let arr = this.state.imgs.concat([]);
  216. if (type === 'add') {
  217. arr.push(value)
  218. } else if (type === 'remove') {
  219. arr.splice(value, 1)
  220. }
  221. this.setState({
  222. imgs: arr,
  223. })
  224. }
  225. onPickerHide() {
  226. this.setState({
  227. isPickerRender: false,
  228. });
  229. }
  230. onSetPickerTime(val) {
  231. let data = val.detail;
  232. this.setState({
  233. rangeStartMinuteVal: data.selectStartTime,
  234. rangeEndMinuteVal: data.selectEndTime
  235. });
  236. let arr = [];
  237. if (data.startTime && data.endTime) {
  238. let a = dayjs(data.startTime);
  239. let b = dayjs(data.endTime);
  240. let num = b.diff(a, 'day') + 1;
  241. let strAdd = data.startTime;
  242. for (let i = 0; i < num; i++) {
  243. let time = dayjs(strAdd).add(i, 'days').format('YYYY-MM-DD');
  244. arr.push({ value: time });
  245. }
  246. }
  247. this.setState({
  248. rangeEndVal: dayjs(data.endTime).format('YYYY-MM-DD'),
  249. rangeStartVal: dayjs(data.startTime).format('YYYY-MM-DD'),
  250. validDates: arr,
  251. }, () => {
  252. let a1 = dayjs(dayjs(data.endTime).format('YYYY-MM-DD HH:mm:ss'));
  253. let b1 = dayjs(dayjs(data.startTime).format('YYYY-MM-DD HH:mm:ss'));
  254. this.getNumHourse(b1, a1)
  255. })
  256. }
  257. render() {
  258. const { dtails } = this.props;
  259. console.log(dtails);
  260. return (
  261. <View className='publicContent'>
  262. <View className='formItem'>
  263. <View className='formName'>公出企业:</View>
  264. <View className='formValue'>{dtails.nickname}</View>
  265. </View>
  266. <View className='formItem'>
  267. <View className='formName'>公出类型:</View>
  268. <View className='formValue'>{dtails.type == 1 ? '技术公出' : '业务/行政公出'}</View>
  269. </View>
  270. { dtails.contractNo ? <View className='formItem'>
  271. <View className='formName'>合同编号:</View>
  272. <View className='formValue'>{dtails.contractNo}</View>
  273. </View> : ''}
  274. <View className='formItem'>
  275. <View className='formName'>作息时间类型:</View>
  276. <View className='formValue'>
  277. <picker onChange={(e) => {
  278. this.setState({
  279. workType: e.detail.value
  280. })
  281. if (this.state.workTypeList[e.detail.value]) {
  282. let obj = Taro.getStorageSync('userInfor');
  283. obj.workTimeInfor = this.state.workTypeList[e.detail.value];
  284. Taro.setStorageSync('userInfor', obj);
  285. this.setState({
  286. rangeStartVal: '',
  287. rangeStartMinuteVal: '',
  288. rangeEndMinuteVal: '',
  289. rangeEndVal: '',
  290. validDates: [],
  291. totalDuration: 0
  292. })
  293. }
  294. }} value={this.state.workType} rangeKey='name' range={this.state.workTypeList}>
  295. <view style={{ display: 'flex', alignItems: 'center' }}>
  296. {this.state.workTypeList[this.state.workType] ? this.state.workTypeList[this.state.workType].name : ''}
  297. <AtIcon value='chevron-right' size='20' color='#bbbbbb' />
  298. </view>
  299. </picker>
  300. </View>
  301. </View>
  302. <View className='formItem'>
  303. <View className='formName'>公出时间:</View>
  304. <View className='formValue'>
  305. <View className='time' onClick={() => {
  306. this.setState({
  307. isPickerRender: true
  308. })
  309. }}>
  310. {
  311. this.state.rangeStartMinuteVal && this.state.rangeEndMinuteVal ? <View className='timeContent'>
  312. <View>
  313. 开始时间:{this.state.rangeStartMinuteVal}
  314. </View>
  315. <View>
  316. 结束时间:{this.state.rangeEndMinuteVal}
  317. </View>
  318. </View> : '请选择公出时间'
  319. }
  320. </View>
  321. <timePicker
  322. config={{
  323. endDate: true,
  324. column: "minute",
  325. dateLimit: false,
  326. initStartTime: this.state.rangeStartMinuteVal, //默认开始时间
  327. initEndTime: this.state.rangeEndMinuteVal, //默认结束时间
  328. limitStartTime: dayjs().subtract(3, 'year').format('YYYY-MM-DD HH:mm:ss'),
  329. limitEndTime: dayjs().add(3, 'year').format('YYYY-MM-DD HH:mm:ss')
  330. }}
  331. isPartition
  332. pickerShow={this.state.isPickerRender}
  333. onconditionaljudgment={(v) => {
  334. let a = dayjs(dayjs(v.detail.endTime).second(0).format('YYYY-MM-DD HH:mm:ss'));
  335. let b = dayjs(dayjs().second(0).format('YYYY-MM-DD HH:mm:ss'))
  336. if (a.isBefore(b)) {
  337. Taro.showToast({
  338. title: '结束时间不能小于当前时间',
  339. icon: 'none'
  340. })
  341. v.detail.setLv(false);
  342. }
  343. }}
  344. onhidepicker={() => {
  345. this.onPickerHide()
  346. }}
  347. onsetpickertime={(v) => {
  348. this.onSetPickerTime(v)
  349. }} />
  350. </View>
  351. </View>
  352. <View className='formItem'>
  353. <View className='formName'>总时长:</View>
  354. <View className='formValue'>
  355. {this.state.totalDuration}小时
  356. </View>
  357. </View>
  358. {this.state.validDates.length !== 0 ? <View className='formItem' style={{ display: 'block', paddingTop: '15px' }}>
  359. <View className='formName'>
  360. <View>去除放假时间:</View>
  361. <View className='tips'>绿色方块为公出时间,长按即可去除放假时间</View>
  362. </View>
  363. <AtCalendar
  364. currentDate={this.state.rangeStartVal}
  365. minDate={this.state.rangeStartVal}
  366. maxDate={this.state.rangeEndVal}
  367. isSwiper={false}
  368. validDates={this.state.validDates}
  369. onDayLongClick={(item) => {
  370. if (!(dayjs(item.value).isSame(this.state.rangeStartVal) || dayjs(item.value).isSame(this.state.rangeEndVal))) {
  371. if (!(dayjs(item.value).isAfter(this.state.rangeStartVal) && dayjs(item.value).isBefore(this.state.rangeEndVal))) {
  372. return;
  373. }
  374. } else {
  375. Taro.showToast({ title: '开始结束时间不能取消', icon: 'none' })
  376. return
  377. }
  378. let index = this.state.validDates.findIndex(v => {
  379. let lv = dayjs(v.value).isSame(item.value);
  380. return lv
  381. })
  382. const { start, end } = getUserWordTimes();
  383. let totalDuration = getHours(dayjs().format('YYYY-MM-DD') + start, dayjs(dayjs().format('YYYY-MM-DD') + end)); //一天工作时长
  384. if (index < 0) {
  385. let arr = item.value.split('-');
  386. this.state.validDates.push({ value: arr.join('-') })
  387. this.setState({
  388. validDates: this.state.validDates,
  389. totalDuration: this.state.totalDuration + totalDuration
  390. })
  391. } else {
  392. this.state.validDates.splice(index, 1)
  393. this.setState({
  394. validDates: this.state.validDates,
  395. totalDuration: this.state.totalDuration - totalDuration
  396. })
  397. }
  398. }}
  399. />
  400. </View> : null}
  401. <View className='formItem' style={{
  402. paddingBottom: 0
  403. }}>
  404. <View className='formName'>公出地点:</View>
  405. <View className='formValue' onClick={this.selectArrder}>
  406. <Text className='formValueText'>{this.props.locationInfor.name}</Text>
  407. <AtIcon value='chevron-right' size='30' color='#bbbbbb' />
  408. </View>
  409. </View>
  410. <View className='tips'>以地图为中心100米范围为可打卡区域,移动红标只需要拖动地图即可</View>
  411. <View className='formItem' style={{ display: 'block', paddingTop: '15px' }}>
  412. {/* 公出目标 */}
  413. <View className='formName'><Text style={{ color: 'red' }}>*公出目标:</Text>
  414. <View className='formValue' style={{ paddingTop: '10px', textAlign: 'left' }}>
  415. <AtTextarea
  416. height={46}
  417. value={this.state.reason}
  418. onChange={(v) => {
  419. this.setState({
  420. reason: v
  421. })
  422. }}
  423. maxLength={200}
  424. placeholder='本次公出目标,谈的思路与步骤?'
  425. />
  426. </View>
  427. </View>
  428. {/* 公出计划 */}
  429. <View className='formName'><Text style={{ color: 'red' }}>*公出计划:</Text>
  430. <View className='formValue' style={{ paddingTop: '10px', textAlign: 'left' }}>
  431. <AtTextarea
  432. height={46}
  433. value={this.state.plan}
  434. onChange={(v) => {
  435. this.setState({
  436. plan: v
  437. })
  438. }}
  439. maxLength={200}
  440. placeholder='本次公出准备工作'
  441. />
  442. </View>
  443. </View>
  444. {/* 预计效果 */}
  445. <View className='formName'><Text style={{ color: 'red' }}>*预计效果:</Text>
  446. <View className='formValue' style={{ paddingTop: '10px', textAlign: 'left' }}>
  447. <AtTextarea
  448. height={46}
  449. value={this.state.expectedEffect}
  450. onChange={(v) => {
  451. this.setState({
  452. expectedEffect: v
  453. })
  454. }}
  455. maxLength={200}
  456. placeholder='预计本次公出效果'
  457. />
  458. </View>
  459. </View>
  460. </View>
  461. <View className='formItem' style={{ display: 'block' }}>
  462. <View className='formName'>附件:</View>
  463. <View className='formValue' style={{ paddingTop: '10px', textAlign: 'left' }}>
  464. {dtails.annexUrl && this.props.isOpened ? <ImagePicker
  465. files={dtails.annexUrl}
  466. showAddBtn={true}
  467. ref={ref => this.imagePickerRef = ref}
  468. url='/api/admin/release/upload'
  469. onChange={this.onChange}
  470. /> : null}
  471. </View>
  472. </View>
  473. <View className='operation'>
  474. <AtButton disabled={this.state.loading} type='secondary' circle onClick={() => {
  475. this.props.onClose();
  476. }}>
  477. 取消
  478. </AtButton>
  479. <AtButton type='primary' loading={this.state.loading} circle onClick={() => {
  480. this.setState({
  481. isInquiryOpened: true,
  482. inquiryTitle: '提醒',
  483. inquiryContent: '您确定要修改此申请吗?',
  484. inquiryFn: () => {
  485. this.onSubmit();
  486. }
  487. })
  488. }}>
  489. 确定修改
  490. </AtButton>
  491. </View>
  492. <InquiryModal
  493. isOpened={this.state.isInquiryOpened}
  494. title={this.state.inquiryTitle}
  495. content={this.state.inquiryContent}
  496. onClose={() => {
  497. this.setState({
  498. isInquiryOpened: false,
  499. inquiryTitle: '',
  500. inquiryContent: '',
  501. })
  502. }}
  503. onDetermine={() => {
  504. this.state.inquiryFn();
  505. this.setState({
  506. isInquiryOpened: false,
  507. inquiryTitle: '',
  508. inquiryContent: '',
  509. inquiryFn: () => { }
  510. })
  511. }}
  512. />
  513. </View>
  514. )
  515. }
  516. }
  517. export default PublicContent;