/**
* 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 (82个子文件)
dfj-20210302-16
sitemap.json 191B
pages
record
record.wxss 4KB
record.wxml 17KB
record.js 8KB
detail
detail.json 2B
detail.js 2KB
detail.wxml 2KB
detail.wxss 2KB
sign
index.wxml 7KB
index.js 10KB
index.json 2B
index.wxss 5KB
task
task.wxml 12KB
task.js 8KB
task.json 2B
task.wxss 4KB
share
share.wxml 783B
share.js 418B
share.json 2B
share.wxss 1KB
add
add.js 2KB
add.json 2B
add.wxss 2KB
add.wxml 3KB
invitation
invitation.json 51B
invitation.js 708B
invitation.wxml 521B
invitation.wxss 441B
new
new.wxss 2KB
new.json 54B
success
success.wxss 1KB
success.json 2B
success.js 419B
success.wxml 857B
new.js 6KB
new.wxml 4KB
app.json 1KB
project.config.json 2KB
app.js 2KB
image
icon_check_unselected.png 1KB
add_unselected.png 1KB
sign_btn_0.png 30KB
s_arr_r.png 2KB
icon_check_selected.png 1KB
dot-line.png 395B
added.png 2KB
icon_task_unselected.png 1KB
icon_location_green@3x.png 2KB
icon_clock_yellow@3x.png 2KB
icon_location_yellow@3x.png 2KB
add_green.png 2KB
sign_btn_unable.png 32KB
task_unselected.png 1KB
refresh.png 2KB
loading.gif 3KB
write.png 462B
icon_share@3x.png 2KB
icon_complete_green@3x.png 2KB
pic.png 33KB
arrow-d-0.png 1KB
arrow-r-0.png 1KB
check_unselected.png 1KB
icon_complete-person@3x.png 2KB
icon_more@3x.png 3KB
check_selected.png 1KB
icon_task_selected.png 1KB
icon_info@3x.png 3KB
icon_clock_red@3x.png 2KB
add_selected.png 1KB
sign_btn_1.png 28KB
icon_top@3x.png 3KB
icon_right_large.png 2KB
icon_add@3x.png 3KB
success-close.png 1KB
icon_location_red@3x.png 2KB
icon_delete@3x.png 2KB
s_arr_l.png 2KB
icon_total-people@3x.png 3KB
task_selected.png 1KB
sign_btn_2.png 26KB
utils
util.js 1001B
app.wxss 377B
共 82 条
- 1
资源评论
小徐博客
- 粉丝: 1973
- 资源: 2718
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功