index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view class="tabPage" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='打卡' bgColor="transparent" :showback="false"></cus-header>
  4. <image class="topbg" :src="imgBase+'clockingin/topbg.png'" mode="widthFix"></image>
  5. <div class="info">
  6. <div class="i_avatar">
  7. <image :src="imgBase+'clockingin/default_avatar.png'"></image>
  8. </div>
  9. <div class="i_name_date">
  10. <p>{{username}}</p>
  11. <p class="date">{{dateweek}}</p>
  12. </div>
  13. </div>
  14. <div class="card">
  15. <div class="c_title">今日打卡</div>
  16. <div class="c_worktime">
  17. <div class="cw_pre">
  18. <p>上班{{workingTime||'08:30'}}</p>
  19. <div class="cwp_time">
  20. <image :src="imgBase+'clockingin/checked_active.png'" v-if="sbClockTime"></image>
  21. <image :src="imgBase+'clockingin/checked_inactive.png'" v-else></image>
  22. <span>打卡{{sbClockTime||'- -'}}</span>
  23. </div>
  24. <div class="cwp_status" :class="{'active':sbClockTime,'inactive':!sbClockTime}">{{sbClockTime?'已打卡':'未打卡'}}</div>
  25. </div>
  26. <div class="cw_pre">
  27. <p>下班{{offWorkTime||'17:30'}}</p>
  28. <div class="cwp_time">
  29. <image :src="imgBase+'clockingin/checked_active.png'" v-if="xbClockTime"></image>
  30. <image :src="imgBase+'clockingin/checked_inactive.png'" v-else></image>
  31. <span>{{xbClockTime||'- -'}}</span>
  32. </div>
  33. <div class="cwp_status" :class="{'active':xbClockTime,'inactive':!xbClockTime}">{{xbClockTime?'已打卡':'未打卡'}}</div>
  34. </div>
  35. </div>
  36. <div class="c_clock">
  37. <!-- <div class="cc_box" :style="{'background-image':'url('+imgBase+(canClock?'clockingin/clock_active_bg.png':'clockingin/clock_inactive_bg.png')+')'}" @tap="clock"> -->
  38. <div class="cc_box" :style="{'background-image':'url('+imgBase+'clockingin/clock_active_bg.png)'}" @tap="clock">
  39. <p>{{isSW?'上班':'下班'}}打卡</p>
  40. <p class="time">{{currentSFM}}</p>
  41. </div>
  42. <div class="cc_location">
  43. <!-- <image :src="imgBase+(canClock?'clockingin/location_active.png':'clockingin/location_inactive.png')"></image> -->
  44. <image :src="imgBase+'clockingin/location_active.png'"></image>
  45. <span v-if="canClock">已进入考勤范围:谷锐特设备自动化有限公司</span>
  46. <span v-else>当前定位不在考勤范围内</span>
  47. </div>
  48. </div>
  49. <!-- <p style="text-align: center;font-size: 32rpx;padding: 20rpx 0;font-weight: bold;">当前定位直线距离:{{distance}}米</p> -->
  50. </div>
  51. <u-popup :show="show" @close="close" mode="center" :round="32" :customStyle="{'width':'calc(100% - 120rpx)'}">
  52. <div class="up_box">
  53. <div class="upb_close">
  54. <image :src="imgBase+'clockingin/close.png'" @tap="close"></image>
  55. </div>
  56. <image class="upb_text" :src="imgBase+'clockingin/clock_success.png'"></image>
  57. <p class="upb_time">打卡时间 {{clockTime}}</p>
  58. <image class="upb_img" :src="imgBase+'clockingin/clock_success2.png'"></image>
  59. <div class="upb_btn" @tap="close">我知道了</div>
  60. </div>
  61. </u-popup>
  62. <Tabbar :tabbarIndex="0"></Tabbar>
  63. </view>
  64. </template>
  65. <script>
  66. var timer = null,timer2 = null;
  67. const QQMapWX = require('../static/lib/qqmap-wx-jssdk.min.js');
  68. const qqmapsdk = new QQMapWX({
  69. key: 'V3NBZ-6NRKT-QOQXY-LU6RY-PNHJ5-QDBTQKEY'
  70. });
  71. import { wgs84togcj02 } from '@/utils/coordtransform.js';
  72. import Tabbar from '@/components/CusTabbar/clock.vue'
  73. export default {
  74. components:{ Tabbar },
  75. data(){
  76. return {
  77. username:'',
  78. dateweek:'',
  79. workingTime:'',
  80. offWorkTime:'',
  81. sbClockTime:'',
  82. xbClockTime:'',
  83. isSW:true,//是否是上午,12点前是上午/12点前上午打过卡就是下午了,12点后是下午
  84. currentSFM:new Date().Format('hh:mm:ss'),
  85. show:false,
  86. canClock:false,
  87. clockTime:'',
  88. distance: null,
  89. targetLocation: { //谷锐特 31.962084,117.020446 /跨境电商大厦 31.865786,117.15297
  90. latitude: 31.962084,
  91. longitude: 117.020446
  92. },
  93. userInfo:null,
  94. canClick:true
  95. }
  96. },
  97. created() {
  98. this.getDateWeek();
  99. this.getCurrentSFM();
  100. this.getCurrentHour();
  101. if(uni.getStorageSync('userInfo')){
  102. this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
  103. this.username = this.userInfo.realName;
  104. }
  105. },
  106. onUnload() {
  107. clearInterval(timer)
  108. clearInterval(timer2)
  109. },
  110. mounted() {
  111. this.getRules();
  112. this.getCurrentLocation();
  113. timer2 = setInterval(()=>{
  114. this.getCurrentLocation();
  115. },5000)
  116. this.getUserInfo();
  117. },
  118. methods:{
  119. getRules(){
  120. this.$api.get('/wms/outsourced/attendance/rule').then(res=>{
  121. if(res.data.code!==0) return this.$showToast(res.data.msg)
  122. this.workingTime = res.data.data.workingTime.slice(0,5);
  123. this.offWorkTime = res.data.data.offWorkTime.slice(0,5);
  124. })
  125. },
  126. getUserInfo(){
  127. this.$api.get('/wms/outsourced/attendance/getAttendanceByUserId/'+this.userInfo?.id).then(res=>{
  128. if(res.data.code!==0) return this.$showToast(res.data.msg)
  129. this.sbClockTime = res.data.data?.checkInTime;
  130. this.xbClockTime = res.data.data?.clockOutTime;
  131. if(new Date().getHours()<12&&!this.sbClockTime) this.isSW = true
  132. else this.isSW = false;
  133. })
  134. },
  135. getDateWeek(){
  136. let date = new Date().Format('yyyy年MM月dd日');
  137. let cfg = {0:'天',1:'一',2:'二',3:'三',4:'四',5:'五',6:'六'};
  138. let week = cfg[new Date().getDay()];
  139. this.dateweek = date+' 星期'+week;
  140. },
  141. getCurrentSFM(){
  142. timer = setInterval(()=>{
  143. this.currentSFM = new Date().Format('hh:mm:ss');
  144. },1000)
  145. },
  146. getCurrentHour(){
  147. this.isSW = new Date().getHours()>12?false:true;
  148. },
  149. clock(){
  150. if(!this.canClick) return
  151. let url = this.isSW?'/wms/outsourced/attendance/checkIn':'/wms/outsourced/attendance/clockOut';
  152. let params = {outUserId:this.userInfo?.id};
  153. params[this.isSW?'checkInTime':'clockOutTime'] = new Date().Format('yyyy-MM-dd hh:mm');
  154. if(!this.canClock){
  155. uni.navigateTo({
  156. url:`/pagesClockin/fieldService?url=${url}&outUserId=${this.userInfo?.id}&isSW=${this.isSW?1:0}`
  157. })
  158. return
  159. }
  160. this.canClick = false;
  161. this.$api.post(url,params).then(res=>{
  162. if(res.data.code!==0) return this.$showToast(res.data.msg);
  163. this.clockTime = new Date().Format('hh:mm');
  164. this.show = true;
  165. this.canClick = true;
  166. })
  167. },
  168. close(){
  169. this.show = false;
  170. this.getUserInfo();
  171. },
  172. // 获取当前位置
  173. async getCurrentLocation() {
  174. try {
  175. const res = await uni.getLocation({
  176. type: 'gcj02', // 腾讯地图使用GCJ-02坐标系/
  177. isHighAccuracy: true
  178. });
  179. let origin = wgs84togcj02(res[1].longitude,res[1].latitude);
  180. let target = wgs84togcj02(this.targetLocation.longitude,this.targetLocation.latitude);
  181. this.calculateDistance(
  182. origin[1],
  183. origin[0],
  184. target[1],
  185. target[0]
  186. );
  187. this.canClock = this.distance<=50;
  188. } catch (err) {
  189. uni.showToast({
  190. title: '获取位置失败,请检查权限设置',
  191. icon: 'none'
  192. });
  193. }
  194. },
  195. // 计算两点间距离
  196. calculateDistance(lat1, lng1, lat2, lng2) {
  197. qqmapsdk.calculateDistance({
  198. mode: 'straight', // 直线距离
  199. from: `${lat1},${lng1}`,
  200. to: `${lat2},${lng2}`,
  201. success: (res) => {
  202. if(res.result && res.result.elements.length > 0) {
  203. this.distance = res.result.elements[0].distance;
  204. }
  205. },
  206. fail: (err) => {
  207. uni.showToast({
  208. title: '距离计算失败',
  209. icon: 'none'
  210. });
  211. }
  212. });
  213. }
  214. }
  215. }
  216. </script>
  217. <style scoped lang="less">
  218. .tabPage{
  219. padding: 0 24rpx 188rpx;
  220. background: #F4F8FB;
  221. .topbg{
  222. width: 100%;
  223. position: fixed;
  224. top: 0;
  225. left: 0;
  226. z-index: 0;
  227. }
  228. .info{
  229. position: relative;
  230. background: #FFFFFF;
  231. border-radius: 16rpx;
  232. margin-top: 20rpx;
  233. padding: 48rpx 24rpx;
  234. display: flex;
  235. align-items: center;
  236. .i_avatar{
  237. width: 98rpx;
  238. height: 98rpx;
  239. image{
  240. width: 100%;
  241. height: 100%;
  242. }
  243. }
  244. .i_name_date{
  245. padding-left: 24rpx;
  246. p{
  247. font-family: PingFang-SC, PingFang-SC;
  248. font-weight: bold;
  249. font-size: 36rpx;
  250. color: #1D2129;
  251. line-height: 36rpx;
  252. &.date{
  253. font-size: 28rpx;
  254. color: #657588;
  255. line-height: 28rpx;
  256. margin-top: 22rpx;
  257. }
  258. }
  259. }
  260. }
  261. .card{
  262. position: relative;
  263. background: #FFFFFF;
  264. border-radius: 16rpx;
  265. padding: 44rpx 24rpx 211rpx;
  266. margin-top: 20rpx;
  267. .c_title{
  268. font-family: PingFang-SC, PingFang-SC;
  269. font-weight: bold;
  270. font-size: 36rpx;
  271. color: #1D2129;
  272. line-height: 36rpx;
  273. }
  274. .c_worktime{
  275. margin-top: 40rpx;
  276. display: flex;
  277. justify-content: space-between;
  278. .cw_pre{
  279. width: calc(50% - 15rpx);
  280. background: #F5F8FA;
  281. border-radius: 16rpx;
  282. position: relative;
  283. padding: 36rpx 20rpx;
  284. box-sizing: border-box;
  285. &>p{
  286. font-family: PingFangSC, PingFang SC;
  287. font-weight: 400;
  288. font-size: 32rpx;
  289. color: #1D2129;
  290. line-height: 32rpx;
  291. }
  292. .cwp_time{
  293. display: flex;
  294. align-items: center;
  295. margin-top: 32rpx;
  296. image{
  297. width: 28rpx;
  298. height: 28rpx;
  299. }
  300. span{
  301. font-family: PingFangSC, PingFang SC;
  302. font-weight: 400;
  303. font-size: 28rpx;
  304. color: #86909C;
  305. line-height: 36rpx;
  306. margin-left: 12rpx;
  307. }
  308. }
  309. .cwp_status{
  310. width: 108rpx;
  311. height: 54rpx;
  312. border-radius: 0rpx 16rpx 0rpx 12rpx;
  313. font-family: PingFang-SC, PingFang-SC;
  314. font-weight: bold;
  315. font-size: 24rpx;
  316. line-height: 54rpx;
  317. text-align: center;
  318. position: absolute;
  319. top: 0;
  320. right: 0;
  321. &.active{
  322. color: #14D08E;
  323. background: rgba(20, 204, 140, 0.08);
  324. }
  325. &.inactive{
  326. color: #86909C;
  327. background: #EFEFEF;
  328. }
  329. }
  330. }
  331. }
  332. .c_clock{
  333. display: flex;
  334. flex-direction: column;
  335. align-items: center;
  336. margin-top: 117rpx;
  337. .cc_box{
  338. width: 306rpx;
  339. height: 306rpx;
  340. background-repeat: no-repeat;
  341. background-size: 100% 100%;
  342. display: flex;
  343. flex-direction: column;
  344. align-items: center;
  345. justify-content: center;
  346. p{
  347. font-family: PingFang-SC, PingFang-SC;
  348. font-weight: bold;
  349. font-size: 40rpx;
  350. color: #FFFFFF;
  351. line-height: 56rpx;
  352. &.time{
  353. font-size: 32rpx;
  354. line-height: 45rpx;
  355. margin-top: 8px;
  356. }
  357. }
  358. }
  359. .cc_location{
  360. margin-top: 64rpx;
  361. display: flex;
  362. align-items: center;
  363. image{
  364. width: 36rpx;
  365. height: 36rpx;
  366. }
  367. span{
  368. font-family: PingFangSC, PingFang SC;
  369. font-weight: 400;
  370. font-size: 26rpx;
  371. color: #86909C;
  372. line-height: 26rpx;
  373. margin-left: 10rpx;
  374. }
  375. }
  376. }
  377. }
  378. .up_box{
  379. background: linear-gradient( 134deg, #E7F4FD 0%, #FFFFFF 100%);
  380. border-radius: 32rpx;
  381. padding: 40rpx;
  382. display: flex;
  383. flex-direction: column;
  384. align-items: center;
  385. .upb_close{
  386. width: 100%;
  387. display: flex;
  388. justify-content: flex-end;
  389. image{
  390. width: 32rpx;
  391. height: 32rpx;
  392. }
  393. }
  394. .upb_text{
  395. width: 210rpx;
  396. height: 50rpx;
  397. margin-top: 16rpx;
  398. }
  399. .upb_time{
  400. font-family: PingFangSC, PingFang SC;
  401. font-weight: 400;
  402. font-size: 28rpx;
  403. color: #86909C;
  404. line-height: 32rpx;
  405. margin-top: 36rpx;
  406. }
  407. .upb_img{
  408. width: 344rpx;
  409. height: 194rpx;
  410. margin-top: 216rpx;
  411. }
  412. .upb_btn{
  413. width: 446rpx;
  414. height: 88rpx;
  415. background: #0171F6;
  416. border-radius: 32rpx;
  417. font-family: PingFang-SC, PingFang-SC;
  418. font-weight: bold;
  419. font-size: 32rpx;
  420. color: #FFFFFF;
  421. line-height: 88rpx;
  422. text-align: center;
  423. margin-top: 112rpx;
  424. letter-spacing: 2rpx;
  425. }
  426. }
  427. }
  428. </style>