sign.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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/functionalUnit.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. //获取签到用户信息
  53. signUser(){
  54. signUser({all:1}).then(({data}) => {
  55. this.actionDay = data.sign_num;//连续签到天数
  56. this.allSign = data.sum_sgin_day;//累计签到天数
  57. this.sum_integral = data.sum_integral;//累计总积分
  58. })
  59. },
  60. // 签到
  61. integral() {
  62. integral({})
  63. .then(e => {
  64. // 改为已签到
  65. this.signTrue = true;
  66. this.actionDay++;
  67. // 保存签到成功
  68. this.signList.push(this.day);
  69. uni.showToast({
  70. title: '签到成功',
  71. duration: 2000,
  72. position: 'top'
  73. });
  74. })
  75. .catch(e => {
  76. console.log(e);
  77. });
  78. },
  79. // 获取签到列表
  80. loadList() {
  81. let obj = this;
  82. let present = this.day; //保存当前天数用于后续计算
  83. let actionDay = 0; //用于计算活跃天数
  84. let arr = []; //保存返回数组;
  85. signList({
  86. page: 1,
  87. limit: 31
  88. }).then(e => {
  89. arr = e.data.map((e, ind) => {
  90. let time = e.add_time.split('-');
  91. let day = parseInt(time[2].replace(/^0/i, ''));
  92. let year = time[0];
  93. let month = +time[1];
  94. if (obj.year == year && obj.month == month) {
  95. return day;
  96. }
  97. });
  98. this.signList = arr;
  99. // 判断今天是否已经签到
  100. if(arr[0]==this.day){
  101. this.signTrue = true;
  102. }
  103. });
  104. }
  105. }
  106. };
  107. </script>
  108. <style lang="scss">
  109. page {
  110. background: $page-color-base;
  111. }
  112. .sign-date-box {
  113. margin: 25rpx;
  114. border-radius: 15rpx;
  115. margin-top: -70rpx;
  116. }
  117. .title-box {
  118. background-color: $base-color;
  119. padding-top: 120rpx;
  120. color: #ffffff;
  121. height: 590rpx;
  122. .title-conetnt {
  123. height: 350rpx;
  124. width: 350rpx;
  125. margin: 0 auto;
  126. text-align: center;
  127. .title-img {
  128. position: absolute;
  129. top: 0;
  130. left: 0;
  131. height: 100%;
  132. width: 100%;
  133. image {
  134. height: 100%;
  135. width: 100%;
  136. }
  137. }
  138. .title-content-box {
  139. position: absolute;
  140. width: 100%;
  141. .title-day-text {
  142. padding: 20rpx;
  143. font-size: $font-base - 2rpx;
  144. .title-day {
  145. font-size: 60rpx;
  146. }
  147. }
  148. .title-text {
  149. font-size: 26rpx;
  150. padding-top: 100rpx;
  151. }
  152. .title-button {
  153. background-color: #fe7e51;
  154. border-radius: 99rpx;
  155. width: 200rpx;
  156. height: 64rpx;
  157. margin: 0 auto;
  158. line-height: 64rpx;
  159. text-align: center;
  160. font-size: $font-base;
  161. &.signAction{
  162. background-color: $font-color-light;
  163. }
  164. }
  165. }
  166. }
  167. }
  168. .title-tip {
  169. color: #ffffff;
  170. font-size: $font-base - 2rpx;
  171. padding-top: 20rpx;
  172. text-align: center;
  173. margin-top: -40rpx;
  174. }
  175. </style>