// packageA//pages/checkin/checkin.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { year: '', month: '', day: '', weekArr: ['日', '一', '二', '三', '四', '五', '六'], dateArr: [], firstDay: '', lastDay: '', param: null, clockNum: 3, res: null, isShowRules: false, isCheckIn: false, checkInDays: 0, //连续签到天数 integral: 0, //积分 checkInNums: 0, //补签次数 isCheckInDay: '', flag: true, }, loadQd(callback) { let self = this; app.request.get('/api/weshop/qdrecord/getUser/'+ app.globalData.setting.stoid + '/' + app.globalData.user_id, { success: function (res) { if(callback) callback(); self.setData({ res: res.data.data }); self.loadCheckedRecord(); }, }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { let self = this; this.getDate(); this.setDate(); var res = wx.getSystemInfoSync(); this.setData({ param: res.windowHeight / 12, }) this.loadQd(); }, // 点击"我的积分"和"去购物"进行跳转 goto(e) { let url = e.target.dataset.url; app.goto(url); }, // 点击显示签到规则 showRules() { if(this.data.isShowRules) { this.setData({ isShowRules: false }); } else { this.setData({ isShowRules: true }); } }, // 加载签到记录 loadCheckedRecord() { let newDateArr = this.data.dateArr; let list; let bqlist; if(this.data.res.qddaylist) { list = this.data.res.qddaylist.split(','); for(let item of list) { newDateArr[item-1].isCheckIn = true; }; } if(this.data.res.curbqdaynum) { bqlist = this.data.res.curbqdaynum.split(','); for(let item of bqlist) { var date = new Date(item); newDateArr[date.getDate()-1].isBq = true; } } this.setData({ dateArr: newDateArr }); }, // 点击签到 checkInToday() { const self = this; // 获取今天的签到状态 let isCheckInToday = this.data.dateArr[this.data.day-1].isCheckIn; // 如果还没签到, 可以点击签到 if(!isCheckInToday) { app.request.promisePost('/api/weshop/qdrecord/saveQd', { data: { store_id: app.globalData.setting.stoid, user_id: app.globalData.user_id, } }).then(res => { // 改变签到状态,由false置为true // let newDateArr = self.data.dateArr; // newDateArr[self.data.day-1].isCheckIn = true; self.loadQd(function() { wx.showToast({ title: self.data.res.qdintro, icon: 'none', duration: 1500, success: function() { } }); }); }) } }, // 补签 reCheckIn() { var self = this; // var i = 0; console.log('补签~'); if(this.data.flag) { this.data.flag = false; app.request.promisePost('/api/weshop/qdrecord/saveBQd', { data: { store_id: app.globalData.setting.stoid, user_id: app.globalData.user_id, daynum: self.data.res.getBQIntegral, bqnum: self.data.res.getbqnum2, bqintegral: self.data.res.getBQIntegral1, } }).then(res => { // 改变签到状态,由false置为true // let newDateArr = self.data.dateArr; // newDateArr[self.data.day-1].isCheckIn = true; var bqlist = self.data.res.curbqdaynum.split(',').sort(); var list = []; for(let item of bqlist) { var date = new Date(item); list.push(date.getDate()); } self.data.dateArr[list[0]-1].isBq = false; self.setData({ dateArr: self.data.dateArr }); self.loadQd(function() { self.data.flag = true; wx.showToast({ title: '补签成功', icon: 'success', duration: 1500, success: function() { } }); }); }) } }, getDate: function() { //获取当月日期 var mydate = new Date(); var year = mydate.getFullYear(); var month = mydate.getMonth(); //0~11: 一月至十二月 var months = month + 1; //1~12:一月至十二月 this.data.year = year; this.data.month = months; this.data.day = mydate.getDate(); //获取当月日期: 1~31 var fist = new Date(year, month, 1); this.data.firstDay = fist.getDay(); //获取当月第一天 var last = new Date(year, months, 0); //0表示当月最后一天 this.data.lastDay = last.getDate(); //获取当月最后一天 this.setData({ year: this.data.year, month: this.data.month, day: this.data.day, firstDay: this.data.firstDay, lastDay: this.data.lastDay }) console.log("今天:" + this.data.day); }, setDate: function() { var day; for (var i = 1; i < this.data.lastDay + 1; i++) { day = { num: i, }; this.data.dateArr.push(day); } this.setData({ dateArr: this.data.dateArr, // firstDay: this.data.firstDay }); }, // prevMonth: function() { //上一月 // var months = ""; // var years = ""; // if (this.data.month == 1) { // years = this.data.year - 1 // this.data.month = 12; // months = this.data.month; // } else { // years = this.data.year; // months = this.data.month - 1; // } // var first = new Date(years, months - 1, 1); // this.data.firstDay = first.getDay(); // var last = new Date(years, months, 0); // this.data.lastDay = last.getDate(); // this.setData({ // month: months, // year: years, // firstDay: this.data.firstDay, // lastDay: this.data.lastDay // }) // this.data.dateArr = []; // for (var i = 1; i < this.data.lastDay + 1; i++) { // this.data.dateArr.push(i); // } // this.setData({ // dateArr: this.data.dateArr // }) // }, // nextMonth: function() { //下一月 // var months = ""; // var years = ""; // if (this.data.month == 12) { // this.data.month = 0; // months = this.data.month; // years = this.data.year + 1; // } else { // months = this.data.month + 1; // years = this.data.year; // } // var months = this.data.month + 1; // var first = new Date(years, months - 1, 1); // this.data.firstDay = first.getDay(); // var last = new Date(years, months, 0); // this.data.lastDay = last.getDate(); // this.setData({ // month: months, // year: years, // firstDay: this.data.firstDay, // lastDay: this.data.lastDay // }) // this.data.dateArr = []; // for (var i = 1; i < this.data.lastDay + 1; i++) { // this.data.dateArr.push(i); // } // this.setData({ // dateArr: this.data.dateArr // }) // }, })