dk.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="content">
  3. <view class="dk-title" @click="goDkHis">
  4. 打卡历史
  5. </view>
  6. <map name="" class="map" :latitude="latitude" :longitude="longitude" :markers="markers"></map>
  7. <view class="info">
  8. <text class="info-tit">打卡时段</text> <text class="info-val">{{today}} 00:00-23:59</text>
  9. </view>
  10. <view class="info">
  11. <text class="info-tit">打卡地点</text> <text class="info-val">{{address}}</text>
  12. </view>
  13. <view class="info" v-for="(item, index) in list">
  14. <text class="info-tit">打卡记录({{index + 1}})</text> <text class="info-val">{{item.create_time}}</text>
  15. </view>
  16. <view class="dk flex" @click="dk">
  17. <view class="dk-main flex">
  18. <view class="dk-main-tit">
  19. 立即打卡
  20. </view>
  21. <view class="dk-main-time">
  22. {{time}}
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { goDk, getClockList } from '@/api/signing.js'
  30. const today = new Date();
  31. const year = today.getFullYear();
  32. const month = today.getMonth() + 1; // 月份从0开始,需要加1
  33. const day = today.getDate();
  34. const date = `${year}-${month}-${day}`
  35. export default {
  36. data() {
  37. return {
  38. loading: false,
  39. id: 0,
  40. today: date,
  41. address: '',
  42. timer: null,
  43. time: '',
  44. latitude: '',
  45. longitude: '',
  46. latitudes: '',
  47. longitudes: '',
  48. markers: [],
  49. list: []
  50. }
  51. },
  52. onLoad(opt) {
  53. if (opt.latitude) {
  54. this.id = opt.id
  55. this.latitude = opt.latitude
  56. this.longitude = opt.longitude
  57. this.address = opt.address
  58. this.markers.push({
  59. id: 1,
  60. latitude: this.latitude,
  61. longitude: this.longitude,
  62. title: '打卡点',
  63. iconPath: '/static/icon/shopAddress.png',
  64. width: 20,
  65. height: 20
  66. })
  67. }
  68. this.getLocation()
  69. this.getDkHis()
  70. if (this.timer) {
  71. clearInterval(this.timer);
  72. }
  73. this.updateTime();
  74. // 设置定时器每秒更新时间
  75. this.timer = setInterval(() => {
  76. this.updateTime();
  77. }, 1000);
  78. },
  79. methods: {
  80. goDkHis() {
  81. uni.navigateTo({
  82. url:'/pages/user/signing/dkhis?id=' + this.id
  83. })
  84. },
  85. getLocation() {
  86. let that = this
  87. uni.getLocation({
  88. type: 'gcj02',
  89. success(res) {
  90. that.latitudes = res.latitude
  91. that.longitudes = res.longitude
  92. console.log(that.latitudes,that.longitudes);
  93. },
  94. fail(err) {
  95. console.log(err,'err');
  96. }
  97. })
  98. },
  99. updateTime() {
  100. const now = new Date();
  101. const hours = String(now.getHours()).padStart(2, '0');
  102. const minutes = String(now.getMinutes()).padStart(2, '0');
  103. const seconds = String(now.getSeconds()).padStart(2, '0');
  104. this.time = `${hours}:${minutes}:${seconds}`;
  105. },
  106. dk() {
  107. if(this.loading) return;
  108. this.loading = true
  109. goDk({
  110. contract_id: this.id,
  111. latitude: this.latitudes,
  112. longitude: this.longitudes
  113. }).then(res => {
  114. this.getDkHis()
  115. uni.showToast({
  116. title: '打卡成功',
  117. duration: 2000
  118. });
  119. setTimeout(()=> {
  120. this.loading = false
  121. })
  122. }).catch(err => {
  123. this.loading = false
  124. })
  125. },
  126. getDkHis() {
  127. getClockList({
  128. contract_id: this.id,
  129. page:1,
  130. limit: 10,
  131. time: this.today
  132. }).then(res => {
  133. // console.log(res);
  134. this.list = res.data.list
  135. })
  136. }
  137. },
  138. onHide() {
  139. if (this.timer) {
  140. clearInterval(this.timer);
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .content {
  147. background-color: #fff;
  148. height: 100vh;
  149. }
  150. .dk-title {
  151. padding: 20rpx;
  152. text-align: right;
  153. font-weight: bold;
  154. font-size: 28rpx;
  155. color: #0066FF;
  156. }
  157. .map {
  158. width: 710rpx;
  159. height: 500rpx;
  160. margin:0 auto 40rpx;
  161. }
  162. .info {
  163. font-size: 26rpx;
  164. padding-left: 28rpx;
  165. margin: 20rpx 0;
  166. &-tit {
  167. display: inline-block;
  168. width: 160rpx;
  169. color: #6E6E6E;
  170. }
  171. &-val {
  172. color: #1B1B1B;
  173. }
  174. }
  175. .dk {
  176. width: 290rpx;
  177. height: 290rpx;
  178. margin: 50rpx auto;
  179. border-radius: 50%;
  180. border: 3rpx solid #0066FF;
  181. justify-content: center;
  182. align-items: center;
  183. &-main {
  184. flex-direction: column;
  185. justify-content: center;
  186. align-items: center;
  187. width: 268rpx;
  188. height: 268rpx;
  189. background: #0066FF;
  190. border-radius: 50%;
  191. color: #FFFFFF;
  192. font-size: 38rpx;
  193. }
  194. }
  195. </style>