index.vue 12 KB

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