clock.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // pages/clock/clock.js
  2. import {
  3. punchClockNeedInfo,
  4. savePunchClock
  5. } from '../../services/index.js'
  6. import {
  7. imgServerUrl
  8. } from '../../config/config.js'
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. approveStatus: false,
  15. imgServerUrl,
  16. navigation: [
  17. {
  18. image: '/images/clock/clock-tongji.png',
  19. text: '统计'
  20. },
  21. {
  22. image: '/images/clock/clock-rule-icon.png',
  23. text: '规则'
  24. },
  25. {
  26. image: '/images/clock/clock-kefu.png',
  27. text: '客服'
  28. },
  29. ],
  30. clockType: 3,
  31. statusImage: `${imgServerUrl}/images/clock/clock-beyond.png`,
  32. statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
  33. statusMessage: `请进入企业后再进行打卡`,
  34. startPunch: "未完成",
  35. endPunch: '未完成',
  36. todayMoney: 0,
  37. sumDuration: 0,
  38. sumMoney: 0,
  39. wsPunchClockId: null
  40. },
  41. toRule() {
  42. wx.navigateTo({
  43. url: './clock-rule/clock-rule',
  44. })
  45. },
  46. getLocation() {
  47. return new Promise(reslove => {
  48. wx.getLocation({
  49. type: 'gcj02 ',
  50. success: data => {
  51. reslove(data)
  52. },
  53. fail: res => {
  54. console.log(res)
  55. }
  56. })
  57. })
  58. },
  59. location() {
  60. return new Promise((reslove, reject) => {
  61. wx.getSetting({
  62. success: async res => {
  63. if (res.authSetting['scope.userLocation']) {
  64. reslove(await this.getLocation())
  65. } else {
  66. wx.authorize({
  67. scope: 'scope.userLocation',
  68. success: async () => {
  69. reslove(await this.getLocation())
  70. },
  71. fail: () => {
  72. wx.showModal({
  73. content: '无法使用打卡功能',
  74. confirmText: '去授权',
  75. title: '位置信息未授权',
  76. success: (result) => {
  77. if (result.confirm) {
  78. wx.openSetting({})
  79. } else {
  80. this.setData({
  81. clockType: 3
  82. })
  83. reject()
  84. }
  85. },
  86. })
  87. }
  88. })
  89. }
  90. }
  91. })
  92. })
  93. },
  94. async click() {
  95. const data = await this.location()
  96. if (this.data.clockType === 1 && !this.data.wsPunchClockId) {
  97. this.clock(data.longitude, data.latitude)
  98. // this.clock(120.353312, 31.535582)
  99. }
  100. if (this.data.clockType === 1 && this.data.wsPunchClockId) {
  101. wx.showModal({
  102. title: '提示',
  103. content: '未到下班时间,请刷新页面获取最新状态',
  104. showCancel: false,
  105. })
  106. }
  107. if (this.data.clockType === 2 && this.data.wsPunchClockId) {
  108. this.clock(data.longitude, data.latitude)
  109. }
  110. if (this.data.clockType === 3) {
  111. wx.showModal({
  112. title: '提示',
  113. content: '超出范围,请刷新页面获取当前位置',
  114. showCancel: false,
  115. })
  116. }
  117. if (this.data.clockType === 4) {
  118. wx.showModal({
  119. title: '提示',
  120. content: '今日打卡已完成',
  121. showCancel: false,
  122. })
  123. }
  124. },
  125. clock(longitude, latitude) {
  126. savePunchClock({ longitude, latitude, clockType: this.data.clockType }).then(data => {
  127. wx.showToast({
  128. title: '打卡成功',
  129. success: () => {
  130. wx.navigateTo({
  131. url: `./clock-success/clock-success?clockType=${this.data.clockType}&&sumMoney=${data.data.sumMoney}&&duration=${data.data.duration}&&todayMoney=${data.data.todayMoney}`
  132. })
  133. }
  134. })
  135. }).catch(data => {
  136. wx.showModal({
  137. title: '提示',
  138. content: data.errmsg,
  139. showCancel: false,
  140. })
  141. })
  142. },
  143. navigator(e) {
  144. const { index } = e.currentTarget.dataset
  145. if (index === 0) {
  146. wx.navigateTo({
  147. url: './clock-tongji/index',
  148. })
  149. }
  150. if (index === 1) {
  151. wx.navigateTo({
  152. url: './clock-rule/clock-rule',
  153. })
  154. }
  155. if (index === 2) {
  156. wx.makePhoneCall({
  157. phoneNumber: '4006920099',
  158. })
  159. }
  160. },
  161. async load() {
  162. const data = await this.location()
  163. punchClockNeedInfo({ longitude: data.longitude, latitude: data.latitude }).then(data => {
  164. // punchClockNeedInfo({ longitude: 120.353312, latitude: 31.535582 }).then(data => {
  165. let {
  166. authenticationStatus,
  167. startPunch,
  168. endPunch,
  169. todayMoney,
  170. clockType, // 1:上班打卡 2:下班打卡 3:超出范围 4:已完成
  171. sumDuration,
  172. sumMoney,
  173. wsPunchClockId,
  174. dailyAvailableMinHour
  175. } = data.data
  176. this.setData({
  177. approveStatus: authenticationStatus, // 认证状态(0:未认证 1:等待认证 2:未通过 3:已认证) ,
  178. startPunch,
  179. endPunch,
  180. todayMoney,
  181. clockType,
  182. sumDuration,
  183. sumMoney,
  184. wsPunchClockId
  185. })
  186. if (clockType === 1 && !wsPunchClockId) {
  187. this.setData({
  188. statusImage: `${imgServerUrl}/images/clock/clock-in.png`,
  189. statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  190. })
  191. }
  192. if (clockType === 1 && wsPunchClockId) {
  193. this.setData({
  194. statusImage: `${imgServerUrl}/images/clock/clock-out-disabled.png`,
  195. statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
  196. statusMessage: `上班${dailyAvailableMinHour}小时候才能进行下班打卡`,
  197. })
  198. }
  199. if (clockType === 2 && wsPunchClockId) {
  200. this.setData({
  201. statusImage: `${imgServerUrl}/images/clock/clock-out.png`,
  202. statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  203. statusMessage: `已进入考勤打卡范围`,
  204. })
  205. }
  206. if (clockType === 3) {
  207. this.setData({
  208. statusImage: `${imgServerUrl}/images/clock/clock-beyond.png`,
  209. statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
  210. statusMessage: `请进入企业后再进行打卡`,
  211. })
  212. }
  213. if (clockType === 4) {
  214. this.setData({
  215. statusImage: `${imgServerUrl}/images/clock/clock-done.png`,
  216. statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  217. statusMessage: `今日打卡已完成`,
  218. })
  219. }
  220. })
  221. },
  222. /**
  223. * 生命周期函数--监听页面加载
  224. */
  225. onLoad: function (options) {
  226. },
  227. /**
  228. * 生命周期函数--监听页面初次渲染完成
  229. */
  230. onReady: function () {
  231. },
  232. /**
  233. * 生命周期函数--监听页面显示
  234. */
  235. onShow: function () {
  236. this.load()
  237. },
  238. /**
  239. * 生命周期函数--监听页面隐藏
  240. */
  241. onHide: function () {
  242. },
  243. /**
  244. * 生命周期函数--监听页面卸载
  245. */
  246. onUnload: function () {
  247. },
  248. /**
  249. * 页面相关事件处理函数--监听用户下拉动作
  250. */
  251. onPullDownRefresh: function () {
  252. this.load()
  253. },
  254. /**
  255. * 页面上拉触底事件的处理函数
  256. */
  257. onReachBottom: function () {
  258. },
  259. /**
  260. * 用户点击右上角分享
  261. */
  262. onShareAppMessage: function () {
  263. }
  264. })