index.vue 11 KB

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