index.vue 11 KB

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