index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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,timer2 = 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. clearInterval(timer2)
  106. },
  107. mounted() {
  108. this.getRules();
  109. this.getCurrentLocation();
  110. timer2 = setInterval(()=>{
  111. this.getCurrentLocation();
  112. },5000)
  113. this.getUserInfo();
  114. },
  115. methods:{
  116. getRules(){
  117. this.$api.get('/wms/outsourced/attendance/rule').then(res=>{
  118. if(res.data.code!==0) return this.$showToast(res.data.msg)
  119. this.workingTime = res.data.data.workingTime.slice(0,5);
  120. this.offWorkTime = res.data.data.offWorkTime.slice(0,5);
  121. })
  122. },
  123. getUserInfo(){
  124. this.$api.get('/wms/outsourced/attendance/getAttendanceByUserId/'+this.userInfo?.id).then(res=>{
  125. if(res.data.code!==0) return this.$showToast(res.data.msg)
  126. this.sbClockTime = res.data.data?.checkInTime;
  127. this.xbClockTime = res.data.data?.clockOutTime;
  128. if(new Date().getHours()<12&&!this.sbClockTime) this.isSW = true
  129. else this.isSW = false;
  130. })
  131. },
  132. getDateWeek(){
  133. let date = new Date().Format('yyyy年MM月dd日');
  134. let cfg = {0:'天',1:'一',2:'二',3:'三',4:'四',5:'五',6:'六'};
  135. let week = cfg[new Date().getDay()];
  136. this.dateweek = date+' 星期'+week;
  137. },
  138. getCurrentSFM(){
  139. timer = setInterval(()=>{
  140. this.currentSFM = new Date().Format('hh:mm:ss');
  141. },1000)
  142. },
  143. getCurrentHour(){
  144. this.isSW = new Date().getHours()>12?false:true;
  145. },
  146. clock(){
  147. if(!this.canClock) return
  148. let url = this.isSW?'/wms/outsourced/attendance/checkIn':'/wms/outsourced/attendance/clockOut';
  149. let params = {outUserId:this.userInfo?.id};
  150. params[this.isSW?'checkInTime':'clockOutTime'] = new Date().Format('hh:mm');
  151. this.$api.post(url,params).then(res=>{
  152. if(res.data.code!==0) return this.$showToast(res.data.msg);
  153. this.clockTime = new Date().Format('hh:mm');
  154. this.show = true;
  155. })
  156. },
  157. close(){
  158. this.show = false;
  159. this.getUserInfo();
  160. },
  161. // 获取当前位置
  162. async getCurrentLocation() {
  163. try {
  164. const res = await uni.getLocation({
  165. type: 'gcj02', // 腾讯地图使用GCJ-02坐标系/
  166. isHighAccuracy: true
  167. });
  168. let origin = wgs84togcj02(res[1].longitude,res[1].latitude);
  169. let target = wgs84togcj02(this.targetLocation.longitude,this.targetLocation.latitude);
  170. this.calculateDistance(
  171. origin[1],
  172. origin[0],
  173. target[1],
  174. target[0]
  175. );
  176. this.canClock = this.distance<=50;
  177. } catch (err) {
  178. uni.showToast({
  179. title: '获取位置失败,请检查权限设置',
  180. icon: 'none'
  181. });
  182. }
  183. },
  184. // 计算两点间距离
  185. calculateDistance(lat1, lng1, lat2, lng2) {
  186. qqmapsdk.calculateDistance({
  187. mode: 'straight', // 直线距离
  188. from: `${lat1},${lng1}`,
  189. to: `${lat2},${lng2}`,
  190. success: (res) => {
  191. if(res.result && res.result.elements.length > 0) {
  192. this.distance = res.result.elements[0].distance;
  193. console.log(this.distance,'distance');
  194. }
  195. },
  196. fail: (err) => {
  197. uni.showToast({
  198. title: '距离计算失败',
  199. icon: 'none'
  200. });
  201. }
  202. });
  203. }
  204. }
  205. }
  206. </script>
  207. <style scoped lang="less">
  208. .tabPage{
  209. padding: 0 24rpx 188rpx;
  210. background: #F4F8FB;
  211. .topbg{
  212. width: 100%;
  213. position: fixed;
  214. top: 0;
  215. left: 0;
  216. z-index: 0;
  217. }
  218. .info{
  219. position: relative;
  220. background: #FFFFFF;
  221. border-radius: 16rpx;
  222. margin-top: 20rpx;
  223. padding: 48rpx 24rpx;
  224. display: flex;
  225. align-items: center;
  226. .i_avatar{
  227. width: 98rpx;
  228. height: 98rpx;
  229. image{
  230. width: 100%;
  231. height: 100%;
  232. }
  233. }
  234. .i_name_date{
  235. padding-left: 24rpx;
  236. p{
  237. font-family: PingFang-SC, PingFang-SC;
  238. font-weight: bold;
  239. font-size: 36rpx;
  240. color: #1D2129;
  241. line-height: 36rpx;
  242. &.date{
  243. font-size: 28rpx;
  244. color: #657588;
  245. line-height: 28rpx;
  246. margin-top: 22rpx;
  247. }
  248. }
  249. }
  250. }
  251. .card{
  252. position: relative;
  253. background: #FFFFFF;
  254. border-radius: 16rpx;
  255. padding: 44rpx 24rpx 211rpx;
  256. margin-top: 20rpx;
  257. .c_title{
  258. font-family: PingFang-SC, PingFang-SC;
  259. font-weight: bold;
  260. font-size: 36rpx;
  261. color: #1D2129;
  262. line-height: 36rpx;
  263. }
  264. .c_worktime{
  265. margin-top: 40rpx;
  266. display: flex;
  267. justify-content: space-between;
  268. .cw_pre{
  269. width: calc(50% - 15rpx);
  270. background: #F5F8FA;
  271. border-radius: 16rpx;
  272. position: relative;
  273. padding: 36rpx 20rpx;
  274. box-sizing: border-box;
  275. &>p{
  276. font-family: PingFangSC, PingFang SC;
  277. font-weight: 400;
  278. font-size: 32rpx;
  279. color: #1D2129;
  280. line-height: 32rpx;
  281. }
  282. .cwp_time{
  283. display: flex;
  284. align-items: center;
  285. margin-top: 32rpx;
  286. image{
  287. width: 28rpx;
  288. height: 28rpx;
  289. }
  290. span{
  291. font-family: PingFangSC, PingFang SC;
  292. font-weight: 400;
  293. font-size: 28rpx;
  294. color: #86909C;
  295. line-height: 36rpx;
  296. margin-left: 12rpx;
  297. }
  298. }
  299. .cwp_status{
  300. width: 108rpx;
  301. height: 54rpx;
  302. border-radius: 0rpx 16rpx 0rpx 12rpx;
  303. font-family: PingFang-SC, PingFang-SC;
  304. font-weight: bold;
  305. font-size: 24rpx;
  306. line-height: 54rpx;
  307. text-align: center;
  308. position: absolute;
  309. top: 0;
  310. right: 0;
  311. &.active{
  312. color: #14D08E;
  313. background: rgba(20, 204, 140, 0.08);
  314. }
  315. &.inactive{
  316. color: #86909C;
  317. background: #EFEFEF;
  318. }
  319. }
  320. }
  321. }
  322. .c_clock{
  323. display: flex;
  324. flex-direction: column;
  325. align-items: center;
  326. margin-top: 117rpx;
  327. .cc_box{
  328. width: 306rpx;
  329. height: 306rpx;
  330. background-repeat: no-repeat;
  331. background-size: 100% 100%;
  332. display: flex;
  333. flex-direction: column;
  334. align-items: center;
  335. justify-content: center;
  336. p{
  337. font-family: PingFang-SC, PingFang-SC;
  338. font-weight: bold;
  339. font-size: 40rpx;
  340. color: #FFFFFF;
  341. line-height: 56rpx;
  342. &.time{
  343. font-size: 32rpx;
  344. line-height: 45rpx;
  345. margin-top: 8px;
  346. }
  347. }
  348. }
  349. .cc_location{
  350. margin-top: 64rpx;
  351. display: flex;
  352. align-items: center;
  353. image{
  354. width: 36rpx;
  355. height: 36rpx;
  356. }
  357. span{
  358. font-family: PingFangSC, PingFang SC;
  359. font-weight: 400;
  360. font-size: 26rpx;
  361. color: #86909C;
  362. line-height: 26rpx;
  363. margin-left: 10rpx;
  364. }
  365. }
  366. }
  367. }
  368. .up_box{
  369. background: linear-gradient( 134deg, #E7F4FD 0%, #FFFFFF 100%);
  370. border-radius: 32rpx;
  371. padding: 40rpx;
  372. display: flex;
  373. flex-direction: column;
  374. align-items: center;
  375. .upb_close{
  376. width: 100%;
  377. display: flex;
  378. justify-content: flex-end;
  379. image{
  380. width: 32rpx;
  381. height: 32rpx;
  382. }
  383. }
  384. .upb_text{
  385. width: 210rpx;
  386. height: 50rpx;
  387. margin-top: 16rpx;
  388. }
  389. .upb_time{
  390. font-family: PingFangSC, PingFang SC;
  391. font-weight: 400;
  392. font-size: 28rpx;
  393. color: #86909C;
  394. line-height: 32rpx;
  395. margin-top: 36rpx;
  396. }
  397. .upb_img{
  398. width: 344rpx;
  399. height: 194rpx;
  400. margin-top: 216rpx;
  401. }
  402. .upb_btn{
  403. width: 446rpx;
  404. height: 88rpx;
  405. background: #0171F6;
  406. border-radius: 32rpx;
  407. font-family: PingFang-SC, PingFang-SC;
  408. font-weight: bold;
  409. font-size: 32rpx;
  410. color: #FFFFFF;
  411. line-height: 88rpx;
  412. text-align: center;
  413. margin-top: 112rpx;
  414. letter-spacing: 2rpx;
  415. }
  416. }
  417. }
  418. </style>