|
@@ -1,14 +1,16 @@
|
|
|
// pages/signIn/index.js
|
|
|
import SignIn from '../../../api/signIn'
|
|
|
import { isEmpty } from '../../../utils/util'
|
|
|
+import { getMobileCache, getPhoneNumber as getPhoneNumberSync } from '../../../utils/user'
|
|
|
+const app = getApp();
|
|
|
|
|
|
Page({
|
|
|
-
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
showPage: false,
|
|
|
+ showSignInSuccessDlg: false,
|
|
|
activity: {},
|
|
|
signInNodes: [{ pos: 1, text: '星期一' },
|
|
|
{ pos: 2, text: '星期二' },
|
|
@@ -16,14 +18,23 @@ Page({
|
|
|
{ pos: 4, text: '星期四' },
|
|
|
{ pos: 5, text: '星期五' },
|
|
|
{ pos: 6, text: '星期六' }],
|
|
|
- lastSignInNode: { pos: 7, text: '星期天' }
|
|
|
+ lastSignInNode: { pos: 7, text: '星期天' },
|
|
|
+ todayIsSigned: false,
|
|
|
+ isLogin: getMobileCache() != "",
|
|
|
+ notUseNum: 0
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
- SignIn.getActivityData("").then(res => {
|
|
|
+ this.data.dayOfWeek = this.getDayOfWeek()
|
|
|
+ this.startLoadActivityData()
|
|
|
+ this.setPageStyle()
|
|
|
+ },
|
|
|
+
|
|
|
+ startLoadActivityData() {
|
|
|
+ SignIn.getActivityData(getMobileCache()).then(res => {
|
|
|
console.log(res)
|
|
|
if (res.code == 200) {
|
|
|
this.setData({
|
|
@@ -38,7 +49,19 @@ Page({
|
|
|
showPage: true
|
|
|
})
|
|
|
})
|
|
|
- this.setPageStyle();
|
|
|
+ if (this.data.isLogin) {
|
|
|
+ SignIn.getUserAwardCouponNum({
|
|
|
+ mobile: getMobileCache()
|
|
|
+ }).then( res => {
|
|
|
+ if (res.code == 200) {
|
|
|
+ this.setData({
|
|
|
+ notUseNum: res.data.notUseNum || 0
|
|
|
+ })
|
|
|
+ }
|
|
|
+ console.log(res)
|
|
|
+ }).catch(_ => {})
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
|
|
|
setPageStyle() {
|
|
@@ -56,13 +79,14 @@ Page({
|
|
|
},
|
|
|
|
|
|
mapToView(data) {
|
|
|
+ this.setColors(data.color)
|
|
|
if (data.dayAwardList && data.dayAwardList.length > 0) {
|
|
|
data.dayAwardList.forEach(item => {
|
|
|
if (item.dayNo == 7) {
|
|
|
- Object.assign(this.data.lastSignInNode, item);
|
|
|
+ this.preDealItemData(this.data.lastSignInNode, item);
|
|
|
} else {
|
|
|
if (this.data.signInNodes[item.dayNo - 1]) {
|
|
|
- Object.assign(this.data.signInNodes[item.dayNo - 1], item)
|
|
|
+ this.preDealItemData(this.data.signInNodes[item.dayNo - 1], item)
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -72,7 +96,31 @@ Page({
|
|
|
lastSignInNode: this.data.lastSignInNode
|
|
|
})
|
|
|
}
|
|
|
- this.setColors(data.color)
|
|
|
+ },
|
|
|
+
|
|
|
+ preDealItemData(target, item) {
|
|
|
+ // 未签到的情况下,计算是否属于过签
|
|
|
+ Object.assign(target, item);
|
|
|
+ if (target.isSignIn == 0 && target.pos < this.data.dayOfWeek) {
|
|
|
+ target.isSignIn = -1;
|
|
|
+ target.textBgGround = this.data.grayBackGroudStyle
|
|
|
+ } else {
|
|
|
+ target.textBgGround = this.data.backGroundStyle
|
|
|
+ }
|
|
|
+ if (target.pos == this.data.dayOfWeek) {
|
|
|
+ this.setData({
|
|
|
+ todayIsSigned: target.isSignIn == 1
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getDayOfWeek(date) {
|
|
|
+ var now = date || new Date();
|
|
|
+ var day = now.getDay();
|
|
|
+ if (day == 0) {
|
|
|
+ return 7
|
|
|
+ }
|
|
|
+ return day;
|
|
|
},
|
|
|
|
|
|
setColors(color) {
|
|
@@ -82,15 +130,102 @@ Page({
|
|
|
if (color.length == 4) {
|
|
|
color = color.replace(/#(.)(.)(.)$/, "#$1$1$2$2$3$3")
|
|
|
}
|
|
|
+ let newColor = "#";
|
|
|
for (let i = 1; i <= 6; i++) {
|
|
|
- console.log(color.charAt(i))
|
|
|
+ if (color.charAt(i) == 'a' || color.charAt(i) == 'A') {
|
|
|
+ newColor += "9"
|
|
|
+ } else if (color.charAt(i) == '0') {
|
|
|
+ newColor += "0"
|
|
|
+ } else {
|
|
|
+ newColor += String.fromCharCode(color.charCodeAt(i) - 1)
|
|
|
+ }
|
|
|
}
|
|
|
+ this.setData({
|
|
|
+ mainColor: color,
|
|
|
+ secColor: newColor,
|
|
|
+ backGroundStyle: "background: linear-gradient(" +color+", "+ newColor+ ", "+color+");",
|
|
|
+ grayBackGroudStyle: "background: #c6c6c6"
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ popMessage(message) {
|
|
|
+ app.showToast(message, "none")
|
|
|
},
|
|
|
|
|
|
tapSignIn: function() {
|
|
|
- SignIn.triggerSignIn(5, "16602120168").then(res => {
|
|
|
+ if (!this.data.isLogin) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.data.activity.id) {
|
|
|
+ app.popMessage("未找到签到活动")
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.isLocked) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.isLocked = true
|
|
|
+
|
|
|
+ SignIn.triggerSignIn(this.data.activity.id, getMobileCache()).then(res => {
|
|
|
console.log(res)
|
|
|
- }).catch(_ => {})
|
|
|
+ if (res.code == 200) {
|
|
|
+ this.dealSignResult(res.data)
|
|
|
+ this.startLoadActivityData()
|
|
|
+ }
|
|
|
+ }).catch(_ => {
|
|
|
+ }).finally(_ => {
|
|
|
+ this.isLocked = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理签到结果
|
|
|
+ */
|
|
|
+ dealSignResult(data) {
|
|
|
+ if (data.isHit == 0 || data.coupon == null) {
|
|
|
+ // 没有配置奖品的情况下
|
|
|
+ postMessage("签到成功!")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const hitResult = data.coupon;
|
|
|
+
|
|
|
+ if (hitResult.couponType == "C") {
|
|
|
+ // 现金券
|
|
|
+ if (hitResult.formatReduceCost.length >= 3) {
|
|
|
+ hitResult._classSmallStyle = "_small"
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (hitResult.couponType == "D") {
|
|
|
+ // 折扣券
|
|
|
+ if (hitResult.formatReduceCost.length >= 3) {
|
|
|
+ hitResult._classSmallStyle = "_small"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hitResult.formatLeastCost == "0") {
|
|
|
+ hitResult.formatLeastCostStr = "无门槛使用"
|
|
|
+ } else {
|
|
|
+ hitResult.formatLeastCostStr = "满" + formatLeastCost + "元使用"
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ hitResult: hitResult,
|
|
|
+ showSignInSuccessDlg: true
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 授权手机号
|
|
|
+ getPhoneNumber(e) {
|
|
|
+ getPhoneNumberSync(e, _ => {
|
|
|
+ this.setData({ isLogin: true })
|
|
|
+ this.startLoadActivityData()
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ closeDlg() {
|
|
|
+ this.setData({
|
|
|
+ showSignInSuccessDlg: false
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
/**
|