index.vue 5.7 KB

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