index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view>
  3. <view class="title-box">
  4. <view class=" title-conetnt position-relative">
  5. <view class="title-img"><image src="/static/img/img08.png" mode="aspectFit"></image></view>
  6. <view class="title-content-box">
  7. <view class="title-text">已连续签到</view>
  8. <view class="title-day-text">
  9. <text class="title-day">{{actionDay}}</text>
  10. <text>天</text>
  11. </view>
  12. <view class="title-button" :class="{'signAction':signTrue}" @click="signTrue?'':integral()">{{signTrue?'已签到':'立即签到'}}</view>
  13. </view>
  14. </view>
  15. <view class="title-tip"><text>共获得{{sum_integral}}积分,总签到{{allSign}}天</text></view>
  16. </view>
  17. <calendar class="sign-date-box" :checks="signList" checksClass="" :checkTextShow="true" checksIcon="/static/img/img07.png"></calendar>
  18. </view>
  19. </template>
  20. <script>
  21. import calendar from '../../components/ss-calendar/ss-calendar.vue';
  22. import { signList, integral,signUser } from '@/api/sign.js';
  23. export default {
  24. components: {
  25. calendar
  26. },
  27. data() {
  28. return {
  29. money: '', //保存当前月份
  30. year: '', //保存当前年份
  31. day: '', //保存当前日期
  32. signList: [] ,//签到日子列表
  33. actionDay:0,//连续签到天数
  34. allSign:0,//累计签到
  35. sum_integral:0,//累计获得积分
  36. signTrue:false,
  37. };
  38. },
  39. onLoad() {
  40. this.signUser();
  41. this.getData();
  42. this.loadList();
  43. },
  44. methods: {
  45. // 获取当前时间
  46. getData(current) {
  47. const date = current ? new Date(current) : new Date();
  48. this.year = date.getFullYear();//保存当前年份
  49. this.month = date.getMonth() + 1;//保存当前月份
  50. this.day = date.getDate();//保存当前日期
  51. },
  52. signUser(){
  53. signUser({all:1}).then(({data}) => {
  54. this.actionDay = data.sign_num;//连续签到天数
  55. this.allSign = data.sum_sgin_day;//累计签到天数
  56. this.sum_integral = data.sum_integral;//累计总积分
  57. })
  58. },
  59. // 签到
  60. integral() {
  61. integral({})
  62. .then(e => {
  63. // 改为已签到
  64. this.signTrue = true;
  65. this.actionDay++;
  66. // 保存签到成功
  67. this.signList.push(this.day);
  68. uni.showToast({
  69. title: '签到成功',
  70. duration: 2000,
  71. position: 'top'
  72. });
  73. })
  74. .catch(e => {
  75. console.log(e);
  76. });
  77. },
  78. // 获取签到列表
  79. loadList() {
  80. let obj = this;
  81. let present = this.day; //保存当前天数用于后续计算
  82. let actionDay = 0; //用于计算活跃天数
  83. let arr = []; //保存返回数组;
  84. signList({
  85. page: 1,
  86. limit: 31
  87. }).then(e => {
  88. arr = e.data.map((e, ind) => {
  89. let time = e.add_time.split('-');
  90. let day = parseInt(time[2].replace(/^0/i, ''));
  91. let year = time[0];
  92. let month = +time[1];
  93. if (obj.year == year && obj.month == month) {
  94. return day;
  95. }
  96. });
  97. this.signList = arr;
  98. // 判断今天是否已经签到
  99. if(arr[0]==this.day){
  100. this.signTrue = true;
  101. }
  102. });
  103. }
  104. }
  105. };
  106. </script>
  107. <style lang="scss">
  108. page {
  109. background: $page-color-base;
  110. }
  111. .sign-date-box {
  112. margin: 25rpx;
  113. border-radius: 15rpx;
  114. margin-top: -70rpx;
  115. }
  116. .title-box {
  117. background-color: $base-color;
  118. padding-top: 120rpx;
  119. color: #ffffff;
  120. height: 590rpx;
  121. .title-conetnt {
  122. height: 350rpx;
  123. width: 350rpx;
  124. margin: 0 auto;
  125. text-align: center;
  126. .title-img {
  127. position: absolute;
  128. top: 0;
  129. left: 0;
  130. height: 100%;
  131. width: 100%;
  132. image {
  133. height: 100%;
  134. width: 100%;
  135. }
  136. }
  137. .title-content-box {
  138. position: absolute;
  139. width: 100%;
  140. .title-day-text {
  141. padding: 20rpx;
  142. font-size: $font-base - 2rpx;
  143. .title-day {
  144. font-size: 60rpx;
  145. }
  146. }
  147. .title-text {
  148. font-size: 26rpx;
  149. padding-top: 100rpx;
  150. }
  151. .title-button {
  152. background-color: #fe7e51;
  153. border-radius: 99rpx;
  154. width: 200rpx;
  155. height: 64rpx;
  156. margin: 0 auto;
  157. line-height: 64rpx;
  158. text-align: center;
  159. font-size: $font-base;
  160. &.signAction{
  161. background-color: $font-color-light;
  162. }
  163. }
  164. }
  165. }
  166. }
  167. .title-tip {
  168. color: #ffffff;
  169. font-size: $font-base - 2rpx;
  170. padding-top: 20rpx;
  171. text-align: center;
  172. margin-top: -40rpx;
  173. }
  174. </style>