clock.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // pages/clock/clock.js
  2. import {
  3. getCenterInfo
  4. } from '../../services/index.js'
  5. import {
  6. imgServerUrl
  7. } from '../../config/config.js'
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. approveStatus: false,
  14. imgServerUrl,
  15. time: '42.0',
  16. money: '170.94',
  17. navigation: [
  18. {
  19. image: '/images/clock/clock-tongji.png',
  20. text: '统计'
  21. },
  22. {
  23. image: '/images/clock/clock-rule-icon.png',
  24. text: '规则'
  25. },
  26. {
  27. image: '/images/clock/clock-kefu.png',
  28. text: '客服'
  29. },
  30. ],
  31. status: 0,
  32. statusImage: `${imgServerUrl}/images/clock/clock-beyond.png`,
  33. statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
  34. statusMessage: `请进入企业后再进行打卡`,
  35. },
  36. getLocation() {
  37. wx.getLocation({
  38. success: data => {
  39. console.log(data)
  40. this.setData({
  41. statusImage: `${imgServerUrl}/images/clock/clock-in.png`,
  42. statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  43. status: 1
  44. })
  45. },
  46. fail: res => {
  47. console.log(res)
  48. }
  49. })
  50. },
  51. location() {
  52. wx.getSetting({
  53. success: res => {
  54. if (res.authSetting['scope.userLocation']) {
  55. this.getLocation()
  56. } else {
  57. wx.authorize({
  58. scope: 'scope.userLocation',
  59. success: () => {
  60. this.getLocation()
  61. },
  62. fail: () => {
  63. wx.showModal({
  64. content: '无法使用打卡功能',
  65. confirmText: '去授权',
  66. title: '位置信息未授权',
  67. success: (result) => {
  68. if (result.confirm) {
  69. wx.openSetting({})
  70. } else {
  71. this.setData({
  72. status: 0
  73. })
  74. }
  75. },
  76. })
  77. }
  78. })
  79. }
  80. }
  81. })
  82. },
  83. click() {
  84. switch (this.data.status) {
  85. case 0:
  86. wx.showModal({
  87. title: '提示',
  88. content: '超出范围,请刷新页面获取当前位置',
  89. showCancel: false,
  90. })
  91. break;
  92. case 1:
  93. this.setData({
  94. statusImage: `${imgServerUrl}/images/clock/clock-out-disabled.png`,
  95. statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
  96. statusMessage: `上班X小时候才能进行下班打卡`,
  97. status: 2
  98. })
  99. setTimeout(() => {
  100. this.setData({
  101. statusImage: `${imgServerUrl}/images/clock/clock-out.png`,
  102. statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  103. statusMessage: `已进入考勤打卡范围`,
  104. status: 3
  105. })
  106. }, 2000)
  107. wx.navigateTo({
  108. url: './clock-success/clock-success?status=3'
  109. })
  110. break;
  111. case 2:
  112. wx.showModal({
  113. title: '提示',
  114. content: '未到下班时间,请刷新页面获取最新状态',
  115. showCancel: false,
  116. })
  117. break;
  118. case 3:
  119. this.setData({
  120. statusImage: `${imgServerUrl}/images/clock/clock-done.png`,
  121. statusMessage: `今日打卡已完成`,
  122. status: 4
  123. })
  124. wx.navigateTo({
  125. url: './clock-success/clock-success?status=4'
  126. })
  127. break;
  128. default:
  129. break;
  130. }
  131. },
  132. navigator(e) {
  133. const { index } = e.currentTarget.dataset
  134. if (index === 0) {
  135. wx.navigateTo({
  136. url: './clock-tongji/index',
  137. })
  138. }
  139. if (index === 1) {
  140. wx.navigateTo({
  141. url: './clock-rule/clock-rule',
  142. })
  143. }
  144. if (index === 2) {
  145. wx.makePhoneCall({
  146. phoneNumber: '4006920099',
  147. })
  148. }
  149. },
  150. load() {
  151. getCenterInfo().then(data => {
  152. let {
  153. approveStatus
  154. } = data.data
  155. this.setData({
  156. approveStatus, // 认证状态(0:未认证 1:等待认证 2:未通过 3:已认证) ,
  157. })
  158. })
  159. this.location()
  160. },
  161. /**
  162. * 生命周期函数--监听页面加载
  163. */
  164. onLoad: function (options) {
  165. },
  166. /**
  167. * 生命周期函数--监听页面初次渲染完成
  168. */
  169. onReady: function () {
  170. },
  171. /**
  172. * 生命周期函数--监听页面显示
  173. */
  174. onShow: function () {
  175. this.load()
  176. },
  177. /**
  178. * 生命周期函数--监听页面隐藏
  179. */
  180. onHide: function () {
  181. },
  182. /**
  183. * 生命周期函数--监听页面卸载
  184. */
  185. onUnload: function () {
  186. },
  187. /**
  188. * 页面相关事件处理函数--监听用户下拉动作
  189. */
  190. onPullDownRefresh: function () {
  191. this.load()
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. onReachBottom: function () {
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage: function () {
  202. }
  203. })