sign.vue 4.1 KB

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