publicContent.jsx 15 KB

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