|
|
@@ -1,6 +1,7 @@
|
|
|
// pages/clock/clock.js
|
|
|
import {
|
|
|
- getCenterInfo
|
|
|
+ punchClockNeedInfo,
|
|
|
+ savePunchClock
|
|
|
} from '../../services/index.js'
|
|
|
import {
|
|
|
imgServerUrl
|
|
|
@@ -13,8 +14,6 @@ Page({
|
|
|
data: {
|
|
|
approveStatus: false,
|
|
|
imgServerUrl,
|
|
|
- time: '42.0',
|
|
|
- money: '170.94',
|
|
|
navigation: [
|
|
|
{
|
|
|
image: '/images/clock/clock-tongji.png',
|
|
|
@@ -29,108 +28,162 @@ Page({
|
|
|
text: '客服'
|
|
|
},
|
|
|
],
|
|
|
- status: 0,
|
|
|
+ clockType: 3,
|
|
|
statusImage: `${imgServerUrl}/images/clock/clock-beyond.png`,
|
|
|
statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
|
|
|
statusMessage: `请进入企业后再进行打卡`,
|
|
|
+ startPunch: "未完成",
|
|
|
+ endPunch: '未完成',
|
|
|
+ todayMoney: 0,
|
|
|
+ sumDuration: 0,
|
|
|
+ sumMoney: 0,
|
|
|
+ wsPunchClockId: null
|
|
|
},
|
|
|
getLocation() {
|
|
|
- wx.getLocation({
|
|
|
- success: data => {
|
|
|
- console.log(data)
|
|
|
- this.setData({
|
|
|
- statusImage: `${imgServerUrl}/images/clock/clock-in.png`,
|
|
|
- statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
|
|
|
- status: 1
|
|
|
- })
|
|
|
- },
|
|
|
- fail: res => {
|
|
|
- console.log(res)
|
|
|
- }
|
|
|
+ return new Promise(reslove => {
|
|
|
+ wx.getLocation({
|
|
|
+ type: 'gcj02 ',
|
|
|
+ success: data => {
|
|
|
+ reslove(data)
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ console.log(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
location() {
|
|
|
- wx.getSetting({
|
|
|
- success: res => {
|
|
|
- if (res.authSetting['scope.userLocation']) {
|
|
|
- this.getLocation()
|
|
|
- } else {
|
|
|
- wx.authorize({
|
|
|
- scope: 'scope.userLocation',
|
|
|
- success: () => {
|
|
|
- this.getLocation()
|
|
|
- },
|
|
|
- fail: () => {
|
|
|
- wx.showModal({
|
|
|
- content: '无法使用打卡功能',
|
|
|
- confirmText: '去授权',
|
|
|
- title: '位置信息未授权',
|
|
|
- success: (result) => {
|
|
|
- if (result.confirm) {
|
|
|
- wx.openSetting({})
|
|
|
- } else {
|
|
|
- this.setData({
|
|
|
- status: 0
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ return new Promise((reslove, reject) => {
|
|
|
+ wx.getSetting({
|
|
|
+ success: async res => {
|
|
|
+ if (res.authSetting['scope.userLocation']) {
|
|
|
+ reslove(await this.getLocation())
|
|
|
+ } else {
|
|
|
+ wx.authorize({
|
|
|
+ scope: 'scope.userLocation',
|
|
|
+ success: async () => {
|
|
|
+ reslove(await this.getLocation())
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ wx.showModal({
|
|
|
+ content: '无法使用打卡功能',
|
|
|
+ confirmText: '去授权',
|
|
|
+ title: '位置信息未授权',
|
|
|
+ success: (result) => {
|
|
|
+ if (result.confirm) {
|
|
|
+ wx.openSetting({})
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ clockType: 3
|
|
|
+ })
|
|
|
+ reject()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
- click() {
|
|
|
- switch (this.data.status) {
|
|
|
- case 0:
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '超出范围,请刷新页面获取当前位置',
|
|
|
- showCancel: false,
|
|
|
- })
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- this.setData({
|
|
|
- statusImage: `${imgServerUrl}/images/clock/clock-out-disabled.png`,
|
|
|
- statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
|
|
|
- statusMessage: `上班X小时候才能进行下班打卡`,
|
|
|
- status: 2
|
|
|
- })
|
|
|
- setTimeout(() => {
|
|
|
- this.setData({
|
|
|
- statusImage: `${imgServerUrl}/images/clock/clock-out.png`,
|
|
|
- statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
|
|
|
- statusMessage: `已进入考勤打卡范围`,
|
|
|
- status: 3
|
|
|
- })
|
|
|
- }, 2000)
|
|
|
- wx.navigateTo({
|
|
|
- url: './clock-success/clock-success?status=3'
|
|
|
- })
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '未到下班时间,请刷新页面获取最新状态',
|
|
|
- showCancel: false,
|
|
|
- })
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- this.setData({
|
|
|
- statusImage: `${imgServerUrl}/images/clock/clock-done.png`,
|
|
|
- statusMessage: `今日打卡已完成`,
|
|
|
- status: 4
|
|
|
- })
|
|
|
- wx.navigateTo({
|
|
|
- url: './clock-success/clock-success?status=4'
|
|
|
- })
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ async click() {
|
|
|
+ const data = await this.location()
|
|
|
+ if (this.data.clockType === 1 && !this.data.wsPunchClockId) {
|
|
|
+ // this.clock(data.longitude, data.latitude)
|
|
|
+ this.clock(120.353312, 31.535582)
|
|
|
+ }
|
|
|
+ if (this.data.clockType === 1 && this.data.wsPunchClockId) {
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '未到下班时间,请刷新页面获取最新状态',
|
|
|
+ showCancel: false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (this.data.clockType === 2 && this.data.wsPunchClockId) {
|
|
|
+ this.clock(data.longitude, data.latitude)
|
|
|
+ }
|
|
|
+ if (this.data.clockType === 3) {
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '超出范围,请刷新页面获取当前位置',
|
|
|
+ showCancel: false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (this.data.clockType === 4) {
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '今日打卡已完成',
|
|
|
+ showCancel: false,
|
|
|
+ })
|
|
|
}
|
|
|
+ // switch (this.data.status) {
|
|
|
+ // case 0:
|
|
|
+ // wx.showModal({
|
|
|
+ // title: '提示',
|
|
|
+ // content: '超出范围,请刷新页面获取当前位置',
|
|
|
+ // showCancel: false,
|
|
|
+ // })
|
|
|
+ // break;
|
|
|
+ // case 1:
|
|
|
+ // this.setData({
|
|
|
+ // statusImage: `${imgServerUrl}/images/clock/clock-out-disabled.png`,
|
|
|
+ // statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
|
|
|
+ // statusMessage: `上班X小时候才能进行下班打卡`,
|
|
|
+ // status: 2
|
|
|
+ // })
|
|
|
+ // setTimeout(() => {
|
|
|
+ // this.setData({
|
|
|
+ // statusImage: `${imgServerUrl}/images/clock/clock-out.png`,
|
|
|
+ // statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
|
|
|
+ // statusMessage: `已进入考勤打卡范围`,
|
|
|
+ // status: 3
|
|
|
+ // })
|
|
|
+ // }, 2000)
|
|
|
+ // wx.navigateTo({
|
|
|
+ // url: './clock-success/clock-success?status=3'
|
|
|
+ // })
|
|
|
+ // break;
|
|
|
+ // case 2:
|
|
|
+ // wx.showModal({
|
|
|
+ // title: '提示',
|
|
|
+ // content: '未到下班时间,请刷新页面获取最新状态',
|
|
|
+ // showCancel: false,
|
|
|
+ // })
|
|
|
+ // break;
|
|
|
+ // case 3:
|
|
|
+ // this.setData({
|
|
|
+ // statusImage: `${imgServerUrl}/images/clock/clock-done.png`,
|
|
|
+ // statusMessage: `今日打卡已完成`,
|
|
|
+ // status: 4
|
|
|
+ // })
|
|
|
+ // wx.navigateTo({
|
|
|
+ // url: './clock-success/clock-success?status=4'
|
|
|
+ // })
|
|
|
+ // break;
|
|
|
+ // default:
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
|
|
|
},
|
|
|
+ clock(longitude, latitude) {
|
|
|
+ savePunchClock({ longitude, latitude, clockType: this.data.clockType }).then(data => {
|
|
|
+ wx.showToast({
|
|
|
+ title: '打卡成功',
|
|
|
+ success: () => {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: `./clock-success/clock-success?clockType=${this.data.clockType}&&sumMoney=${data.data.sumMoney}&&duration=${data.data.duration}&&todayMoney=${data.data.todayMoney}`
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }).catch(data => {
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: data.errmsg,
|
|
|
+ showCancel: false,
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
navigator(e) {
|
|
|
const { index } = e.currentTarget.dataset
|
|
|
if (index === 0) {
|
|
|
@@ -149,16 +202,67 @@ Page({
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
- load() {
|
|
|
- getCenterInfo().then(data => {
|
|
|
+ async load() {
|
|
|
+ const data = await this.location()
|
|
|
+ console.log(data)
|
|
|
+ // punchClockNeedInfo({ longitude: data.longitude, latitude: data.latitude }).then(data => {
|
|
|
+ punchClockNeedInfo({ longitude: 120.353312, latitude: 31.535582 }).then(data => {
|
|
|
let {
|
|
|
- approveStatus
|
|
|
+ authenticationStatus,
|
|
|
+ startPunch,
|
|
|
+ endPunch,
|
|
|
+ todayMoney,
|
|
|
+ clockType, // 1:上班打卡 2:下班打卡 3:超出范围 4:已完成
|
|
|
+ sumDuration,
|
|
|
+ sumMoney,
|
|
|
+ wsPunchClockId,
|
|
|
+ dailyAvailableMinHour
|
|
|
} = data.data
|
|
|
this.setData({
|
|
|
- approveStatus, // 认证状态(0:未认证 1:等待认证 2:未通过 3:已认证) ,
|
|
|
+ approveStatus: authenticationStatus, // 认证状态(0:未认证 1:等待认证 2:未通过 3:已认证) ,
|
|
|
+ startPunch,
|
|
|
+ endPunch,
|
|
|
+ todayMoney,
|
|
|
+ clockType,
|
|
|
+ sumDuration,
|
|
|
+ sumMoney,
|
|
|
+ wsPunchClockId
|
|
|
})
|
|
|
+ if (clockType === 1 && !wsPunchClockId) {
|
|
|
+ this.setData({
|
|
|
+ statusImage: `${imgServerUrl}/images/clock/clock-in.png`,
|
|
|
+ statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (clockType === 1 && wsPunchClockId) {
|
|
|
+ this.setData({
|
|
|
+ statusImage: `${imgServerUrl}/images/clock/clock-out-disabled.png`,
|
|
|
+ statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
|
|
|
+ statusMessage: `上班${dailyAvailableMinHour}小时候才能进行下班打卡`,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (clockType === 2 && wsPunchClockId) {
|
|
|
+ this.setData({
|
|
|
+ statusImage: `${imgServerUrl}/images/clock/clock-out.png`,
|
|
|
+ statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
|
|
|
+ statusMessage: `已进入考勤打卡范围`,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (clockType === 3) {
|
|
|
+ this.setData({
|
|
|
+ statusImage: `${imgServerUrl}/images/clock/clock-beyond.png`,
|
|
|
+ statusIcon: `${imgServerUrl}/images/clock/clock-waring.png`,
|
|
|
+ statusMessage: `请进入企业后再进行打卡`,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (clockType === 4) {
|
|
|
+ this.setData({
|
|
|
+ statusImage: `${imgServerUrl}/images/clock/clock-done.png`,
|
|
|
+ statusIcon: `${imgServerUrl}/images/clock/clock-can.png`,
|
|
|
+ statusMessage: `今日打卡已完成`,
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
- this.location()
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|