clock.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. getLocation() {
  42. return new Promise(reslove => {
  43. wx.getLocation({
  44. type: 'gcj02 ',
  45. success: data => {
  46. reslove(data)
  47. },
  48. fail: res => {
  49. console.log(res)
  50. }
  51. })
  52. })
  53. },
  54. location() {
  55. return new Promise((reslove, reject) => {
  56. wx.getSetting({
  57. success: async res => {
  58. if (res.authSetting['scope.userLocation']) {
  59. reslove(await this.getLocation())
  60. } else {
  61. wx.authorize({
  62. scope: 'scope.userLocation',
  63. success: async () => {
  64. reslove(await this.getLocation())
  65. },
  66. fail: () => {
  67. wx.showModal({
  68. content: '无法使用打卡功能',
  69. confirmText: '去授权',
  70. title: '位置信息未授权',
  71. success: (result) => {
  72. if (result.confirm) {
  73. wx.openSetting({})
  74. } else {
  75. this.setData({
  76. clockType: 3
  77. })
  78. reject()
  79. }
  80. },
  81. })
  82. }
  83. })
  84. }
  85. }
  86. })
  87. })
  88. },
  89. async click() {
  90. const data = await this.location()
  91. if (this.data.clockType === 1 && !this.data.wsPunchClockId) {
  92. // this.clock(data.longitude, data.latitude)
  93. this.clock(120.353312, 31.535582)
  94. }
  95. if (this.data.clockType === 1 && this.data.wsPunchClockId) {
  96. wx.showModal({
  97. title: '提示',
  98. content: '未到下班时间,请刷新页面获取最新状态',
  99. showCancel: false,
  100. })
  101. }
  102. if (this.data.clockType === 2 && this.data.wsPunchClockId) {
  103. this.clock(data.longitude, data.latitude)
  104. }
  105. if (this.data.clockType === 3) {
  106. wx.showModal({
  107. title: '提示',
  108. content: '超出范围,请刷新页面获取当前位置',
  109. showCancel: false,
  110. })
  111. }
  112. if (this.data.clockType === 4) {
  113. wx.showModal({
  114. title: '提示',
  115. content: '今日打卡已完成',
  116. showCancel: false,
  117. })
  118. }
  119. // switch (this.data.status) {
  120. // case 0:
  121. // wx.showModal({
  122. // title: '提示',
  123. // content: '超出范围,请刷新页面获取当前位置',
  124. // showCancel: false,
  125. // })
  126. // break;
  127. // case 1:
  128. // this.setData({
  129. // statusImage: `${imgServerUrl}/images/clock/clock-out-disabled.png`,
  130. // statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
  131. // statusMessage: `上班X小时候才能进行下班打卡`,
  132. // status: 2
  133. // })
  134. // setTimeout(() => {
  135. // this.setData({
  136. // statusImage: `${imgServerUrl}/images/clock/clock-out.png`,
  137. // statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  138. // statusMessage: `已进入考勤打卡范围`,
  139. // status: 3
  140. // })
  141. // }, 2000)
  142. // wx.navigateTo({
  143. // url: './clock-success/clock-success?status=3'
  144. // })
  145. // break;
  146. // case 2:
  147. // wx.showModal({
  148. // title: '提示',
  149. // content: '未到下班时间,请刷新页面获取最新状态',
  150. // showCancel: false,
  151. // })
  152. // break;
  153. // case 3:
  154. // this.setData({
  155. // statusImage: `${imgServerUrl}/images/clock/clock-done.png`,
  156. // statusMessage: `今日打卡已完成`,
  157. // status: 4
  158. // })
  159. // wx.navigateTo({
  160. // url: './clock-success/clock-success?status=4'
  161. // })
  162. // break;
  163. // default:
  164. // break;
  165. // }
  166. },
  167. clock(longitude, latitude) {
  168. savePunchClock({ longitude, latitude, clockType: this.data.clockType }).then(data => {
  169. wx.showToast({
  170. title: '打卡成功',
  171. success: () => {
  172. wx.navigateTo({
  173. url: `./clock-success/clock-success?clockType=${this.data.clockType}&&sumMoney=${data.data.sumMoney}&&duration=${data.data.duration}&&todayMoney=${data.data.todayMoney}`
  174. })
  175. }
  176. })
  177. }).catch(data => {
  178. wx.showModal({
  179. title: '提示',
  180. content: data.errmsg,
  181. showCancel: false,
  182. })
  183. })
  184. },
  185. navigator(e) {
  186. const { index } = e.currentTarget.dataset
  187. if (index === 0) {
  188. wx.navigateTo({
  189. url: './clock-tongji/index',
  190. })
  191. }
  192. if (index === 1) {
  193. wx.navigateTo({
  194. url: './clock-rule/clock-rule',
  195. })
  196. }
  197. if (index === 2) {
  198. wx.makePhoneCall({
  199. phoneNumber: '4006920099',
  200. })
  201. }
  202. },
  203. async load() {
  204. const data = await this.location()
  205. console.log(data)
  206. // punchClockNeedInfo({ longitude: data.longitude, latitude: data.latitude }).then(data => {
  207. punchClockNeedInfo({ longitude: 120.353312, latitude: 31.535582 }).then(data => {
  208. let {
  209. authenticationStatus,
  210. startPunch,
  211. endPunch,
  212. todayMoney,
  213. clockType, // 1:上班打卡 2:下班打卡 3:超出范围 4:已完成
  214. sumDuration,
  215. sumMoney,
  216. wsPunchClockId,
  217. dailyAvailableMinHour
  218. } = data.data
  219. this.setData({
  220. approveStatus: authenticationStatus, // 认证状态(0:未认证 1:等待认证 2:未通过 3:已认证) ,
  221. startPunch,
  222. endPunch,
  223. todayMoney,
  224. clockType,
  225. sumDuration,
  226. sumMoney,
  227. wsPunchClockId
  228. })
  229. if (clockType === 1 && !wsPunchClockId) {
  230. this.setData({
  231. statusImage: `${imgServerUrl}/images/clock/clock-in.png`,
  232. statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  233. })
  234. }
  235. if (clockType === 1 && wsPunchClockId) {
  236. this.setData({
  237. statusImage: `${imgServerUrl}/images/clock/clock-out-disabled.png`,
  238. statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
  239. statusMessage: `上班${dailyAvailableMinHour}小时候才能进行下班打卡`,
  240. })
  241. }
  242. if (clockType === 2 && wsPunchClockId) {
  243. this.setData({
  244. statusImage: `${imgServerUrl}/images/clock/clock-out.png`,
  245. statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  246. statusMessage: `已进入考勤打卡范围`,
  247. })
  248. }
  249. if (clockType === 3) {
  250. this.setData({
  251. statusImage: `${imgServerUrl}/images/clock/clock-beyond.png`,
  252. statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
  253. statusMessage: `请进入企业后再进行打卡`,
  254. })
  255. }
  256. if (clockType === 4) {
  257. this.setData({
  258. statusImage: `${imgServerUrl}/images/clock/clock-done.png`,
  259. statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
  260. statusMessage: `今日打卡已完成`,
  261. })
  262. }
  263. })
  264. },
  265. /**
  266. * 生命周期函数--监听页面加载
  267. */
  268. onLoad: function (options) {
  269. },
  270. /**
  271. * 生命周期函数--监听页面初次渲染完成
  272. */
  273. onReady: function () {
  274. },
  275. /**
  276. * 生命周期函数--监听页面显示
  277. */
  278. onShow: function () {
  279. this.load()
  280. },
  281. /**
  282. * 生命周期函数--监听页面隐藏
  283. */
  284. onHide: function () {
  285. },
  286. /**
  287. * 生命周期函数--监听页面卸载
  288. */
  289. onUnload: function () {
  290. },
  291. /**
  292. * 页面相关事件处理函数--监听用户下拉动作
  293. */
  294. onPullDownRefresh: function () {
  295. this.load()
  296. },
  297. /**
  298. * 页面上拉触底事件的处理函数
  299. */
  300. onReachBottom: function () {
  301. },
  302. /**
  303. * 用户点击右上角分享
  304. */
  305. onShareAppMessage: function () {
  306. }
  307. })