attence.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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="13" :latitude="latitude" :longitude="longitude" :markers="covers" ></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="bottom">
  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. var ALog = uni.requireNativePlugin("AndroidLog")
  89. var location = uni.requireNativePlugin("Location")
  90. export default{
  91. data(){
  92. return{
  93. roadNo:'',
  94. payeeinfo:[],
  95. theRoad:[],
  96. currentTime: new Date().getTime(), // 获取当前时间
  97. outPosition:true,//是否超出打卡范围
  98. positionInfo:false,//是否线上位置关系信息
  99. remarkPopupShow:false,//备注弹框
  100. remarkTip:'',
  101. remark:'',
  102. workType:1,
  103. // 地图
  104. covers: [],
  105. latitude: '',
  106. longitude: '',
  107. }
  108. },
  109. onLoad(){
  110. },
  111. onShow() {
  112. let that = this;
  113. setInterval(function () {
  114. that.currentTime = new Date().getTime()//修改数据让他可以实时更新
  115. }, 1000);
  116. this.payeeinfo = this.$store.state.vuex_user;
  117. this.roadNo = this.payeeinfo?.roadList?.[0]?.roadNo;
  118. // console.log(' this.payeeinfo1', this.payeeinfo);
  119. this.getPunchInfo(this.roadNo);
  120. },
  121. methods:{
  122. getLocation(){
  123. ALog?.info({msg:'请求定位'});
  124. uni.showLoading({ title: '定位中'});
  125. let that = this;
  126. uni.getLocation({
  127. type:"gcj02",
  128. success : function (res) {
  129. uni.hideLoading();
  130. console.log("定位返回信息:", res)
  131. // alert(res.longitude + "," + res.latitude )
  132. ALog?.info({msg:res})
  133. that.payeeinfo.longitude = res.longitude;
  134. that.payeeinfo.latitude = res.latitude;
  135. var dst = `${that.payeeinfo.longitude},${that.payeeinfo.latitude}`;
  136. var src = res.latitude + ',' + res.longitude;
  137. var locRet = location?.distance?.(src, dst);
  138. that.positionInfo = true;
  139. // console.log('locRet',locRet);
  140. ALog?.info({msg:locRet.distance})
  141. if(locRet<=that.payeeinfo.workDistance){//在打卡范围内
  142. that.outPosition = false;
  143. console.log('that.workType',that.workType);
  144. // debugger;
  145. if(that.workType==1){
  146. let workStartTime = new Date(that.payeeinfo.workStartTime.replace(/-/g,'/'));
  147. if(that.currentTime<=workStartTime.getTime()){
  148. }else{//迟到
  149. that.remarkTip = '您已迟到!';
  150. that.remarkPopupShow = true;
  151. return;
  152. }
  153. console.log('workStartTime',workStartTime.getTime())
  154. }else if(that.workType==2){
  155. if(that.payeeinfo.isPunchOut){
  156. that.$refs.uToast.show({
  157. title: '已经打过下班卡!',
  158. type: 'error',
  159. });
  160. return;
  161. };
  162. let workEndTime = new Date(that.payeeinfo.workEndTime.replace(/-/g,'/'));
  163. if(that.currentTime<=workEndTime.getTime()){//
  164. that.remarkTip = '还未到下班时间,现在打卡将视为早退!';
  165. that.remarkPopupShow = true;
  166. return;
  167. }
  168. console.log('workEndTime',workEndTime.getTime())
  169. }
  170. that.getPunchIn();
  171. }else{//不在打卡范围内
  172. that.outPosition = true;
  173. // that.remarkPopupShow = true;
  174. // console.table({locRet:locRet,workDistance:that.payeeinfo.workDistance,r:locRet<=that.payeeinfo.workDistance});
  175. that.$refs.uToast.show({
  176. title: '超出打卡范围!',
  177. type: 'error',
  178. });
  179. };
  180. },
  181. fail: function(res){
  182. uni.hideLoading();
  183. console.log('getLocation err',res)
  184. ALog?.info({msg:'请求错误',err:res})
  185. }
  186. })
  187. },
  188. handlePunchIn(){
  189. this.getLocation();
  190. },
  191. remarkClose(){
  192. this.remark = '';
  193. },
  194. getPunchIn(){
  195. let that = this;
  196. let param ={
  197. latitude:that.payeeinfo.latitude,
  198. longitude:that.payeeinfo.longitude,
  199. remark:that.remark,
  200. roadNo:that.payeeinfo.roadNo,
  201. workType:that.workType
  202. }
  203. that.$u.api.punchIn(param)
  204. .then(res=>{
  205. this.$refs.uToast.show({
  206. title: res.msg,
  207. type: 'success',
  208. });
  209. this.remarkPopupShow = false;
  210. this.getPunchInfo(this.roadNo);
  211. console.log('this.punchIn',res)
  212. }).catch(err=>{
  213. if(err.errMsg){
  214. this.$refs.uToast.show({
  215. title: '请检查网络',
  216. type: 'error',
  217. });
  218. return false;
  219. };
  220. this.$refs.uToast.show({
  221. title: err.msg,
  222. type: 'error',
  223. });
  224. console.log('punchIn ',err)
  225. });
  226. },
  227. customBack(){
  228. this.$u.route({
  229. // type:'switchTab',
  230. url: 'pages/index/index'
  231. });
  232. },
  233. getPunchInfo(roadNo){
  234. this.$u.api.punchInfo({roadNo:roadNo})
  235. .then(res=>{
  236. // this.$refs.uToast.show({
  237. // title: res.msg,
  238. // type: 'success',
  239. // });
  240. this.payeeinfo ={...this.payeeinfo,...res.data};
  241. // console.log('getPunchInfo res',res);
  242. this.latitude = res.data.latitude;
  243. this.longitude = res.data.longitude;
  244. let mark = {
  245. latitude:res.data.latitude,
  246. longitude:res.data.longitude
  247. };
  248. this.covers.push(mark);
  249. if(!res.data.isPunchIn){//还未打上班卡
  250. this.workType = 1;
  251. }
  252. else{//已打上班卡
  253. this.workType = 2;
  254. }
  255. // console.log('this.payeeinfo',this.payeeinfo)
  256. }).catch(err=>{
  257. if(err.errMsg){
  258. this.$refs.uToast.show({
  259. title: '请检查网络',
  260. type: 'error',
  261. });
  262. return false;
  263. };
  264. this.$refs.uToast.show({
  265. title: err.msg,
  266. type: 'error',
  267. });
  268. console.log('punchInfo ',err)
  269. });
  270. }
  271. },
  272. filters:{
  273. filterWorkType(WorkType){
  274. return (WorkType==1)?'上班':'下班'
  275. }
  276. }
  277. }
  278. </script>
  279. <style lang="scss">
  280. @import './attence.scss'
  281. </style>