/**
* Page() 快速打卡页
*
* @author marsliang <marsliang@tencent.com>
* @date 2016-11-14 20:07:04
* @update 2016-11-30
*/
var util = require('../../utils/util.js');
var app = getApp();
Page({
data: {
// 是否有签到任务
flag: false,
indicatorDots: true,
autoplay: false,
interval: 5000,
duration: 400,
current: 0,
tasks: [],
quickTasks: [],
userInfo: {},
openId: '',
currentState: 0,
currentTimeFlag: 0,
currentLeaveStart: '',
currentLeaveEnd: '',
curTask: {},
// 倒计时
clock: {
hour: '00',
min: '00'
},
// 打卡按钮状态 0:未按压 1:按压 2:完成
btn: 0,
btnPress: false,
updateAddres: false,
// 提示框默认隐藏
modalHidden: true,
modalText: '',
leaveHidden: true,
// 默认心情为空
humor: '',
humorAble: false,
// 请假事由
reason: ''
},
// 显示请假面板
showLeavePanel: function () {
this.setData({
leaveHidden: false
})
},
// 关闭请假面板
HideLeavePanel: function () {
this.setData({
leaveHidden: true
})
},
// 当前请假任务开始时间
startDateChange: function (e) {
this.setData({
currentLeaveStart: e.detail.value
})
},
// 当前请假任务结束时间
endDateChange: function (e) {
this.setData({
currentLeaveEnd: e.detail.value
})
},
inputReason: function (e) {
this.setData({
reason: e.detail.value
})
},
// 发送请假请求
leaveSubmit: function () {
var openId = wx.getStorageSync('openId');
var d = this.data;
wx.showToast({
title: '请假中',
icon: 'success',
duration: 2000
})
wx.request({
url: 'https://www.cpcsign.com/api/leave',
data: {
taskID: d.curTask._id,
openId: openId,
startDate: d.currentLeaveStart,
endDate: d.currentLeaveEnd,
reason: d.reason
},
method: 'POST',
success: function(res){
// success
that.HideLeavePanel();
},
fail: function() {
// fail
},
complete: function() {
// complete
}
})
},
// 更新距离
updateDistance: function () {
var openId = wx.getStorageSync('openId');
var that = this;
this.setData({
updateAddres: true
});
setTimeout(function () {
that.setData({
updateAddres: false
});
}, 1000);
this.updateTask(openId);
},
// 获取任务
updateTask: function (openId) {
var that = this;
wx.request({
url: 'https://www.cpcsign.com/api/task',
data: {
'openId': openId
},
method: 'GET',
success: function(res){
// success
var tasks = res.data.data.sort(function (a, b) {
return a.state - b.state
});
var tmpTasks = [];
for (var j = 0, len = tasks.length; j < len; ++j) {
if (tasks[j].state == 0 || tasks[j].state == 1 || tasks[j].state == 2 ) {
tmpTasks.push(tasks[j]);
}
}
wx.getLocation({
type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: function(res){
var my = {
latitude: res.latitude,
longitude: res.longitude
}
for (var i = 0, len = tmpTasks.length; i < len; ++i) {
var d = that.getDistance(my.latitude, my.longitude, tmpTasks[i].latitude, tmpTasks[i].longitude);
tmpTasks[i].distance = '距离还有' + d + '公里';
}
that.setData({
flag: true,
tasks: tmpTasks,
currentState: tmpTasks[that.data.current].state,
curTask: tmpTasks[that.data.current],
currentLeaveStart: tmpTasks[that.data.current].startTime,
currentLeaveEnd: tmpTasks[that.data.current].endTime,
humorAble: tmpTasks[that.data.current].state == 0 ? true : false
})
// 时间
var sign;
var now = new Date();
var nowDate = util.getYMD(now);
var time_str = nowDate + ' ' + tmpTasks[that.data.current].signTime + ':00';
sign = new Date(time_str.replace(/-/g, '/'));
if (now.getTime() < sign.getTime()) {
// 倒计时状态
that.setData({
currentTimeFlag: 0
})
} else {
// 已迟到状态
that.setData({
currentTimeFlag: 1
})
}
var disTime = Math.abs(now.getTime() - sign.getTime());
that.setData({
'clock.hour': util.formatNumber(Math.floor(disTime/(3600*1000))),
'clock.min': util.formatNumber(Math.floor(disTime%(3600*1000)/(60*1000)))
})
}
})
}
})
},
// 切换滑块
changeSwiper: function (e) {
var that = this;
var sign;
var now = new Date();
var nowDate = util.getYMD(now);
var time_str = nowDate + ' ' + this.data.tasks[e.detail.current].signTime + ':00';
this.setData({
current: e.detail.current
})
sign = new Date(time_str.replace(/-/g, '/'));
if (now.getTime() < sign.getTime()) {
// 倒计时状态
that.setData({
currentTimeFlag: 0
})
} else {
// 已迟到状态
that.setData({
currentTimeFlag: 1
})
}
var disTime = Math.abs(now.getTime() - sign.getTime());
that.setData({
'clock.hour': util.formatNumber(Math.floor(disTime/(3600*1000))),
'clock.min': util.formatNumber(Math.floor(disTime%(3600*1000)/(60*1000)))
})
this.setData({
currentState: this.data.tasks[e.detail.current].state,
curTask: this.data.tasks[e.detail.current],
currentLeaveStart: this.data.tasks[e.detail.current].startTime,
currentLeaveEnd: this.data.tasks[e.detail.current].endTime
})
},
// 计算距离
getDistance: function (lat1, lng1, lat2, lng2) {
function rad(d) {
return d * Math.PI / 180.0
}
var radLat1 = rad(lat1);
var radLat2 = rad(lat2);
var a = radLat1 - radLat2;
var b = rad(lng1) - rad(lng2);
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
s = s * 6378.137 ;// EARTH_RADIUS;
s = (Math.round(s * 10000) / 10000).toFixed(2);
return s;
},
// 签到打卡
signTask: function () {
var that = this;
var d;
if (!this.data.btnPress) {
wx.showToast({
title: '请求中',
icon: 'loading',
duration: 1000
})
this.setData({
'btn': 1,
'btnPress': true
});
setTimeout(function () {
that.setData({
'btn': 0,
'btnPress': false
});
}, 500);
wx.getLocation({
type: 'wgs84',
success: function(res){
var openId = wx.getStorageSync('openId');
var my = {
latitude: res.latitude,
longitude: res.longitude
};
var curTask = that.data.tasks[that.data.current];
var d = that.getDistance(my.latitude, my.longitude, curTask.latitude, curTask.longitude);
if (d < 2) {
if (that.data.currentTimeFlag == 0 && parseInt(that.data.clock.hour) > 2) {
that.setData({
modalText: '您来的太早了',
modalHidden: false
})
} else {
wx.request({
url: 'https://www.cpcsign.com/api/sign?time='+ (new Date()).getTime(),
data: {
openId: openId,
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
微信小程序开发-易打卡签到案例源码.zip (81个子文件)
易打卡签到
weapp-signin
app
pages
invitation
invitation.js 708B
invitation.wxss 441B
invitation.json 51B
invitation.wxml 521B
new
new.wxml 4KB
success
success.json 2B
success.wxml 857B
success.wxss 1KB
success.js 419B
new.js 6KB
new.json 54B
new.wxss 2KB
detail
detail.wxml 2KB
detail.json 2B
detail.js 2KB
detail.wxss 2KB
add
add.js 2KB
add.json 2B
add.wxml 3KB
add.wxss 2KB
record
record.wxss 4KB
record.wxml 17KB
record.js 8KB
task
task.wxml 12KB
share
share.wxss 1KB
share.js 418B
share.wxml 783B
share.json 2B
task.js 8KB
task.json 2B
task.wxss 4KB
sign
index.wxss 5KB
index.json 2B
index.wxml 7KB
index.js 10KB
utils
util.js 1001B
app.js 2KB
image
icon_delete@3x.png 2KB
task_selected.png 1KB
arrow-r-0.png 1KB
icon_task_selected.png 1KB
icon_right_large.png 2KB
arrow-d-0.png 1KB
icon_clock_yellow@3x.png 2KB
icon_complete_green@3x.png 2KB
icon_share@3x.png 2KB
icon_task_unselected.png 1KB
pic.png 33KB
sign_btn_1.png 28KB
added.png 2KB
icon_info@3x.png 3KB
add_unselected.png 1KB
sign_btn_unable.png 32KB
s_arr_l.png 2KB
dot-line.png 395B
icon_total-people@3x.png 3KB
icon_add@3x.png 3KB
success-close.png 1KB
icon_check_selected.png 1KB
s_arr_r.png 2KB
sign_btn_2.png 26KB
icon_location_yellow@3x.png 2KB
check_selected.png 1KB
loading.gif 3KB
check_unselected.png 1KB
sign_btn_0.png 30KB
icon_location_green@3x.png 2KB
icon_top@3x.png 3KB
refresh.png 2KB
icon_clock_red@3x.png 2KB
icon_location_red@3x.png 2KB
icon_check_unselected.png 1KB
icon_complete-person@3x.png 2KB
write.png 462B
add_selected.png 1KB
add_green.png 2KB
task_unselected.png 1KB
icon_more@3x.png 3KB
app.json 1KB
app.wxss 377B
临时资源.zip 1.27MB
共 81 条
- 1
资源评论
- wpb33235702022-07-24简直是宝藏资源,实用价值很高,支持!
- weixin_412223822022-11-22超赞的资源,感谢资源主分享,大家一起进步!
- 大娄啊i2022-10-21资源使用价值高,内容详实,给了我很多新想法,感谢大佬分享~
- ㅤ1692022-06-06用户下载后在一定时间内未进行评价,系统默认好评。
- m0_670266402022-03-25用户下载后在一定时间内未进行评价,系统默认好评。
芝麻粒儿
- 粉丝: 5w+
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功