activity.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/signIn/index.js
  2. import SignIn from '../../../api/signIn'
  3. import { isEmpty } from '../../../utils/util'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showPage: false,
  10. activity: {},
  11. signInNodes: [{ pos: 1, text: '星期一' },
  12. { pos: 2, text: '星期二' },
  13. { pos: 3, text: '星期三' },
  14. { pos: 4, text: '星期四' },
  15. { pos: 5, text: '星期五' },
  16. { pos: 6, text: '星期六' }],
  17. lastSignInNode: { pos: 7, text: '星期天' }
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. SignIn.getActivityData("").then(res => {
  24. console.log(res)
  25. if (res.code == 200) {
  26. this.setData({
  27. activity: res.data
  28. })
  29. this.mapToView(res.data)
  30. }
  31. }).catch(_ => {
  32. }).finally(_ => {
  33. this.setData({
  34. showPage: true
  35. })
  36. })
  37. this.setPageStyle();
  38. },
  39. setPageStyle() {
  40. let dwObj = wx.getMenuButtonBoundingClientRect()
  41. let navHeight_ = (dwObj.top + dwObj.height)
  42. let capsuleTop_ = dwObj.top
  43. let windowHeight = wx.getSystemInfoSync().windowHeight
  44. this.setData({
  45. navHeight: navHeight_,
  46. capsuleTop:capsuleTop_,
  47. capHeight: dwObj.height,
  48. bodyHeight: windowHeight - navHeight_,
  49. });
  50. },
  51. mapToView(data) {
  52. if (data.dayAwardList && data.dayAwardList.length > 0) {
  53. data.dayAwardList.forEach(item => {
  54. if (item.dayNo == 7) {
  55. Object.assign(this.data.lastSignInNode, item);
  56. } else {
  57. if (this.data.signInNodes[item.dayNo - 1]) {
  58. Object.assign(this.data.signInNodes[item.dayNo - 1], item)
  59. }
  60. }
  61. });
  62. this.setData({
  63. signInNodes: this.data.signInNodes,
  64. lastSignInNode: this.data.lastSignInNode
  65. })
  66. }
  67. this.setColors(data.color)
  68. },
  69. setColors(color) {
  70. if (isEmpty(color)) {
  71. color = "#EE5A5A"
  72. }
  73. if (color.length == 4) {
  74. color = color.replace(/#(.)(.)(.)$/, "#$1$1$2$2$3$3")
  75. }
  76. for (let i = 1; i <= 6; i++) {
  77. console.log(color.charAt(i))
  78. }
  79. },
  80. tapSignIn: function() {
  81. SignIn.triggerSignIn(5, "16602120168").then(res => {
  82. console.log(res)
  83. }).catch(_ => {})
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面隐藏
  97. */
  98. onHide: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面卸载
  102. */
  103. onUnload: function () {
  104. },
  105. /**
  106. * 页面相关事件处理函数--监听用户下拉动作
  107. */
  108. onPullDownRefresh: function () {
  109. },
  110. /**
  111. * 页面上拉触底事件的处理函数
  112. */
  113. onReachBottom: function () {
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage: function () {
  119. }
  120. })