sign.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view>
  3. <view class="title-box">
  4. <view class="bg">
  5. <image src="/static/img/sign-bg.png">
  6. </view>
  7. <view class=" title-conetnt position-relative" @click="signTrue?'':integral()">
  8. <view class="title-img"><image src="/static/img/sign-btn.png" mode="aspectFit"></image></view>
  9. <view class="title-content-box">
  10. <view class="title-text">签到</view>
  11. <view class="title-day-text">
  12. 今日签到可得10购物积分
  13. <!-- <text class="title-day">签到</text> -->
  14. <!-- <text>天</text> -->
  15. </view>
  16. <!-- <view class="title-button" :class="{'signAction':signTrue}" @click="signTrue?'':integral()">{{signTrue?'已签到':'立即签到'}}</view> -->
  17. </view>
  18. </view>
  19. <!-- <view class="title-tip"><text>共获得{{sum_integral}}积分,总签到{{allSign}}天</text></view> -->
  20. </view>
  21. <view class="conenter">
  22. <view class="money"><text>{{sum_integral}}</text><br>获得金额
  23. </view>
  24. <view class="l"></view>
  25. <view class="day"><text>{{allSign}}</text><br>签到天数</view>
  26. </view>
  27. <view class="explain">
  28. 签到说明
  29. <image src="../../static/img/img74.png"></image>
  30. </view>
  31. <!-- <calendar class="sign-date-box" :checks="signList" checksClass="" :checkTextShow="true" checksIcon="/static/img/img07.png"></calendar> -->
  32. </view>
  33. </template>
  34. <script>
  35. import calendar from '../../components/ss-calendar/ss-calendar.vue';
  36. import { signList, integral,signUser } from '@/api/functionalUnit.js';
  37. export default {
  38. components: {
  39. calendar
  40. },
  41. data() {
  42. return {
  43. money: '', //保存当前月份
  44. year: '', //保存当前年份
  45. day: '', //保存当前日期
  46. signList: [] ,//签到日子列表
  47. actionDay:0,//连续签到天数
  48. allSign:0,//累计签到
  49. sum_integral:0,//累计获得积分
  50. signTrue:false,
  51. };
  52. },
  53. onLoad() {
  54. this.signUser();
  55. this.getData();
  56. this.loadList();
  57. },
  58. methods: {
  59. // 获取当前时间
  60. getData(current) {
  61. const date = current ? new Date(current) : new Date();
  62. this.year = date.getFullYear();//保存当前年份
  63. this.month = date.getMonth() + 1;//保存当前月份
  64. this.day = date.getDate();//保存当前日期
  65. },
  66. //获取签到用户信息
  67. signUser(){
  68. signUser({all:1}).then(({data}) => {
  69. this.actionDay = data.sign_num;//连续签到天数
  70. this.allSign = data.sum_sgin_day;//累计签到天数
  71. this.sum_integral = data.sum_integral;//累计总积分
  72. })
  73. },
  74. // 签到
  75. integral() {
  76. integral({})
  77. .then(e => {
  78. // 改为已签到
  79. this.signTrue = true;
  80. this.actionDay++;
  81. // 保存签到成功
  82. this.signList.push(this.day);
  83. uni.showToast({
  84. title: '签到成功',
  85. duration: 2000,
  86. position: 'top'
  87. });
  88. })
  89. .catch(e => {
  90. console.log(e);
  91. });
  92. },
  93. // 获取签到列表
  94. loadList() {
  95. let obj = this;
  96. let present = this.day; //保存当前天数用于后续计算
  97. let actionDay = 0; //用于计算活跃天数
  98. let arr = []; //保存返回数组;
  99. signList({
  100. page: 1,
  101. limit: 31
  102. }).then(e => {
  103. arr = e.data.map((e, ind) => {
  104. let time = e.add_time.split('-');
  105. let day = parseInt(time[2].replace(/^0/i, ''));
  106. let year = time[0];
  107. let month = +time[1];
  108. if (obj.year == year && obj.month == month) {
  109. return day;
  110. }
  111. });
  112. this.signList = arr;
  113. // 判断今天是否已经签到
  114. if(arr[0]==this.day){
  115. this.signTrue = true;
  116. }
  117. });
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. page {
  124. background: $page-color-base;
  125. }
  126. .sign-date-box {
  127. margin: 25rpx;
  128. border-radius: 15rpx;
  129. margin-top: -70rpx;
  130. }
  131. .title-box {
  132. background-color: $base-color;
  133. padding-top: 120rpx;
  134. color: #ffffff;
  135. height: 590rpx;
  136. .bg {
  137. position: absolute;
  138. width: 100%;
  139. top: 0;
  140. image {
  141. width: 100%;
  142. height: 590rpx;
  143. }
  144. }
  145. .title-conetnt {
  146. height: 240rpx;
  147. margin: 0 auto;
  148. text-align: center;
  149. .title-img {
  150. position: absolute;
  151. top: 60rpx;
  152. left: 0;
  153. height: 100%;
  154. width: 100%;
  155. image {
  156. height: 100%;
  157. width: 100%;
  158. }
  159. }
  160. .title-content-box {
  161. position: absolute;
  162. width: 100%;
  163. text-align: center;
  164. .title-day-text {
  165. // margin: auto 0 ;
  166. // width: 150%;
  167. padding-top: 100rpx;
  168. // margin-right: 75%;
  169. // padding: -50rpx;
  170. font-size: $font-base + 2rpx;
  171. }
  172. .title-text {
  173. font-size: 50rpx;
  174. padding-top: 140rpx;
  175. }
  176. .title-button {
  177. background-color: #fe7e51;
  178. border-radius: 99rpx;
  179. width: 200rpx;
  180. height: 64rpx;
  181. margin: 0 auto;
  182. line-height: 64rpx;
  183. text-align: center;
  184. font-size: $font-base;
  185. &.signAction{
  186. background-color: $font-color-light;
  187. }
  188. }
  189. }
  190. }
  191. }
  192. .title-tip {
  193. color: #ffffff;
  194. font-size: $font-base - 2rpx;
  195. padding-top: 20rpx;
  196. text-align: center;
  197. margin-top: -40rpx;
  198. }
  199. .conenter {
  200. background-color: #fff;
  201. display: flex;
  202. padding: 60rpx 0;
  203. margin: 0 30rpx;
  204. border-radius: 10rpx;
  205. position: relative;
  206. top: -80rpx;
  207. .l {
  208. width: 2rpx;
  209. background-color: #EFEFEF;
  210. }
  211. .money,.day {
  212. width: 50%;
  213. text-align: center;
  214. color: #7e7e7e;
  215. font-family: PingFang-SC-Bold;
  216. text {
  217. font-size: 50rpx;
  218. font-weight: bold;
  219. }
  220. }
  221. }
  222. .explain {
  223. font-family: PingFang-SC-Bold;
  224. font-size: 30rpx;
  225. color: #333333;
  226. position: relative;
  227. top: -60rpx;
  228. background-color: #fff;
  229. padding: 30rpx;
  230. margin: 0 30rpx;
  231. border-radius: 10rpx;
  232. image {
  233. float: right;
  234. width: 14rpx;
  235. height: 30rpx;
  236. margin-top: 6rpx;
  237. }
  238. }
  239. </style>