the_leave.vue 17 KB

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