index.vue 6.5 KB

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