the_leave.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <template>
  2. <view class="content">
  3. <view class="" v-if="value==0">
  4. <view class='wrap'>
  5. <view class="c-row">
  6. <view class="title">请假类型</view>
  7. <view class="con-list">
  8. <view @click='show=true'>{{detailData.leaveType}} ></view>
  9. <u-picker :range="leaveTypeList" range-key="leaveType" @confirm='ltCheck($event)' v-model="show"
  10. mode="selector">
  11. </u-picker>
  12. </view>
  13. </view>
  14. <view class="c-row">
  15. <view class="title">开始时间</view>
  16. <view class="con-list">
  17. <view @click='show1=true'>{{detailData.startDate}} ></view>
  18. <u-picker v-model="show1" mode="time" @confirm='dateChange($event)' :params="params">
  19. </u-picker>
  20. </view>
  21. </view>
  22. <view class="c-row">
  23. <view class="title">结束时间</view>
  24. <view class="con-list">
  25. <view @click='show2=true'>{{detailData.endDate}} ></view>
  26. <u-picker v-model="show2" mode="time" @confirm='dateChange1($event)' :params="params">
  27. </u-picker>
  28. </view>
  29. </view>
  30. <view class="c-row">
  31. <view class="title">时长</view>
  32. <view class="con-list">
  33. <input v-model='detailData.leaveDuration' placeholder="请输入时长"></input>
  34. </view>
  35. </view>
  36. <view class="c-row">
  37. <view class="left">请假事由</view>
  38. </view>
  39. <view style='position:relative;' class="wrap no-boder">
  40. <u-input class='textarea' v-model="detailData.reasonForLeave" :type="type" :border="border"
  41. :height="height" :auto-height="autoHeight" maxlength="100" />
  42. <view style='position:absolute;right:10px;bottom:20px;color:#AFB3BF;'>
  43. {{detailData.reasonForLeave.length}}/100个字
  44. </view>
  45. </view>
  46. <view style='margin:5px 0;'>
  47. <u-button type="primary" class="submit" hover-class="none" @click="submit">提交</u-button>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="" v-else>
  52. <view class='wrap' v-for="(item, index) in tableData" :key="index">
  53. <view class="wenzi audit1" v-if="item.approveStatus">审核中
  54. </view>
  55. <view class="wenzi audit2" v-if="item.status == '已通过'">已通过</view>
  56. <view class="wenzi audit3" v-if="item.status == '未通过'">未通过</view>
  57. <view class="c-row">
  58. <view class="title">请假类型 : {{item.leaveType}}</view>
  59. </view>
  60. <view class="c-row">
  61. <view class="title">请假事由 : {{item.reasonForLeave}}</view>
  62. </view>
  63. <view class="c-row">
  64. <view class="title">开始时间 : {{item.startDate}}</view>
  65. </view>
  66. <view class="c-row">
  67. <view class="title">结束时间 : {{item.endDate}}</view>
  68. </view>
  69. </view>
  70. <view v-show="isLoadMore">
  71. <uni-load-more :status="loadStatus"></uni-load-more>
  72. </view>
  73. <view class="bottom-btn">
  74. <view>
  75. <view style='width:100%;' class='flex flex-space-between'>
  76. <view @click='clocksubmit' style='width:50%;text-align:center;'>
  77. <image v-if='value==0' class="u-page__item__slot-icon"
  78. src="../../static/img/oa_office/leave/qingjia-check.png"></image>
  79. <image v-else class="u-page__item__slot-icon"
  80. src="../../static/img/oa_office/leave/qingjia.png"></image>
  81. <view :style='{"color":value==0?"#22C572":"#000"}'>请假</view>
  82. </view>
  83. <view @click='clockRecord' style='width:50%;text-align:center;'>
  84. <image v-if='value==1' class="u-page__item__slot-icon"
  85. src="../../static/img/oa_office/leave/jilu-check.png"></image>
  86. <image v-else class="u-page__item__slot-icon"
  87. src="../../static/img/oa_office/leave/jilu.png"></image>
  88. <view :style='{"color":value==1?"#22C572":"#000"}'>记录</view>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- <u-button type="primary" class="submit" hover-class="none" @click="clockRecord">记录</u-button> -->
  93. </view>
  94. </view>
  95. <u-toast ref="uToast" />
  96. <view class="bottom-btn">
  97. <view>
  98. <view style='width:100%;' class='flex flex-space-between'>
  99. <view @click='clocksubmit' style='width:50%;text-align:center;'>
  100. <image v-if='value==0' class="u-page__item__slot-icon"
  101. src="../../static/img/oa_office/leave/qingjia-check.png"></image>
  102. <image v-else class="u-page__item__slot-icon"
  103. src="../../static/img/oa_office/leave/qingjia.png"></image>
  104. <view :style='{"color":value==0?"#22C572":"#000"}'>请假</view>
  105. </view>
  106. <view @click='clockRecord' style='width:50%;text-align:center;'>
  107. <image v-if='value==1' class="u-page__item__slot-icon"
  108. src="../../static/img/oa_office/leave/jilu-check.png"></image>
  109. <image v-else class="u-page__item__slot-icon" src="../../static/img/oa_office/leave/jilu.png">
  110. </image>
  111. <view :style='{"color":value==1?"#22C572":"#000"}'>记录</view>
  112. </view>
  113. </view>
  114. </view>
  115. <!-- <u-button type="primary" class="submit" hover-class="none" @click="clockRecord">记录</u-button> -->
  116. </view>
  117. </view>
  118. </template>
  119. <script>
  120. import dRili from '@/components/d-rili/d-rili.vue';
  121. export default {
  122. components: {
  123. dRili
  124. },
  125. data() {
  126. return {
  127. isLoadMore: false, //是否加载中
  128. loadStatus: 'loading', //加载样式:more-加载前样式,loading-加载中样式,nomore-没有数据样式
  129. pageSize: 10,
  130. currentPage: 1,
  131. show: false,
  132. show1: false,
  133. show2: false,
  134. isFreeTime: true,
  135. detailData: {
  136. leaveType: '选择请假类型',
  137. reasonForLeave: "",
  138. startDate: '',
  139. endDate: '选择结束时间',
  140. leaveDuration: '',
  141. },
  142. params: {
  143. year: true,
  144. month: true,
  145. day: true,
  146. hour: true,
  147. minute: true,
  148. },
  149. value: 0,
  150. type: 'textarea',
  151. border: true,
  152. height: 150,
  153. autoHeight: true,
  154. // endDate1:"",
  155. // startDate1: "",
  156. leaveTypeList: [{
  157. leaveType: "事假"
  158. },
  159. {
  160. leaveType: "病假"
  161. },
  162. ],
  163. startDate:"",
  164. endDate:"",
  165. beginTime:"",
  166. endTime:"",
  167. days:"",
  168. hours:"",
  169. date:"",
  170. stWorkTime:"",
  171. enWrokTime:"",
  172. freeTimeMon:"",
  173. freeTimeAft:"",
  174. freeTime:"",
  175. }
  176. },
  177. onReachBottom() { //上拉触底函数
  178. if (!this.isLoadMore) { //此处判断,上锁,防止重复请求
  179. this.isLoadMore = true
  180. this.currentPage += 1
  181. this.getList()
  182. }
  183. },
  184. onLoad(options) {
  185. let h
  186. let m
  187. let s
  188. let _day = new Date();
  189. _day.setTime(_day.getTime());
  190. if (_day.getHours() < 10) {
  191. h = "0" + _day.getHours()
  192. } else {
  193. h = _day.getHours()
  194. }
  195. if (_day.getMinutes() < 10) {
  196. m = "0" + _day.getMinutes()
  197. } else {
  198. m = _day.getMinutes()
  199. }
  200. this.detailData.startDate = _day.getFullYear() + "-" + (_day.getMonth() + 1) + "-" + _day.getDate() +
  201. " " + h + ":" + m;
  202. },
  203. onShow() {
  204. this.getList()
  205. },
  206. methods: {
  207. getList() {
  208. this.$api.doRequest('get', '/leaveInfo/selectLeaveInfo', {
  209. pageSize: this.pageSize,
  210. currentPage: this.currentPage,
  211. pcFlag: 0,
  212. compId: uni.getStorageSync('pcUserInfo').compId,
  213. commonId: uni.getStorageSync('pcUserInfo').userId,
  214. }).then(res => {
  215. // if (res.data.code == 200) {
  216. // this.tableData = res.data.data.records
  217. // }
  218. if (res.data.code == 200) {
  219. if (res.data.data.records.length > 0) {
  220. this.isLoadMore = false
  221. this.loadStatus = 'loading'
  222. } else {
  223. this.isLoadMore = true
  224. this.loadStatus = 'nomore'
  225. }
  226. if (this.currentPage == 1) {
  227. this.tableData = res.data.data.records
  228. } else {
  229. this.tableData = this.tableData.concat(res.data.data.records)
  230. }
  231. }
  232. })
  233. },
  234. calculate() {
  235. const query = uni.createSelectorQuery().in(this);
  236. query.selectAll('.left')
  237. console.log(query)
  238. },
  239. ltCheck(e) {
  240. this.detailData.leaveType = this.leaveTypeList[e].leaveType
  241. if (this.detailData.leaveType == "事假") {
  242. this.detailData.leaveTypeKey = "1"
  243. } else {
  244. this.detailData.leaveTypeKey = "3"
  245. }
  246. },
  247. /**
  248. * 计算请假时长
  249. * beginTime 开始时间
  250. * endTime 结束时间
  251. * stWorkTime 上班时间
  252. * enWrokTime 下班时间
  253. * isFreeTime 是否要去除午休工作时长
  254. * freeTimeMon 午休开始时间
  255. * freeTimeAft 午休结束时间
  256. *
  257. */
  258. dateChange(e) {
  259. this.detailData.startDate = e.year + "-" + e.month + "-" + e.day + " " + e.hour + ":" + e.minute
  260. },
  261. diffDay(earlyDate,lastDate){
  262. return (Date.parse(lastDate) - Date.parse(earlyDate))/1000/60/60/24 +1;
  263. },
  264. dateChange1(e) {
  265. this.detailData.endDate = e.year + "-" + e.month + "-" + e.day + " " + e.hour + ":" + e.minute
  266. var days;
  267. var hours;
  268. var date;
  269. var freeTimeAft =13 ;
  270. var freeTimeMon = 12;
  271. var stWorkTime = 8;
  272. var enWrokTime = 17;
  273. var isFreeTime = true;
  274. var freeTime = freeTimeAft - freeTimeMon;
  275. var beginTime = (this.detailData.startDate).replace(/-/g, '/');
  276. var beginArr = beginTime.split(" ");
  277. var beginMonth = parseInt(beginArr[0].split("/")[1]);
  278. var beginDay = parseInt(beginArr[0].split("/")[2]);
  279. var beginHours = parseInt(beginArr[1].split(":")[0]);
  280. var beginMin = parseInt(beginArr[1].split(":")[1]);
  281. var beginHoursMin = beginHours + beginMin / 60;
  282. var endTime = (this.detailData.endDate).replace(/-/g, '/');
  283. var endArr = endTime.split(" ");
  284. var endMonth = parseInt(endArr[0].split("/")[1]);
  285. var endDay = parseInt(endArr[0].split("/")[2]);
  286. var endHours = parseInt(endArr[1].split(":")[0]);
  287. var endMin = parseInt(endArr[1].split(":")[1]);
  288. var endHoursMin = endHours + endMin / 60;
  289. //如果beginHoursMin时间小于上班时间都算上班时间
  290. if (beginHoursMin <= stWorkTime) {
  291. beginHoursMin = stWorkTime;
  292. }
  293. //如果endHoursMin时间大于上班时间都算下班时间
  294. if (endHoursMin >= enWrokTime) {
  295. endHoursMin = enWrokTime;
  296. }
  297. //如果开始时间在freeTimeMon和freeTimeAft之间都算freeTimeAft
  298. if (isFreeTime == true) {
  299. if (beginHoursMin >= freeTimeMon && beginHoursMin <= freeTimeAft) {
  300. beginHoursMin = freeTimeAft;
  301. }
  302. }
  303. //如果结束时间在freeTimeMon和freeTimeAft之间都算freeTimeMon
  304. if (isFreeTime == true) {
  305. if (endHoursMin >= freeTimeMon && endHoursMin <= freeTimeAft) {
  306. endHoursMin = freeTimeMon;
  307. }
  308. }
  309. //获取结束时间-开始时间的天数
  310. var daysBetween = this.diffDay(beginTime.substring(0, 10), endTime.substring(0, 10));
  311. if (daysBetween > 0) {
  312. var hour = enWrokTime - stWorkTime - freeTime;
  313. if (daysBetween == 1) {
  314. //同一天
  315. if(beginHoursMin < freeTimeMon && endHoursMin > freeTimeAft){
  316. hours = (endHoursMin) - (beginHoursMin) - freeTime;
  317. }else{
  318. hours = endHoursMin - beginHoursMin;
  319. }
  320. } else if (daysBetween == 2) {
  321. //跨一天
  322. //第一天的时长
  323. hours = enWrokTime - beginHoursMin;
  324. //是否有午休
  325. if (beginHoursMin <= freeTimeMon)
  326. hours = hours - freeTime;
  327. //第二天的时长
  328. hours += endHoursMin - stWorkTime;
  329. //是否有午休
  330. if (endHoursMin >= freeTimeAft)
  331. hours = hours - freeTime;
  332. } else {
  333. //跨两天以上
  334. //第一天的时长
  335. hours = enWrokTime - beginHoursMin;
  336. //是否有午休
  337. if (beginHoursMin <= freeTimeMon)
  338. hours = hours - freeTime;
  339. //中间时长
  340. hours += (daysBetween - 2) * (hour);
  341. //最后一天时长
  342. hours += endHoursMin - stWorkTime;
  343. //是否有午休
  344. if (endHoursMin >= freeTimeAft)
  345. hours = hours - freeTime;
  346. }
  347. days = Math.floor(hours / hour);
  348. hours = hours % hour;
  349. date = {
  350. "days": days,
  351. "hours": hours
  352. };
  353. }
  354. this.detailData.leaveDuration = Math.round((date.days * 8 + date.hours) * 10) /10
  355. return date;
  356. // var endtime = new Date(this.detailData.endDate)
  357. // var starttime = new Date(this.detailData.startDate)
  358. // console.log(endtime - starttime)
  359. // this.detailData.leaveDuration = Math.floor((endtime - starttime) / (3600 * 1000))
  360. // this.endDate1 = e.year + "-" + e.month + "-" + e.day + "-" + e.hour + "-" + e.minute + "-" + e.second
  361. },
  362. submit() {
  363. if (!this.detailData.leaveType || this.detailData.leaveType == '选择请假类型') {
  364. this.$api.msg('请假类型不能为空')
  365. return
  366. }
  367. if (!this.detailData.startDate) {
  368. this.$api.msg('请选择请假开始时间')
  369. return
  370. }
  371. if (!this.detailData.endDate || this.detailData.endDate == '选择结束时间') {
  372. this.$api.msg('请选择请假结束时间')
  373. return
  374. }
  375. if (!this.detailData.leaveDuration) {
  376. this.$api.msg('请输入请假时长')
  377. return
  378. }
  379. if (!this.detailData.reasonForLeave) {
  380. this.$api.msg('请假事由不能为空')
  381. return
  382. }
  383. var that = this
  384. uni.showModal({
  385. content: "确定提交请假信息?",
  386. showCancel: true,
  387. confirmText: '提交',
  388. success: function(res) {
  389. if (res.confirm) {
  390. that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  391. that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  392. that.detailData.dept = uni.getStorageSync('pcUserInfo').deptName
  393. that.detailData.phone = uni.getStorageSync('pcUserInfo').userMobilePhone
  394. that.detailData.empName = uni.getStorageSync('userInfo').userName
  395. uni.showLoading({
  396. title: '加载中',
  397. mask: true
  398. })
  399. that.$api.doRequest('post', '/leaveInfo/api/addLeave', that.detailData)
  400. .then(res => {
  401. if (res.data.code == 200) {
  402. that.$api.msg('提交成功')
  403. uni.hideLoading()
  404. that.value = 1
  405. that.getList()
  406. uni.navigateTo({
  407. url: '/pages/leave/the_leave_record'
  408. })
  409. } else {
  410. that.$api.msg('提交失败')
  411. }
  412. })
  413. }
  414. }
  415. })
  416. },
  417. clockRecord() {
  418. this.value = 1
  419. uni.setNavigationBarTitle({
  420. title: '请假记录'
  421. });
  422. this.getList()
  423. // uni.navigateTo({
  424. // url: '/pages/leave/the_leave_record'
  425. // })
  426. },
  427. clocksubmit() {
  428. this.value = 0
  429. uni.setNavigationBarTitle({
  430. title: '请假'
  431. });
  432. // uni.navigateTo({
  433. // url: '/pages/leave/the_leave'
  434. // })
  435. },
  436. },
  437. }
  438. </script>
  439. <style lang='scss' scoped>
  440. page {
  441. background: #F5F6FA;
  442. }
  443. .title_b {
  444. margin: 20rpx 20rpx 0rpx 20rpx;
  445. padding: 20rpx 10rpx 20rpx 10rpx;
  446. font-size: 18px;
  447. font-weight: 550;
  448. }
  449. .c-row {
  450. display: -webkit-box;
  451. display: -webkit-flex;
  452. display: flex;
  453. -webkit-box-align: center;
  454. -webkit-align-items: center;
  455. align-items: center;
  456. padding: 20rpx 30rpx;
  457. position: relative;
  458. }
  459. .con-list {
  460. -webkit-box-flex: 1;
  461. -webkit-flex: 1;
  462. flex: 1;
  463. display: -webkit-box;
  464. display: -webkit-flex;
  465. display: flex;
  466. -webkit-box-orient: vertical;
  467. -webkit-box-direction: normal;
  468. -webkit-flex-direction: column;
  469. flex-direction: column;
  470. color: #303133;
  471. line-height: 40rpx;
  472. text-align: right;
  473. padding-right: 20rpx;
  474. }
  475. .wrap {
  476. padding-top: 15px;
  477. padding-bottom: 20px;
  478. font-size: 14px;
  479. background: #fff;
  480. margin: 10px;
  481. border-radius: 10px;
  482. input {
  483. font-size: 14px;
  484. }
  485. >.title {
  486. padding: 10px 16px;
  487. }
  488. .wenzi {
  489. text-align: right;
  490. border-radius: 10rpx;
  491. margin-right: 30rpx;
  492. height: 10rpx;
  493. }
  494. .audit1 {
  495. color: red;
  496. }
  497. .audit2 {
  498. color: #afafe6;
  499. }
  500. .audit3 {
  501. color: red;
  502. }
  503. .c-row {
  504. display: -webkit-box;
  505. display: -webkit-flex;
  506. display: flex;
  507. -webkit-box-align: center;
  508. -webkit-align-items: center;
  509. align-items: center;
  510. padding: 5rpx 30rpx;
  511. position: relative;
  512. }
  513. }
  514. /* .footer {
  515. background: #fff;
  516. position: fixed;
  517. bottom: 0;
  518. width: 100%;
  519. padding: 20px 10px;
  520. z-index: 10;
  521. .button {
  522. background: #22C572;
  523. width: 90%;
  524. margin: 20rpx auto;
  525. padding: 10px;
  526. color: #fff;
  527. text-align: center;
  528. border-radius: 30px;
  529. }
  530. } */
  531. .submit {
  532. width: 40%;
  533. background: #22C572;
  534. border-radius: 10rpx;
  535. }
  536. .bottom-btn {
  537. padding: 30rpx;
  538. background: #FFFFFF;
  539. width: 100%;
  540. position: fixed;
  541. bottom: 0rpx;
  542. z-index: 9999;
  543. }
  544. .buns_item {
  545. display: flex;
  546. padding: 80rpx 0 50rpx 0;
  547. justify-content: space-around;
  548. }
  549. .but_css {
  550. background: #22C572;
  551. width: 40%;
  552. padding: 20rpx;
  553. color: #fff;
  554. text-align: center;
  555. border-radius: 20rpx;
  556. }
  557. /deep/.u-radio-group {
  558. flex-direction: row-reverse;
  559. }
  560. .no-boder {
  561. border: 0;
  562. }
  563. .textarea {
  564. background: #F9F9FA;
  565. border: 1px solid #EEEEEE;
  566. }
  567. .u-page__item__slot-icon {
  568. width: 20px;
  569. height: 20px;
  570. }
  571. .content {
  572. padding-bottom: 150rpx;
  573. overflow: hidden;
  574. }
  575. </style>