attence.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view>
  3. <u-navbar
  4. title="考勤"
  5. title-color="#fff"
  6. :custom-back="customBack"
  7. :border-bottom="false"
  8. back-icon-color="#CCE8FF"
  9. :background="{background: 'linear-gradient(145deg, #41AFF9 0%, #2D8CFB 100%)' }">
  10. </u-navbar>
  11. <view class="wrap">
  12. <view class="payeeinfo u-flex">
  13. <u-image src="../../static/img/default-portrait.png" width="87" height="87"></u-image>
  14. <view class="payeeinfo-text">
  15. <view class="name">{{payeeinfo.payeeName||'智慧停车'}}</view>
  16. <view class="id">工号:{{payeeinfo.payeeNo}}</view>
  17. </view>
  18. </view>
  19. <view class="attence-block">
  20. <view class="today-attence u-flex">
  21. <view class="today-attence-item">
  22. <view class="work-time">上班:{{payeeinfo.workStartTime?payeeinfo.workStartTime.slice(11):''}}</view>
  23. <view class="my-time" v-if="payeeinfo.isPunchIn">
  24. <u-icon name="checkmark-circle-fill" color="#2979ff" size="28"></u-icon>
  25. {{payeeinfo.punchInTime?payeeinfo.punchInTime.slice(11):''}}已打卡
  26. </view>
  27. <view class="my-time" v-else>未打卡</view>
  28. </view>
  29. <view class="today-attence-item">
  30. <view class="work-time">下班:{{payeeinfo.workEndTime?payeeinfo.workEndTime.slice(11):''}}</view>
  31. <view class="my-time" v-if="payeeinfo.isPunchOut">
  32. <u-icon name="checkmark-circle-fill" color="#2979ff" size="28"></u-icon>
  33. {{payeeinfo.punchOutTime?payeeinfo.punchOutTime.slice(11):''}}已打卡
  34. </view>
  35. <view class="my-time" v-else>未打卡</view>
  36. </view>
  37. </view>
  38. <view class="attence-button u-flex u-flex-wrap" @click="handlePunchIn">
  39. <view class="attence-button-type">{{workType|filterWorkType}}打卡</view>
  40. <view class="attence-button-time">{{ $u.timeFormat(currentTime, 'hh:MM:ss') }}</view>
  41. </view>
  42. <view class="position-tip" v-if="!outPosition&&positionInfo">
  43. <u-icon name="checkmark-circle-fill" color="#21CF3D" size="28"></u-icon>
  44. 您已进入考勤范围:{{payeeinfo.roadName}}
  45. </view>
  46. <view class="position-tip" v-else-if="outPosition&&positionInfo">
  47. <u-icon name="checkmark-circle-fill" color="#da0808" size="28"></u-icon>
  48. 您已超出考勤范围:{{payeeinfo.roadName}}
  49. </view>
  50. <!-- <view class="statistics u-flex">
  51. <view class="statistics-item">
  52. <view class="statistics-item-til">本月已打卡</view>
  53. <view class="statistics-item-con">
  54. <span class="number">{{payeeinfo.punched}}</span>
  55. </view>
  56. </view>
  57. <view class="statistics-item">
  58. <view class="statistics-item-til">月目标打卡</view>
  59. <view class="statistics-item-con">
  60. <span class="number">{{payeeinfo.punchTotal}}</span>
  61. </view>
  62. </view>
  63. </view> -->
  64. <map id="navmap" scale="12" :latitude="latitude" :longitude="longitude" :markers="covers" :circles="circles" ></map>
  65. </view>
  66. </view>
  67. <!-- <u-bottom color="#949494">
  68. <view class="bottom" slot="content">
  69. 城市智慧停车 版权所有
  70. </view>
  71. </u-bottom> -->
  72. <u-popup class="remark" v-model="remarkPopupShow" @close="remarkClose" mode="top">
  73. <u-button class="submit-btn" type="primary" size="mini" @click="getPunchIn">打卡</u-button>
  74. <view class="content">
  75. <u-form-item
  76. label="备注"
  77. :label-style="{fontSize:'36rpx'}"
  78. label-position="top">
  79. <u-input v-model="remark" type="textarea" />
  80. </u-form-item>
  81. <view class="remark-tip" v-if="remarkTip">{{remarkTip}}</view>
  82. </view>
  83. </u-popup>
  84. <u-toast ref="uToast" />
  85. </view>
  86. </template>
  87. <script>
  88. //#ifdef APP-PLUS
  89. var ALog = uni.requireNativePlugin("AndroidLog")
  90. var location = uni.requireNativePlugin("Location")
  91. //#endif
  92. export default{
  93. data(){
  94. return{
  95. roadNo:'',
  96. payeeinfo:[],
  97. theRoad:[],
  98. currentTime: new Date().getTime(), // 获取当前时间
  99. outPosition:true,//是否超出打卡范围
  100. positionInfo:false,//是否线上位置关系信息
  101. remarkPopupShow:false,//备注弹框
  102. remarkTip:'',
  103. remark:'',
  104. workType:1,
  105. punchDistance:0, //打卡距离
  106. punchRange:0, //打卡范围
  107. outwork:0, //是否外勤 0-否 1-是
  108. punchAddress:'', //打卡地址
  109. // 地图
  110. covers: [],
  111. circles:[{
  112. latitude: '',
  113. longitude: '',
  114. radius: 300,
  115. strokeWidth: 1,
  116. color: "#428BCA88",
  117. fillColor: "#B6E1F248",
  118. }],
  119. latitude: '',
  120. longitude: '',
  121. }
  122. },
  123. onLoad(){
  124. },
  125. onShow() {
  126. let that = this;
  127. setInterval(function () {
  128. that.currentTime = new Date().getTime()//修改数据让他可以实时更新
  129. }, 1000);
  130. this.payeeinfo = this.$store.state.vuex_user;
  131. this.roadNo = this.payeeinfo?.roadList?.[0]?.roadNo;
  132. // console.log(' this.payeeinfo1', this.payeeinfo);
  133. this.getPunchInfo(this.roadNo);
  134. },
  135. methods:{
  136. getLocation(){
  137. //#ifdef APP-PLUS
  138. ALog?.info({msg:'请求定位'});
  139. //#endif
  140. uni.showLoading({ title: '定位中'});
  141. let that = this;
  142. uni.getLocation({
  143. type:"gcj02",
  144. geocode: true,
  145. success : function (res) {
  146. uni.hideLoading();
  147. var dst = `${that.payeeinfo.latitude},${that.payeeinfo.longitude}`;
  148. var src = res.latitude + ',' + res.longitude;
  149. ALog?.info({msg: "返回数据:" + JSON.stringify(res)});
  150. var locRet = location?.distance?.(src, dst);
  151. that.positionInfo = true;
  152. that.punchDistance = locRet.distance;
  153. that.punchRange = that.payeeinfo.workDistance;
  154. that.punchAddress = res?.address?.province + res?.address?.city
  155. + res?.address?.district + res?.address?.street + res?.address?.streetNum;
  156. if(locRet.distance <= that.payeeinfo.workDistance){//在打卡范围内
  157. that.outPosition = false;
  158. that.outwork = 0;
  159. if(that.workType==1){
  160. let workStartTime = new Date(that.payeeinfo.workStartTime.replace(/-/g,'/'));
  161. if(that.currentTime<=workStartTime.getTime()){
  162. }else{//迟到
  163. that.remarkTip = '您已迟到!';
  164. that.remarkPopupShow = true;
  165. return;
  166. }
  167. console.log('workStartTime',workStartTime.getTime())
  168. }else if(that.workType==2){
  169. if(that.payeeinfo.isPunchOut){
  170. that.$refs.uToast.show({
  171. title: '已经打过下班卡!',
  172. type: 'error',
  173. });
  174. return;
  175. };
  176. let workEndTime = new Date(that.payeeinfo.workEndTime.replace(/-/g,'/'));
  177. if(that.currentTime<=workEndTime.getTime()){//
  178. that.remarkTip = '还未到下班时间,现在打卡将视为早退!';
  179. that.remarkPopupShow = true;
  180. return;
  181. }
  182. console.log('workEndTime',workEndTime.getTime())
  183. }
  184. that.getPunchIn();
  185. }else{//不在打卡范围内
  186. that.outPosition = true;
  187. that.outwork = 1;
  188. // that.remarkPopupShow = true;
  189. // console.table({locRet:locRet,workDistance:that.payeeinfo.workDistance,r:locRet<=that.payeeinfo.workDistance});
  190. that.$refs.uToast.show({
  191. title: '超出打卡范围!',
  192. type: 'error',
  193. });
  194. };
  195. },
  196. fail: function(res){
  197. uni.hideLoading();
  198. console.log('getLocation err',res)
  199. //#ifdef APP-PLUS
  200. ALog?.info({msg:'请求错误',err:res})
  201. //#endif
  202. }
  203. })
  204. },
  205. handlePunchIn(){
  206. this.getLocation();
  207. },
  208. remarkClose(){
  209. this.remark = '';
  210. },
  211. getPunchIn(){
  212. let that = this;
  213. let param ={
  214. latitude:that.payeeinfo.latitude,
  215. longitude:that.payeeinfo.longitude,
  216. remark:that.remark,
  217. roadNo:that.payeeinfo.roadNo,
  218. workType:that.workType,
  219. punchDistance: that.punchDistance,
  220. punchRange: that.punchRange,
  221. outwork: that.outwork,
  222. punchAddress: that.punchAddress
  223. }
  224. that.$u.api.punchIn(param)
  225. .then(res=>{
  226. this.$refs.uToast.show({
  227. title: res.msg,
  228. type: 'success',
  229. });
  230. this.remarkPopupShow = false;
  231. this.getPunchInfo(this.roadNo);
  232. console.log('this.punchIn',res)
  233. }).catch(err=>{
  234. if(err.errMsg){
  235. this.$refs.uToast.show({
  236. title: '请检查网络',
  237. type: 'error',
  238. });
  239. return false;
  240. };
  241. this.$refs.uToast.show({
  242. title: err.msg,
  243. type: 'error',
  244. });
  245. console.log('punchIn ',err)
  246. });
  247. },
  248. customBack(){
  249. uni.navigateBack({
  250. delta: 1
  251. });
  252. },
  253. getPunchInfo(roadNo){
  254. this.$u.api.punchInfo({roadNo:roadNo})
  255. .then(res=>{
  256. // this.$refs.uToast.show({
  257. // title: res.msg,
  258. // type: 'success',
  259. // });
  260. this.payeeinfo ={...this.payeeinfo,...res.data};
  261. // console.log('getPunchInfo res',res);
  262. this.latitude = res.data.latitude;
  263. this.longitude = res.data.longitude;
  264. this.circles[0].latitude = res.data.latitude;
  265. this.circles[0].longitude = res.data.longitude;
  266. this.circles[0].radius = res.data.workDistance;
  267. console.log('this.circles',this.circles);
  268. let mark = {
  269. latitude:res.data.latitude,
  270. longitude:res.data.longitude
  271. };
  272. this.covers.push(mark);
  273. if(!res.data.isPunchIn){//还未打上班卡
  274. this.workType = 1;
  275. }
  276. else{//已打上班卡
  277. this.workType = 2;
  278. }
  279. // console.log('this.payeeinfo',this.payeeinfo)
  280. }).catch(err=>{
  281. if(err.errMsg){
  282. this.$refs.uToast.show({
  283. title: '请检查网络',
  284. type: 'error',
  285. });
  286. return false;
  287. };
  288. this.$refs.uToast.show({
  289. title: err.msg,
  290. type: 'error',
  291. });
  292. console.log('punchInfo ',err)
  293. });
  294. }
  295. },
  296. filters:{
  297. filterWorkType(WorkType){
  298. return (WorkType==1)?'上班':'下班'
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="scss">
  304. @import './attence.scss'
  305. </style>