sign.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 class="title-tip"><text>签到赠送1肥料包</text></view>
  17. </view>
  18. <calendar class="sign-date-box" :checks="signList" checksClass="" :checkTextShow="true" checksIcon="/static/img/img07.png"></calendar>
  19. </view>
  20. </template>
  21. <script>
  22. import calendar from '../../components/ss-calendar/ss-calendar.vue';
  23. import { signList, integral,signUser } from '@/api/functionalUnit.js';
  24. export default {
  25. components: {
  26. calendar
  27. },
  28. data() {
  29. return {
  30. money: '', //保存当前月份
  31. year: '', //保存当前年份
  32. day: '', //保存当前日期
  33. signList: [] ,//签到日子列表
  34. actionDay:0,//连续签到天数
  35. allSign:0,//累计签到
  36. sum_integral:0,//累计获得积分
  37. signTrue:false,
  38. };
  39. },
  40. onLoad() {
  41. this.signUser();
  42. this.getData();
  43. this.loadList();
  44. },
  45. methods: {
  46. // 获取当前时间
  47. getData(current) {
  48. const date = current ? new Date(current) : new Date();
  49. this.year = date.getFullYear();//保存当前年份
  50. this.month = date.getMonth() + 1;//保存当前月份
  51. this.day = date.getDate();//保存当前日期
  52. },
  53. //获取签到用户信息
  54. signUser(){
  55. signUser({all:1}).then(({data}) => {
  56. this.actionDay = data.sign_num;//连续签到天数
  57. this.allSign = data.sum_sgin_day;//累计签到天数
  58. this.sum_integral = data.sum_integral;//累计总积分
  59. })
  60. },
  61. // 签到
  62. integral() {
  63. integral({})
  64. .then(e => {
  65. // 改为已签到
  66. this.signTrue = true;
  67. this.actionDay++;
  68. // 保存签到成功
  69. this.signList.push(this.day);
  70. uni.showToast({
  71. title: '签到成功',
  72. duration: 2000,
  73. position: 'top'
  74. });
  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. color: #333333;
  155. background-color: #ffffff;
  156. border-radius: 99rpx;
  157. width: 200rpx;
  158. height: 64rpx;
  159. margin: 0 auto;
  160. line-height: 64rpx;
  161. text-align: center;
  162. font-size: $font-base;
  163. &.signAction{
  164. background-color: $font-color-light;
  165. }
  166. }
  167. }
  168. }
  169. }
  170. .title-tip {
  171. color: #ffffff;
  172. font-size: $font-base - 2rpx;
  173. padding-top: 20rpx;
  174. text-align: center;
  175. margin-top: -40rpx;
  176. }
  177. </style>