index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <view class="main">
  3. <navbar :config="config" backColor="#666666"></navbar>
  4. <view class="cover">
  5. <view class="title1">本月已签到天数</view>
  6. <view class="title2"><text class="num">{{signDetail.num_day_sign_in_this_month}}</text>天</view>
  7. <view class="count-box">
  8. <view class="count">
  9. <view class="img"><text class="num">{{signDetail.cumulative_sign_in}}</text>天</view>
  10. <button>累计签到</button>
  11. </view>
  12. <view class="count">
  13. <view class="img"><text class="num">{{signDetail.cumulative_love_value}}</text></view>
  14. <button>累计爱心值</button>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="content">
  19. <view class="label">签到日历 {{nowYear}}年{{nowMonth}}月</view>
  20. <view class="date-box">
  21. <view class="date" :class="{
  22. active: siginDay.indexOf((item-2))>-1,
  23. active2: (siginDay[siginDay.length-1] != (item-2)) && (item-2)==nowDay,
  24. hide: (item-2)<1 || (item-2)>getCountDays()
  25. }" v-for="(item,index) in 35" :key="index">
  26. <view class="circle">
  27. <text class="iconfont2">&#xeb75;</text>
  28. </view>
  29. <view class="num">{{formDay(item-2)}}</view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="submit-box">
  34. <button class="submit" :class="nowDaySign?'':'active'" @click="submit()">立即签到</button>
  35. <view class="tip">{{signDetail.rules}}</view>
  36. </view>
  37. <uni-popup class="sign-popup" ref="submitPopup" type="center" :mask-click="false">
  38. <view class="content-box">
  39. <image @click="closePopup()" class="close" src="/static/signCenter/tip-close.png"></image>
  40. <view class="tip">
  41. <view class="title">签到赢爱心</view>
  42. <view class="tip-date">{{formDay(nowDay)}}</view>
  43. <view class="title2">签到成功,再接再厉</view>
  44. </view>
  45. <view class="tip-bar">{{successMsg}}</view>
  46. </view>
  47. </uni-popup>
  48. </view>
  49. </template>
  50. <script>
  51. export default{
  52. data(){
  53. return {
  54. //手机状态栏高度
  55. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  56. config: {
  57. back: true,
  58. title: '签到中心',
  59. color: '#1A1A1A',
  60. backgroundColor: [1, "#fff"],
  61. statusBarFontColor: '#1A1A1A'
  62. },
  63. nowYear: new Date().getFullYear(),//当年
  64. nowMonth: (new Date().getMonth()+1)<10?('0'+(new Date().getMonth()+1)):(new Date().getMonth()+1),//当月
  65. nowDay: new Date().getDate(),//当天
  66. successMsg: '',
  67. signDetail:{
  68. cumulative_love_value: '',
  69. cumulative_sign_in: '',
  70. num_day_sign_in_this_month: '',
  71. rules: ''
  72. },
  73. siginDay: [],//已签到
  74. nowDaySign: false
  75. }
  76. },
  77. onLoad() {
  78. this.getDetail();
  79. this.getList();
  80. },
  81. methods:{
  82. formDay(day){
  83. return day>9?day:`0${day}`
  84. },
  85. openPopup(){
  86. this.$refs.submitPopup.open();
  87. },
  88. closePopup(){
  89. this.$refs.submitPopup.close();
  90. },
  91. submit(){
  92. if(this.nowDaySign){
  93. uni.showToast({
  94. icon: 'none',
  95. title: '您今天已签到'
  96. })
  97. return ;
  98. }
  99. let that = this;
  100. uni.showModal({
  101. title: '提示',
  102. content: '您确认要签到吗',
  103. success: function (res) {
  104. if (res.confirm) {
  105. uni.showLoading({
  106. title: '正在提交中...',
  107. mask: true
  108. });
  109. that.$http.post('/signInRecord/signInNow',{})
  110. .then(res => {
  111. if(res.code==200){
  112. that.successMsg = res.data;
  113. that.openPopup();
  114. //更新详情
  115. that.getDetail();
  116. that.getList();
  117. }
  118. })
  119. .finally(()=>{
  120. uni.hideLoading();
  121. })
  122. }
  123. }
  124. });
  125. },
  126. getDetail(){
  127. this.$http.get(`/signInRecord/dataStatistics/${this.nowYear}-${this.nowMonth}`,{})
  128. .then(res=>{
  129. if (res.code == 200) {
  130. this.signDetail = res.list;
  131. }
  132. })
  133. },
  134. getList(){
  135. this.$http.get(`/signInRecord/list/${this.nowYear}-${this.nowMonth}`,{})
  136. .then(res=>{
  137. if (res.code == 200) {
  138. this.siginDay = res.list.map(dateStr=>{
  139. let day = new Date(dateStr.replace(/-/g, '/')).getDate();
  140. return day
  141. })
  142. if(this.siginDay[this.siginDay.length-1] == this.nowDay){
  143. this.nowDaySign = true;
  144. }
  145. }
  146. })
  147. },
  148. //获取当月所有的天数
  149. getCountDays() {
  150. let curDate = new Date();
  151. /* 获取当前月份 */
  152. let curMonth = curDate.getMonth();
  153. /* 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
  154. curDate.setMonth(curMonth + 1);
  155. /* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
  156. curDate.setDate(0);
  157. /* 返回当月的天数 */
  158. return curDate.getDate();
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .main{
  165. min-height: 100vh;
  166. background-image: url('/static/signCenter/bg.png');
  167. background-size: 100%;
  168. background-position: 0 40rpx;
  169. .cover{
  170. width: 100%;
  171. height: 320rpx;
  172. padding: 40rpx 0 0 0;
  173. text-align: center;
  174. .title1{
  175. font-size: 30rpx;
  176. font-family: PingFang SC, PingFang SC-Bold;
  177. font-weight: 700;
  178. text-align: center;
  179. color: #40a999;
  180. margin-bottom: 10rpx;
  181. }
  182. .title2{
  183. font-size: 28rpx;
  184. font-family: PingFang SC, PingFang SC-Regular;
  185. font-weight: 400;
  186. color: #40a999;
  187. line-height: 46rpx;
  188. .num{
  189. font-size: 52rpx;
  190. }
  191. }
  192. .count-box{
  193. padding: 0 168rpx;
  194. width: 100%;
  195. display: flex;
  196. justify-content: space-between;
  197. .count{
  198. position: relative;
  199. .img{
  200. position: absolute;
  201. top: 0;
  202. left: 50%;
  203. transform: translateX(-50%);
  204. z-index: 1;
  205. height: 90rpx;
  206. width: 90rpx;
  207. font-size: 18rpx;
  208. font-family: PingFang SC, PingFang SC-Bold;
  209. font-weight: 700;
  210. color: #ffffff;
  211. line-height: 90rpx;
  212. background-image: url('/static/signCenter/progress.png');
  213. background-size: 100% 100%;
  214. .num{
  215. font-size: 26rpx;
  216. }
  217. }
  218. button{
  219. margin-top: 80rpx;
  220. height: 60rpx;
  221. padding: 0 27rpx;
  222. background: #3fa797;
  223. border-radius: 30rpx;
  224. font-size: 24rpx;
  225. font-family: PingFang SC, PingFang SC-Regular;
  226. font-weight: 400;
  227. text-align: center;
  228. color: #ffffff;
  229. }
  230. }
  231. }
  232. }
  233. .content{
  234. width: 100%;
  235. padding: 0 30rpx;
  236. margin-top: 20rpx;
  237. position: relative;
  238. .label{
  239. position: absolute;
  240. top: -34rpx;
  241. left: 50%;
  242. transform: translateX(-50%);
  243. width: 440rpx;
  244. height: 102rpx;
  245. line-height: 102rpx;
  246. background-image: url('/static/signCenter/label.png');
  247. background-size: 100% 100%;
  248. font-size: 32rpx;
  249. font-family: PingFang SC, PingFang SC-Regular;
  250. font-weight: 400;
  251. text-align: center;
  252. color: #ffffff;
  253. }
  254. .date-box{
  255. width: 100%;
  256. border-radius: 20rpx;
  257. background-color: white;
  258. padding: 100rpx 30rpx 70rpx 30rpx;
  259. box-sizing: border-box;
  260. display: flex;
  261. justify-content: space-around;
  262. flex-wrap: wrap;
  263. .date{
  264. width: 83rpx;
  265. height: 123rpx;
  266. background: #F5F5F5;
  267. border-radius: 10rpx;
  268. padding: 7rpx 12rpx;
  269. margin-bottom: 10rpx;
  270. &.active{
  271. background: #67ca96;
  272. .circle{
  273. background: #4eb47e;
  274. color: #ffffff;
  275. }
  276. .num{
  277. color: #ffffff;
  278. }
  279. }
  280. &.active2{
  281. background: #FBE180;
  282. .circle{
  283. background: #FFB221;
  284. color: #ffffff;
  285. }
  286. .num{
  287. color: #333333;
  288. }
  289. }
  290. &.hide{
  291. visibility: hidden;
  292. }
  293. .circle{
  294. width: 60rpx;
  295. height: 60rpx;
  296. line-height: 60rpx;
  297. background: #E6E6E6;
  298. color: #B3B3B3;
  299. border-radius: 50%;
  300. text-align: center;
  301. margin-bottom: 5rpx;
  302. .iconfont2{
  303. font-size: 35rpx;
  304. }
  305. }
  306. .num{
  307. font-size: 32rpx;
  308. font-family: PingFang SC, PingFang SC-Regular;
  309. font-weight: 400;
  310. text-align: center;
  311. color: #333333;
  312. }
  313. }
  314. }
  315. }
  316. .submit-box{
  317. background-image: url('/static/signCenter/bg2.png');
  318. background-size: 100%;
  319. padding: 0 30rpx 35rpx 30rpx;
  320. text-align: left;
  321. .submit{
  322. width: 690rpx;
  323. height: 87rpx;
  324. line-height: 87rpx;
  325. border-radius: 44rpx;
  326. margin: 35rpx auto;
  327. font-size: 34rpx;
  328. font-family: PingFang SC, PingFang SC-Regular;
  329. font-weight: 400;
  330. background: #F5F5F5;
  331. color: #999999;
  332. &.active{
  333. background: linear-gradient(179deg,#2bb42c 0%, #057e53 100%);
  334. color: white;
  335. }
  336. }
  337. .tip{
  338. font-size: 28rpx;
  339. font-family: PingFang SC, PingFang SC-Regular;
  340. font-weight: 400;
  341. color: #ffffff;
  342. line-height: 45rpx;
  343. }
  344. }
  345. .sign-popup{
  346. .content-box{
  347. position: relative;
  348. .close{
  349. width: 54rpx;
  350. height: 54rpx;
  351. position: absolute;
  352. top: -58rpx;
  353. right: 0;
  354. }
  355. .tip{
  356. width: 580rpx;
  357. height: 392rpx;
  358. background-image: url('/static/signCenter/tip.png');
  359. background-size: 100% 100%;
  360. padding-top: 60rpx;
  361. padding-left: 40rpx;
  362. text-align: center;
  363. .tip-date{
  364. display: block;
  365. margin: 25rpx auto;
  366. width: 187rpx;
  367. height: 130rpx;
  368. line-height: 150rpx;
  369. background-image: url('/static/signCenter/tip-date.png');
  370. background-size: 100% 100%;
  371. font-size: 40rpx;
  372. color: #057e53;
  373. font-weight: 500;
  374. }
  375. .title{
  376. font-size: 34rpx;
  377. font-family: PingFang SC, PingFang SC-Bold;
  378. font-weight: 700;
  379. text-align: center;
  380. color: #1a1a1a;
  381. }
  382. .title2{
  383. font-size: 30rpx;
  384. font-family: PingFang SC, PingFang SC-Bold;
  385. font-weight: 700;
  386. text-align: center;
  387. color: #333333;
  388. line-height: 45rpx;
  389. }
  390. }
  391. .tip-bar{
  392. width: 510rpx;
  393. height: 76rpx;
  394. line-height: 70rpx;
  395. background-image: url('/static/signCenter/tip-bar.png');
  396. background-size: 100% 100%;
  397. margin: -10rpx auto 0 auto;
  398. font-size: 24rpx;
  399. font-family: PingFang SC, PingFang SC-Regular;
  400. font-weight: 400;
  401. text-align: center;
  402. color: #22ab30;
  403. }
  404. }
  405. }
  406. }
  407. </style>