sign.vue 10 KB

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