index.vue 11 KB

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