sign.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <view v-if="ifShow" class="signBox">
  3. <JHeader title="签到领积分" width="50" height="50" style="padding: 24upx 0 0;"></JHeader>
  4. <view class="signBg">
  5. <view style="font-size: 44upx;font-weight: bold;text-align: center;">每日签到送积分</view>
  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. <tui-icon name="arrowleft" :size="48" unit="upx" color="#C5AA7B" @click="lastMonth"></tui-icon>
  27. <view>{{ year }}年{{ month }}月</view>
  28. <tui-icon name="arrowright" :size="48" unit="upx" color="#C5AA7B" @click="nextMonth"></tui-icon>
  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 class="redEnvelope mar-top-20">
  53. <view class="redEnvelopeBg flex-items flex-center">
  54. <view>
  55. <view class="fs32 font-color-333">积分兑换红包优惠券</view>
  56. <view class="fs24 font-color-999 mar-top-10">各种大额红包等你兑换哦</view>
  57. <view class="fs24 font-color-FFF exchangeBtn mar-top-20" @click="goToexchange">马上兑换</view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 签到弹窗 -->
  63. <tui-modal :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. </tui-modal>
  81. </view>
  82. </template>
  83. <script>
  84. import { updateCreditSignInApi, updateCreditSelectByMonthApi } from '../../../api/anotherTFInterface'
  85. export default {
  86. name: 'Sign',
  87. data() {
  88. return {
  89. signList: [],
  90. year: new Date().getFullYear(), // 当前年
  91. month: new Date().getMonth() + 1, // 当前月
  92. continuousNum: '', // 连续签到天数
  93. currentDay: new Date(Date.now()).toLocaleString()
  94. .substring(0, 10)
  95. .replaceAll('/', '-'),
  96. currentMonth: new Date(Date.now()).toLocaleString()
  97. .substring(0, 7)
  98. .replaceAll('/', '-'),
  99. lastDay: '',
  100. weeked: '', // 今天周几
  101. dayArr: [], // 当前月每日
  102. day: new Date().getDate(), // 当前日
  103. weekArr: ['日', '一', '二', '三', '四', '五', '六'], // 每周
  104. type: 'sign',
  105. checkDate: true,
  106. bgweek: '#C5AA7B',
  107. bgday: '#C5AA7B',
  108. signTips: false,
  109. ifShow: false
  110. }
  111. },
  112. onLoad() {
  113. this.getSignData()
  114. },
  115. methods: {
  116. getSignData() {
  117. // uni.showLoading({
  118. // mask: true,
  119. // title: '请稍等...',
  120. // })
  121. const selectMonth = this.year + '-' + this.formatNum(this.month)
  122. const that = this
  123. updateCreditSelectByMonthApi({ month: `${this.year}-${this.formatNum(this.month)}` })
  124. .then((res) => {
  125. // uni.hideLoading()
  126. that.ifShow = true
  127. that.signList = res.data
  128. // 初始日期
  129. that.initDate()
  130. // 今天日期
  131. if (that.currentMonth === selectMonth) {
  132. that.continuousNum = that.signList[that.signList.length - 1].continueDay || 0
  133. that.lastDay = that.signList[that.signList.length - 1].createTime.substring(0, 10)
  134. }
  135. // 今天周几
  136. that.weeked = that.weekArr[new Date().getDay()]
  137. // 签到功能
  138. if (that.type !== 'calendar') {
  139. for (const i in that.dayArr) {
  140. that.$set(this.dayArr[i], 'flag', false)
  141. }
  142. }
  143. that.signList.forEach((item) => {
  144. item.day = parseInt(item.createTime.slice(8, 10))
  145. })
  146. for (let i = 0; i < that.signList.length; i++) {
  147. for (let j = 0; j < that.dayArr.length; j++) {
  148. if (that.signList[i].day === that.dayArr[j].day && that.dayArr[j].date !== '') {
  149. that.dayArr[j].select = 1
  150. }
  151. }
  152. }
  153. })
  154. },
  155. // 签到
  156. signInFn() {
  157. // uni.showLoading({
  158. // mask: true,
  159. // title: '请稍等...',
  160. // })
  161. updateCreditSignInApi({}).then((res) => {
  162. // uni.hideLoading()
  163. this.getSignData()
  164. this.signTips = true
  165. })
  166. },
  167. // 格式化日期位数
  168. formatNum(num) {
  169. return num < 10 ? '0' + num : num
  170. },
  171. // 选择年月
  172. changeDate(e) {
  173. const that = this
  174. that.year = parseInt(e.detail.value.split('-')[0])
  175. that.month = parseInt(e.detail.value.split('-')[1])
  176. this.getSignData()
  177. },
  178. // 点击签到
  179. signToday(obj, index) {
  180. },
  181. // 初始化日期
  182. initDate() {
  183. const that = this
  184. that.dayArr = []
  185. // 当前月总天数
  186. const totalDay = new Date(that.year, that.month, 0).getDate()
  187. // 遍历总天数将日期逐个添加至数组
  188. for (let i = 1; i <= totalDay; i++) {
  189. // 得到需补充天数
  190. const value = new Date(that.year, that.month - 1, i).getDay()
  191. // 补充前面空白日期
  192. if (i === 1 && value !== 0) that.addBefore(value)
  193. // 添加本月日期
  194. const obj = {}
  195. obj.date = that.year + '-' + that.formatNum(that.month) + '-' + that.formatNum(i)
  196. obj.day = i
  197. obj.select = 0
  198. that.dayArr.push(obj)
  199. // 补充后面空白日期
  200. if (i === totalDay && value !== 6) that.addAfter(value)
  201. }
  202. },
  203. // 补充前面空白日期
  204. addBefore(value) {
  205. const that = this
  206. const totalDay = new Date(that.year, that.month - 1, 0).getDate()
  207. for (let i = 0; i < value; i++) {
  208. const obj = {}
  209. obj.date = ''
  210. obj.day = totalDay - (value - i) + 1
  211. that.dayArr.push(obj)
  212. }
  213. },
  214. // 补充后空白日期
  215. addAfter(value) {
  216. const that = this
  217. for (let i = 0; i < (6 - value); i++) {
  218. const obj = {}
  219. obj.date = ''
  220. obj.day = i + 1
  221. that.dayArr.push(obj)
  222. }
  223. },
  224. // 上一个月
  225. lastMonth() {
  226. const that = this
  227. if (that.month === 1) {
  228. that.year -= 1
  229. that.month = 12
  230. } else {
  231. that.month -= 1
  232. }
  233. that.getSignData()
  234. },
  235. // 下一个月
  236. nextMonth() {
  237. const that = this
  238. if (that.month === 12) {
  239. that.year += 1
  240. that.month = 1
  241. } else {
  242. that.month += 1
  243. }
  244. that.getSignData()
  245. },
  246. goToexchange() {
  247. uni.navigateTo({
  248. url: '/another-tf/another-serve/integral/index?tabActive=2'
  249. })
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="less" scoped>
  255. .signBox {
  256. background-color: #F8F8F8;
  257. padding-bottom: 50rpx;
  258. .signBg {
  259. background-size: contain;
  260. min-height: 100vh;
  261. padding-top: 160rpx;
  262. .signDayNumBox {
  263. width: 100%;
  264. .signDayNum {
  265. color: #93866F;
  266. text {
  267. color: #FDF3D0;
  268. margin: 0 10rpx;
  269. }
  270. }
  271. }
  272. .signState {
  273. .signStateBg {
  274. width: 300rpx;
  275. height: 300rpx;
  276. background-color: #fddd99;
  277. background-size: contain;
  278. text {
  279. color: #C83732;
  280. }
  281. }
  282. .noSign {
  283. background-color: #cccccc;
  284. background-size: contain;
  285. text {
  286. color: #FFFFFF;
  287. }
  288. }
  289. }
  290. .calendarBox {
  291. padding: 0 20rpx;
  292. min-height: 300rpx;
  293. .calendarBg {
  294. border-radius: 16rpx;
  295. background: #FFFFFF;
  296. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.05);
  297. overflow: hidden;
  298. }
  299. }
  300. }
  301. .redEnvelope {
  302. padding: 0 20rpx;
  303. .redEnvelopeBg {
  304. height: 230rpx;
  305. background-color: #fff9f6;
  306. background-size: contain;
  307. padding-right: 50rpx;
  308. .exchangeBtn {
  309. width: 160rpx;
  310. height: 56rpx;
  311. line-height: 56rpx;
  312. background: #C83732;
  313. border-radius: 8rpx;
  314. text-align: center;
  315. }
  316. }
  317. }
  318. }
  319. .calendar-box {
  320. width: 100%;
  321. flex-direction: column;
  322. justify-content: center;
  323. }
  324. .calendar-box,
  325. .month,
  326. .week,
  327. .day {
  328. display: flex;
  329. align-items: center;
  330. justify-content: space-between;
  331. }
  332. .month,
  333. .week,
  334. .day {
  335. width: 100%;
  336. }
  337. .month {
  338. height: 96rpx;
  339. padding: 0 50rpx;
  340. position: relative;
  341. background: #FAF6ED;
  342. }
  343. .picker {
  344. width: 160rpx;
  345. height: 40rpx;
  346. position: absolute;
  347. top: 20rpx;
  348. left: 50%;
  349. transform: translate(-50%, -50%);
  350. }
  351. .day {
  352. flex-wrap: wrap;
  353. }
  354. .week>view,
  355. .day>view.dayItem {
  356. width: 100rpx;
  357. height: 100rpx;
  358. position: relative;
  359. line-height: 100rpx;
  360. display: flex;
  361. justify-content: center;
  362. align-items: center;
  363. }
  364. .dayValue {
  365. width: 60rpx;
  366. height: 60rpx;
  367. text-align: center;
  368. position: relative;
  369. line-height: 60rpx;
  370. }
  371. .checkday {
  372. color: #999;
  373. }
  374. .select {
  375. background: #FAF6ED;
  376. color: #C5AA7B;
  377. border-radius: 50%;
  378. }
  379. .choose {
  380. color: #FFFFFF;
  381. background: #C5AA7B;
  382. border-radius: 50%;
  383. }
  384. .Put-box1 {
  385. .btn {
  386. text-align: center;
  387. margin-top: 40rpx;
  388. border: 2rpx solid #333333;
  389. height: 80upx;
  390. line-height: 80upx;
  391. width: 240upx;
  392. color: #333333;
  393. }
  394. .submit {
  395. background-color: #333333;
  396. color: #FFEBC4;
  397. }
  398. }
  399. </style>