publicContent.jsx 14 KB

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