You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

299 lines
7.0 KiB

  1. <template>
  2. <view class="">
  3. <view v-if="ready" class="contentBox">
  4. <view class="rules">
  5. <view class="">
  6. <view class="">
  7. 上班 {{info.WorkTime}}
  8. </view>
  9. <view class="">
  10. {{info.UserWorkTime?info.UserWorkTime.substring(8)+' 打卡':'未打卡'}}
  11. </view>
  12. </view>
  13. <view class="">
  14. <view class="">
  15. 下班 {{info.CloseTime}}
  16. </view>
  17. <view class="">
  18. {{info.UserCloseTime?info.UserCloseTime.substring(8)+' 打卡':'未打卡'}}
  19. </view>
  20. </view>
  21. </view>
  22. <view class="content" id="attendContent">
  23. <view id="show">{{now}}</view>
  24. <view class="pen" @click="action('dk')">
  25. <img :class="{gray:info.AttendanceType != 1}" id="attimg" :src="imgsrc" alt="" width="100%">
  26. </view>
  27. <view class="title">
  28. {{info.AttendanceTypeString}}
  29. </view>
  30. </view>
  31. <view class="footer">
  32. <img src="../../common/images/2.png" alt="" width="100%">
  33. </view>
  34. </view>
  35. <view id='container'></view>
  36. </view>
  37. </template>
  38. <script>
  39. /*
  40. * 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
  41. * Copyright (c) 2013-2020 上海力软信息技术有限公司
  42. * 创建人:超级管理员
  43. * 日 期:2022-03-10 15:30
  44. * 描 述:考勤打卡
  45. */
  46. /**
  47. * 本段代码由移动端代码生成器输出,移动端须 2.2.0 版本及以上可以使用
  48. * 请在移动端 /pages.json 中的 pages 字段中添加一条记录:
  49. * { "path": "pages/AttendanceCard/list", "style": { "navigationBarTitleText": "考勤打卡" } }
  50. *
  51. * (navigationBarTitleText 字段为本页面的标题文本,可以修改)
  52. * (必须自行操作该步骤,力软代码生成器不会自动帮您修改 /pages.json 文件)
  53. */
  54. import get from 'lodash/get'
  55. import set from 'lodash/set'
  56. import moment from 'moment'
  57. import customPageMixins from '@/common/custompage.js'
  58. //导入图片
  59. import dk from '../../common/images/dk.png'
  60. import dkred from '../../common/images/dkred.png'
  61. import dkyellow from '../../common/images/dkyellow.png'
  62. export default {
  63. mixins: [customPageMixins],
  64. data() {
  65. return {
  66. // 页面相关参数
  67. info:{},
  68. now: null,
  69. imgsrc:dk,
  70. ready: false,
  71. timer:'',
  72. map:null,
  73. }
  74. },
  75. async onLoad() {
  76. await this.init()
  77. },
  78. methods: {
  79. // 页面初始化
  80. async init() {
  81. this.LOADING('加载数据中...')
  82. this.now = this.getCurrentTime()
  83. this.timer = setInterval(this.getCurrentTime,1000)
  84. await this.judgeIsDK()
  85. this.ready = true
  86. this.HIDE_LOADING()
  87. },
  88. // 点击 「打卡」按钮
  89. async action(type) {
  90. switch (type) {
  91. case 'dk':
  92. if(this.imgsrc == dkred){
  93. return
  94. }
  95. this.LOADING()
  96. this.HTTP_POST('learun/adms/attendance/clockin', {}, '打卡失败').then(success => {
  97. this.HIDE_LOADING()
  98. if(!success) {
  99. this.TOAST('打卡失败')
  100. return
  101. }
  102. this.TOAST('打卡成功','success')
  103. setTimeout(this.back,500)
  104. })
  105. return
  106. default: break
  107. }
  108. },
  109. //判断当前时间是否可以打卡
  110. async judgeIsDK(){
  111. let success = await this.HTTP_GET('learun/adms/attendance/IsAttendance',{},'判断当前时间是否可以打卡失败')
  112. if(!success){return}
  113. this.info = success.data
  114. this.imgsrc=dk;
  115. // if ([1].includes(this.info.AttendanceType)) {
  116. // this.imgsrc=dk;
  117. // } else if ([2,3].includes(this.info.AttendanceType)) {
  118. // this.imgsrc=dkyellow;
  119. // }else {
  120. // this.imgsrc=dkred;
  121. // }
  122. if(![5].includes(this.info.AttendanceType)){
  123. if(!window.BMapGL) await this.loadJScript()
  124. this.map = new BMapGL.Map('container');
  125. await this.isFieldPersonnel()
  126. }
  127. },
  128. //返回
  129. back(){
  130. this.NAV_BACK()
  131. },
  132. //获取当前时间
  133. getCurrentTime() {
  134. let nowDate = new Date();
  135.   let hh = nowDate.getHours();
  136.   let mf = nowDate.getMinutes()<10 ? '0'+nowDate.getMinutes() : nowDate.getMinutes();
  137.   let ss = nowDate.getSeconds()<10 ? '0'+nowDate.getSeconds() : nowDate.getSeconds();
  138.   this.now = hh+':'+mf+':'+ss;
  139. },
  140. // 判断是否外勤打卡
  141. async isFieldPersonnel(){
  142. let point = new BMapGL.Point(this.info.GPSLon,this.info.GPSLat)
  143. await this.getDistance(point)
  144. },
  145. //异步加载地图
  146. loadJScript() {
  147. return new Promise((resolve,reject)=>{
  148. window.initMap = function(){
  149. resolve(BMapGL)
  150. }
  151. var script = document.createElement('script');
  152. script.type = 'text/javascript';
  153. script.src = 'https://api.map.baidu.com/api?v=1.0&type=webgl&ak=j1TvNK854LRvVuxuAhNNxdhKVB0KbEZD'+'&callback='+'initMap';
  154. script.onerror = reject
  155. document.head.appendChild(script);
  156. })
  157. },
  158. // 计算距离打卡点的距离
  159. // 签到状态(1正常打卡,2迟到打卡,3早退打卡,4外勤打卡,5不在考勤时间范围)
  160. async getDistance(myP1) {
  161. // new BMapGL.Point(116.404, 39.915)
  162. let myP2 = await this.local();
  163. let distance = this.map.getDistance(myP1, myP2).toFixed(2)
  164. console.log(distance)
  165. if(Number(distance) > Number(this.info.GPSRange)){
  166. this.$set(this.info,'AttendanceType',4)
  167. this.$set(this.info,'AttendanceTypeString','外勤打卡')
  168. }
  169. },
  170. // 获取当前位置
  171. local() {
  172. return new Promise((resolve) => {
  173. // 创建定位对象
  174. let geolocation = new BMapGL.Geolocation();
  175. geolocation.getCurrentPosition(
  176. async function (r) {
  177. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  178. resolve(r.point);
  179. } else {
  180. resolve(new BMapGL.Point(116.404, 39.915)); //北京
  181. }
  182. },
  183. { enableHighAccuracy: true }
  184. );
  185. navigator.geolocation.clearWatch(geolocation);
  186. });
  187. }
  188. },
  189. destroyed() {
  190. clearInterval(this.timer)
  191. }
  192. }
  193. </script>
  194. <style lang="less">
  195. uni-page-body{
  196. height: 100%;
  197. width: 100%;
  198. background-color: #fff;
  199. }
  200. .content {
  201. width: 48%;
  202. height: 50%;
  203. position: absolute;
  204. top: 15%;
  205. left: 50%;
  206. transform: translate(-50%, 10%);
  207. }
  208. .title{
  209. font-size: 14px;
  210. text-align: center;
  211. color: #333;
  212. margin-top: 8px;
  213. }
  214. .rules{
  215. display: flex;
  216. justify-content: space-between;
  217. color: #666;
  218. padding: 15px;
  219. line-height: 24px;
  220. }
  221. .rules>*{
  222. width: 49%;
  223. background-color: #BDE4FF;
  224. padding: 8px;
  225. border-radius: 8px 12px;
  226. }
  227. .rules>*>*:first-child{
  228. color: #333;
  229. }
  230. #show {
  231. text-align: center;
  232. height: 200rpx;
  233. font-size: 56rpx;
  234. }
  235. .pen {
  236. height: 48%;
  237. border-radius: 50%;
  238. background-color: #e7f5ff;
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. }
  243. .pen2 {
  244. width: 91%;
  245. height: 91%;
  246. border-radius: 50%;
  247. background-color: #bde4ff;
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. }
  252. .pen3 {
  253. width: 84%;
  254. height: 84%;
  255. border-radius: 50%;
  256. background-color: #0c86d8;
  257. text-align: center;
  258. font-size: 68rpx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. color: #ffff;
  263. }
  264. .footer {
  265. width: 100%;
  266. position: fixed;
  267. left: 0;
  268. bottom: 0;
  269. overflow: hidden;
  270. }
  271. .gray{
  272. -webkit-filter: grayscale(100%);
  273. -moz-filter: grayscale(100%);
  274. -ms-filter: grayscale(100%);
  275. -o-filter: grayscale(100%);
  276. filter: grayscale(100%);
  277. filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  278. filter: gray;
  279. }
  280. </style>