index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template lang="">
  2. <div
  3. style="
  4. height: 100vh;
  5. background: linear-gradient(216deg, #fe854c 0%, #ff9a5a 100%);
  6. box-sizing: border-box;
  7. overflow: scroll;
  8. "
  9. >
  10. <div
  11. :style="{
  12. background: 'url(https://file.rongcyl.cn/festatic/bkm/first2/bg.png)',
  13. height: 'calc(100vh - 160rpx)',
  14. 'background-repeat': 'no-repeat',
  15. 'background-position': 'center center',
  16. 'background-size': 'cover',
  17. 'padding-top': safeAreaTop,
  18. 'box-sizing': 'border-box',
  19. overflow: 'scroll',
  20. 'padding-bottom': '160rpx',
  21. }"
  22. >
  23. <div class="card rounded-md shadow-sm mx-auto mt-10 py-2">
  24. <div class="fs16 bold italic text-gray-900 pl-3 my-2">签到赚积分</div>
  25. <div class="flex justify-between text-black px-3">
  26. <div v-for="day in weekdays">周{{ day }}</div>
  27. </div>
  28. <div class="flex justify-between px-3 mt-2">
  29. <div
  30. style="width: 60rpx; height: 60rpx"
  31. :class="{ 'bg-amber-200': i >= todayIndex || day.status, 'bg-gray-200': i < todayIndex }"
  32. class="flex justify-center items-center rounded-full"
  33. v-for="(day, i) in signList"
  34. @click="sign(i)"
  35. >
  36. <div
  37. style="width: 45rpx; height: 45rpx"
  38. :class="{ 'bg-amber-300': i >= todayIndex || day.status, 'bg-gray-300': i < todayIndex }"
  39. class="flex justify-center items-center rounded-full"
  40. >
  41. <span
  42. class="fs11 bold"
  43. :class="{ 'text-red-400': i >= todayIndex || day.status, 'text-gray-400': i < todayIndex }"
  44. >
  45. +1
  46. </span>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="flex justify-between px-3 mt-2">
  51. <div v-for="day in signList">
  52. <span v-if="day.status" class="fs12 text-green-500">已签到</span>
  53. <span v-else="day.status" class="fs12 text-grey-500">未签到</span>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="card rounded-md shadow-sm mx-auto mt-4 py-2">
  58. <div class="fs16 bold italic text-gray-900 pl-3 my-2">消费领优惠券</div>
  59. <div class="flex items-center px-3">
  60. <img
  61. src="https://file.rongcyl.cn/festatic/bkm/task/coupon.png"
  62. style="width: 80rpx; height: 80rpx"
  63. class=""
  64. />
  65. <div class="ml-3 flex-1">
  66. <div>
  67. <span>连续消费满 {{ totalNum }} 天领取</span>
  68. <span class="text-rose-500">({{ status == 2 ? 7 : currentNum }}/{{ totalNum }})</span>
  69. </div>
  70. <div style="color: #ff2c43">
  71. <span>¥</span>
  72. <span class="bold fs15">{{ couponPrice }}</span>
  73. </div>
  74. </div>
  75. <div></div>
  76. <div
  77. style="width: 110rpx; height: 44rpx; line-height: 44rpx"
  78. class="rounded-sm bg-purple-100 fs14 text-center"
  79. @click="reveiveTaskReward"
  80. >
  81. 领取
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </template>
  88. <script>
  89. import { getSignList, signToday, getTaskStat, reveiveTaskReward } from '@/api/task'
  90. export default {
  91. data() {
  92. return {
  93. safeAreaTop: '0px',
  94. signList: [],
  95. todayIndex: -1,
  96. weekdays: ['一', '二', '三', '四', '五', '六', '日'],
  97. currentNum: 0,
  98. totalNum: 0,
  99. couponPrice: 0,
  100. status: 0,
  101. }
  102. },
  103. created() {
  104. this.getSafeAreaTop()
  105. this.getList()
  106. this.getTaskStat()
  107. },
  108. methods: {
  109. reveiveTaskReward() {
  110. if (this.status == 2) {
  111. wx.showToast({
  112. title: '已领取',
  113. icon: 'error',
  114. })
  115. return
  116. }
  117. if (this.currentNum < this.totalNum) {
  118. wx.showToast({
  119. title: '未达到领取条件',
  120. icon: 'error',
  121. })
  122. return
  123. }
  124. reveiveTaskReward().then(rs => {
  125. wx.showToast({
  126. title: '领取成功',
  127. icon: 'sucess',
  128. })
  129. this.getTaskStat()
  130. })
  131. },
  132. getTaskStat() {
  133. getTaskStat().then(rs => {
  134. this.currentNum = rs.data.currentNum
  135. this.totalNum = rs.data.totalNum
  136. this.couponPrice = rs.data.couponPrice
  137. this.status = rs.data.status
  138. console.log(rs)
  139. })
  140. },
  141. posTodayIndex() {
  142. var today = this.getTodayString()
  143. for (var i = 0; i < this.signList.length; i++) {
  144. if (this.signList[i].date === today) {
  145. this.todayIndex = i
  146. break
  147. }
  148. }
  149. },
  150. getTodayString() {
  151. var today = new Date()
  152. var year = today.getFullYear()
  153. var month = String(today.getMonth() + 1).padStart(2, '0') // Months are 0-based
  154. var day = String(today.getDate()).padStart(2, '0')
  155. return year + '-' + month + '-' + day
  156. },
  157. getList() {
  158. getSignList().then(rs => {
  159. this.signList = rs.data
  160. this.posTodayIndex()
  161. })
  162. },
  163. sign(i) {
  164. if (i == this.todayIndex) {
  165. signToday().then(this.getList)
  166. wx.showToast({
  167. title: '签到成功',
  168. icon: 'sucess',
  169. })
  170. }
  171. },
  172. getSafeAreaTop() {
  173. wx.getSystemInfo({
  174. success: res => {
  175. this.safeAreaTop = res.safeArea.top + 'px'
  176. },
  177. })
  178. },
  179. },
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. .card {
  184. width: 90%;
  185. background-image: linear-gradient(45deg, #f5eeea 0%, #faab86 100%);
  186. }
  187. </style>