attence.vue 8.3 KB

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