index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 class="tip">每日消费满{{ limitPrice }}元达标,连续7天,若期间有一日未达标,则任务重置</div>
  89. </div>
  90. </div>
  91. </div>
  92. </template>
  93. <script>
  94. import { getSignList, signToday, getTaskStat, reveiveTaskReward } from '@/api/task'
  95. export default {
  96. data() {
  97. return {
  98. safeAreaTop: '0px',
  99. signList: [],
  100. todayIndex: -1,
  101. weekdays: ['一', '二', '三', '四', '五', '六', '日'],
  102. currentNum: 0,
  103. totalNum: 0,
  104. couponPrice: 0,
  105. limitPrice: 0,
  106. status: 0,
  107. }
  108. },
  109. created() {
  110. this.getSafeAreaTop()
  111. this.getList()
  112. this.getTaskStat()
  113. },
  114. methods: {
  115. goBack() {
  116. wx.navigateBack({
  117. delta: 1,
  118. })
  119. },
  120. reveiveTaskReward() {
  121. if (this.status == 2) {
  122. return
  123. }
  124. if (this.currentNum < this.totalNum) {
  125. wx.showToast({
  126. title: '未达到领取条件',
  127. icon: 'error',
  128. })
  129. return
  130. }
  131. reveiveTaskReward().then(rs => {
  132. wx.showToast({
  133. title: '领取成功',
  134. icon: 'sucess',
  135. })
  136. this.getTaskStat()
  137. })
  138. },
  139. getTaskStat() {
  140. getTaskStat().then(rs => {
  141. this.currentNum = rs.data.currentNum
  142. this.totalNum = rs.data.totalNum
  143. this.couponPrice = rs.data.couponPrice
  144. this.status = rs.data.status
  145. this.limitPrice = rs.data.limitPrice
  146. console.log(rs)
  147. })
  148. },
  149. posTodayIndex() {
  150. var today = this.getTodayString()
  151. for (var i = 0; i < this.signList.length; i++) {
  152. if (this.signList[i].date === today) {
  153. this.todayIndex = i
  154. break
  155. }
  156. }
  157. },
  158. getTodayString() {
  159. var today = new Date()
  160. var year = today.getFullYear()
  161. var month = String(today.getMonth() + 1).padStart(2, '0') // Months are 0-based
  162. var day = String(today.getDate()).padStart(2, '0')
  163. return year + '-' + month + '-' + day
  164. },
  165. getList() {
  166. getSignList().then(rs => {
  167. this.signList = rs.data
  168. this.posTodayIndex()
  169. })
  170. },
  171. sign(i) {
  172. console.log(this.signList[i].status)
  173. if (i == this.todayIndex && !this.signList[i].status) {
  174. signToday().then(this.getList)
  175. wx.showToast({
  176. title: '签到成功',
  177. icon: 'sucess',
  178. })
  179. }
  180. },
  181. getSafeAreaTop() {
  182. wx.getSystemInfo({
  183. success: res => {
  184. this.safeAreaTop = res.safeArea.top + 'px'
  185. },
  186. })
  187. },
  188. },
  189. }
  190. </script>
  191. <style lang="scss" scoped>
  192. .card {
  193. width: 90%;
  194. background-image: linear-gradient(45deg, #f5eeea 0%, #faab86 100%);
  195. }
  196. .tip {
  197. margin-top: 5px;
  198. // text-align: center;
  199. padding: 0 15px;
  200. color: #969696;
  201. font-size: 12px;
  202. }
  203. </style>