index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. <span v-if="status == 2">已</span>
  82. 领取
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import { getSignList, signToday, getTaskStat, reveiveTaskReward } from '@/api/task'
  91. export default {
  92. data() {
  93. return {
  94. safeAreaTop: '0px',
  95. signList: [],
  96. todayIndex: -1,
  97. weekdays: ['一', '二', '三', '四', '五', '六', '日'],
  98. currentNum: 0,
  99. totalNum: 0,
  100. couponPrice: 0,
  101. status: 0,
  102. }
  103. },
  104. created() {
  105. this.getSafeAreaTop()
  106. this.getList()
  107. this.getTaskStat()
  108. },
  109. methods: {
  110. reveiveTaskReward() {
  111. if (this.status == 2) {
  112. return
  113. }
  114. if (this.currentNum < this.totalNum) {
  115. wx.showToast({
  116. title: '未达到领取条件',
  117. icon: 'error',
  118. })
  119. return
  120. }
  121. reveiveTaskReward().then(rs => {
  122. wx.showToast({
  123. title: '领取成功',
  124. icon: 'sucess',
  125. })
  126. this.getTaskStat()
  127. })
  128. },
  129. getTaskStat() {
  130. getTaskStat().then(rs => {
  131. this.currentNum = rs.data.currentNum
  132. this.totalNum = rs.data.totalNum
  133. this.couponPrice = rs.data.couponPrice
  134. this.status = rs.data.status
  135. console.log(rs)
  136. })
  137. },
  138. posTodayIndex() {
  139. var today = this.getTodayString()
  140. for (var i = 0; i < this.signList.length; i++) {
  141. if (this.signList[i].date === today) {
  142. this.todayIndex = i
  143. break
  144. }
  145. }
  146. },
  147. getTodayString() {
  148. var today = new Date()
  149. var year = today.getFullYear()
  150. var month = String(today.getMonth() + 1).padStart(2, '0') // Months are 0-based
  151. var day = String(today.getDate()).padStart(2, '0')
  152. return year + '-' + month + '-' + day
  153. },
  154. getList() {
  155. getSignList().then(rs => {
  156. this.signList = rs.data
  157. this.posTodayIndex()
  158. })
  159. },
  160. sign(i) {
  161. if (i == this.todayIndex) {
  162. signToday().then(this.getList)
  163. wx.showToast({
  164. title: '签到成功',
  165. icon: 'sucess',
  166. })
  167. }
  168. },
  169. getSafeAreaTop() {
  170. wx.getSystemInfo({
  171. success: res => {
  172. this.safeAreaTop = res.safeArea.top + 'px'
  173. },
  174. })
  175. },
  176. },
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .card {
  181. width: 90%;
  182. background-image: linear-gradient(45deg, #f5eeea 0%, #faab86 100%);
  183. }
  184. </style>