sign.vue
11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<template>
<view>
<global-loading />
<view class="signBox" v-if="ifShow">
<view class="signBg">
<view class="signDayNumBox flex-center" v-if="continuousNum">
<view class="signDayNum fs28">
当前周期已连续签到
<text class="fs40">{{ continuousNum || '0' }}</text>
天
</view>
</view>
<view v-if="currentDay == lastDay" class="signState flex-center mar-top-30">
<view class="signStateBg flex-items flex-center noSign">
<text class="fs48">已签到</text>
</view>
</view>
<view v-if="currentDay != lastDay" class="signState flex-center mar-top-30" @click="signInFn" >
<view class="signStateBg flex-items flex-center">
<text class="fs48">未签到</text>
</view>
</view>
<view class="calendarBox">
<view class="calendarBg">
<view class="calendar-box">
<view class="month">
<view class="u-arrow u-arrow-left" @click="lastMonth"></view>
<view>{{year}}年{{month}}月</view>
<view class="u-arrow u-arrow-right" @click="nextMonth"></view>
<picker v-if="checkDate" class="picker" mode="date" fields="month" @change="changeDate" />
</view>
<view class="week">
<view :style="'color:'+(weeks==weeked?bgweek:'')+';'" v-for="weeks in weekArr">{{weeks}}</view>
</view>
<view class="day">
<view
class="dayItem"
v-for="(days,index) in dayArr"
:key="index"
@click="signToday(days,index)"
>
<view
:class="[
{'checkday':days.date==''},
{'choose':days.date==currentDay},
{'select': days.select === 1}
]"
class="dayValue"
>{{days.day}}</view>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="redEnvelope mar-top-20">
<view class="redEnvelopeBg flex-items flex-end">
<view>
<view class="fs32 font-color-333">积分兑换红包优惠券</view>
<view class="fs24 font-color-999 mar-top-10">各种大额红包等你兑换哦</view>
<view class="fs24 font-color-FFF exchangeBtn mar-top-20" @click="goToexchange">马上兑换</view>
</view>
</view>
</view>
<!-- 签到弹窗 -->
<tui-modal :show="signTips" :custom="true" :fadein="true">
<view class="Put-box1">
<view class="text-align fs34 fs-bold">
签到成功
</view>
<view class="mar-top-40 text-align">
今日签到成功,签到积分可以在我的积分内兑换商品
</view>
<view class="flex-display flex-sp-between">
<view class="btn" @click="signTips = false">
取消
</view>
<view class="btn submit" @click="signTips = false">
确定
</view>
</view>
</view>
</tui-modal>
</view>
</view>
</template>
<script>
import tuiModal from "@/components/modal/modal";
import dateUtil from "@/utils/dateUtil"
const NET = require('../../utils/request')
const API = require('../../config/api')
export default {
components: {
tuiModal
},
name: "sign",
data() {
return {
signList: [],
year: new Date().getFullYear(), // 当前年
month: new Date().getMonth() + 1, // 当前月
continuousNum: '', // 连续签到天数
currentDay: dateUtil.formatDate(),
currentMonth: dateUtil.formatMonth(),
lastDay: '',
weeked: '', // 今天周几
dayArr: [], // 当前月每日
day: new Date().getDate(), // 当前日
weekArr: ['日', '一', '二', '三', '四', '五', '六'], // 每周
type: 'sign',
checkDate: true,
bgweek: '#C5AA7B',
bgday: '#C5AA7B',
signTips: false,
ifShow: false
}
},
onLoad() {
this.getSignData()
},
methods: {
getSignData() {
// uni.showLoading({
// mask: true,
// title: '请稍等...',
// })
let selectMonth = this.year + '-' + this.formatNum(this.month)
const that = this
NET.request(API.selectByMonth,
{
month: `${this.year}-${this.formatNum(this.month)}`
},
'POST')
.then(res => {
// uni.hideLoading()
that.ifShow = true
that.signList = res.data
// 初始日期
that.initDate()
// 今天日期
if (that.currentMonth === selectMonth) {
console.log('currentMoth === selectMonth', that.currentMonth === selectMonth)
that.continuousNum = that.signList[that.signList.length - 1].continueDay || 0;
that.lastDay = that.signList[that.signList.length - 1].createTime.substring(0,10);
console.log('this.lastDay', that.lastDay)
}
// 今天周几
that.weeked = that.weekArr[new Date().getDay()];
// 签到功能
if (that.type !== 'calendar') {
for (let i in that.dayArr) {
that.$set(this.dayArr[i], 'flag', false);
}
}
that.signList.forEach((item) => {
item['day'] = parseInt(item.createTime.slice(8, 10))
})
for (let i = 0; i < that.signList.length; i++) {
for (let j = 0; j < that.dayArr.length; j++) {
if (that.signList[i].day === that.dayArr[j].day && that.dayArr[j].date !== '') {
that.dayArr[j].select = 1
}
}
}
}).catch(res => {})
},
signDate(event) {
console.log(event);
},
// 签到
signInFn() {
// uni.showLoading({
// mask: true,
// title: '请稍等...',
// })
NET.request(API.creditSignIn, {}, 'POST').then(res => {
// uni.hideLoading()
this.getSignData()
this.signTips = true
}).catch(res => {})
},
// 格式化日期位数
formatNum(num) {
return num < 10 ? ('0' + num) : num;
},
// 选择年月
changeDate(e) {
let that = this;
that.year = parseInt(e.detail.value.split('-')[0]);
that.month = parseInt(e.detail.value.split('-')[1]);
this.getSignData()
},
// 点击签到
signToday(obj, index) {
},
// 初始化日期
initDate() {
let that = this;
that.dayArr = [];
// 当前月总天数
let totalDay = new Date(that.year, that.month, 0).getDate();
// 遍历总天数将日期逐个添加至数组
for (let i = 1; i <= totalDay; i++) {
// 得到需补充天数
let value = (new Date(that.year, that.month - 1, i)).getDay();
// 补充前面空白日期
if (i === 1 && value !== 0) that.addBefore(value);
// 添加本月日期
let obj = {};
obj.date = that.year + '-' + that.formatNum(that.month) + '-' + that.formatNum(i);
obj.day = i;
obj.select = 0
that.dayArr.push(obj);
// 补充后面空白日期
if (i === totalDay && value !== 6) that.addAfter(value);
}
},
// 补充前面空白日期
addBefore(value) {
let that = this;
let totalDay = new Date(that.year, that.month - 1, 0).getDate();
for (let i = 0; i < value; i++) {
let obj = {};
obj.date = '';
obj.day = totalDay - (value - i) + 1;
that.dayArr.push(obj);
}
},
// 补充后空白日期
addAfter(value) {
let that = this;
for (let i = 0; i < (6 - value); i++) {
let obj = {};
obj.date = '';
obj.day = i + 1;
that.dayArr.push(obj);
}
},
// 上一个月
lastMonth() {
let that = this;
if (that.month === 1) {
that.year -= 1;
that.month = 12;
} else {
that.month -= 1;
}
that.getSignData();
},
// 下一个月
nextMonth() {
let that = this;
if (that.month === 12) {
that.year += 1;
that.month = 1;
} else {
that.month += 1;
}
that.getSignData();
},
goToexchange() {
uni.navigateTo({
url: '../../pages_category_page1/integral/index?tabActive=2'
})
}
}
}
</script>
<style lang="scss" scoped>
page {
background: #F8F8F8;
}
.signBox {
padding-bottom: 50rpx;
.signBg {
background: url("https://jy.scjysm.asia:18086/cdwlMall/questionnaire/file/static/images/signBg.png") no-repeat left top;
background-size: contain;
min-height: 702rpx;
padding-top: 160rpx;
.signDayNumBox {
width: 100%;
.signDayNum {
color: #93866F;
text {
color: #FDF3D0;
margin: 0 10rpx;
}
}
}
.signState {
.signStateBg {
width: 300rpx;
height: 300rpx;
background: url("https://jy.scjysm.asia:18086/cdwlMall/questionnaire/file/static/images/signState.png") no-repeat left top;
background-size: contain;
text {
color: #C83732;
}
}
.noSign {
background: url("https://jy.scjysm.asia:18086/cdwlMall/questionnaire/file/static/images/signState1.png") no-repeat left top;
background-size: contain;
text {
color: #FFFFFF;
}
}
}
.checked {
.signStateBg {
text {
color: #FFFFFF;
}
}
}
.calendarBox {
padding: 0 20rpx;
min-height: 300rpx;
.calendarBg {
border-radius: 16rpx;
background: #FFFFFF;
box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.05);
overflow: hidden;
}
}
}
.redEnvelope {
padding: 0 20rpx;
.redEnvelopeBg {
height: 230rpx;
background: url("https://jy.scjysm.asia:18086/cdwlMall/questionnaire/file/static/images/redEnvelopeBg.png") no-repeat left top;
background-size: contain;
padding-right: 50rpx;
.exchangeBtn {
width: 160rpx;
height: 56rpx;
line-height: 56rpx;
background: #C83732;
border-radius: 8rpx;
text-align: center;
}
}
}
}
.calendar-box {
width: 100%;
flex-direction: column;
justify-content: center;
}
.calendar-box,
.month,
.week,
.day {
display: flex;
align-items: center;
justify-content: space-between;
}
.month,
.week,
.day {
width: 100%;
}
.month {
height: 96rpx;
padding: 0 50rpx;
position: relative;
background: #FAF6ED;
.u-arrow {
border-top: 4rpx solid #666;
border-right: 4rpx solid #666;
}
}
.picker {
width: 160rpx;
height: 40rpx;
position: absolute;
top: 20rpx;
left: 50%;
transform: translate(-50%, -50%);
}
.day {
flex-wrap: wrap;
.dayValue {
}
}
.week>view,
.day>view.dayItem {
width: 100rpx;
height: 100rpx;
position: relative;
line-height: 100rpx;
display: flex;
justify-content: center;
align-items: center;
}
.dayValue {
width: 60rpx;
height: 60rpx;
text-align: center;
position: relative;
line-height: 60rpx;
}
.checkday {
color: #999;
}
.select {
background: #FAF6ED;
color: #C5AA7B;
border-radius: 50%;
}
.choose {
color: #FFFFFF;
background: #C5AA7B;
border-radius: 50%;
}
.circle {
width: 10rpx;
height: 10rpx;
border-radius: 50%;
position: absolute;
bottom: 10%;
left: 50%;
transform: translate(-50%, -50%);
}
.sign {
background-color: #0089fe;
}
.repair {
background-color: #f4a01a;
}
.Put-box1 {
.btn {
text-align: center;
margin-top: 40rpx;
border: 2rpx solid #333333;
height: 80upx;
line-height: 80upx;
width: 240upx;
color: #333333;
}
.submit {
background-color: #333333;
color: #FFEBC4;
}
}
</style>