推拿小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
6.3 KiB

  1. <template>
  2. <view class="page">
  3. <view class="bg"></view>
  4. <view class="content">
  5. <navbar title="每日签到" leftClick @leftClick="$utils.navigateBack" bgColor="transparent" color="#fff" />
  6. <!-- todo: 对接接口 -->
  7. <view class="flex info">
  8. <view class="flex flex-column info-item">
  9. <view class="info-value">{{ duration }}</view>
  10. <view class="info-label">连续签到/</view>
  11. </view>
  12. <view class="flex flex-column info-item">
  13. <view class="info-value">{{ total }}</view>
  14. <view class="info-label">累计签到/</view>
  15. </view>
  16. <view class="flex flex-column info-item">
  17. <view class="info-value">{{ userCenterData.score }}</view>
  18. <view class="info-label">获得积分</view>
  19. </view>
  20. </view>
  21. <view class="calendars">
  22. <uv-calendars
  23. insert
  24. :showMonth="false"
  25. :selected="signedDates"
  26. :readonly="true"
  27. />
  28. <view class="flex tips">
  29. <image class="tips-icon" src="../static/signIn/icon-tips.png" mode="widthFix"></image>
  30. <text>{{ `签到一次得 ${configList.config_sign_score} 积分` }}</text>
  31. </view>
  32. </view>
  33. <view style="text-align: right;">
  34. <button plain class="flex btn btn-record" @click="$utils.navigateTo('/pages_order/mine/pointsRecord')">
  35. <text>积分明细</text>
  36. <image class="btn-record-icon" src="../static/signIn/icon-arrow.png" mode="widthFix"></image>
  37. </button>
  38. </view>
  39. <view class="tools">
  40. <button plain class="flex btn btn-sign" :class="{ 'is-disabled': isSigned }" @click="onSignIn" :disabled="isSigned">我要签到</button>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import { mapState } from 'vuex'
  47. export default {
  48. data() {
  49. return {
  50. signedDates: [],
  51. total: 0,
  52. duration: 0,
  53. isSigned: false,
  54. }
  55. },
  56. onLoad() {
  57. if (uni.getStorageSync('token')) {
  58. this.$store.commit('getUserCenterInfo')
  59. this.fetchSignedData()
  60. }
  61. },
  62. computed: {
  63. ...mapState(['userCenterData']),
  64. },
  65. methods: {
  66. async fetchSignedData() {
  67. try {
  68. const res = await this.$fetch('queryScoreList')
  69. const { records, total } = res
  70. const today = this.$dayjs()
  71. let todaySigned = false
  72. let duration = 0
  73. let baseDay = today.subtract(1, 'day')
  74. const set = new Set()
  75. const dates = []
  76. records.forEach(item => {
  77. const { createTime } = item
  78. const date = this.$dayjs(createTime)
  79. const dateStr = date.format("YYYY-MM-DD")
  80. if (set.has(dateStr)) {
  81. return
  82. }
  83. set.add(dateStr)
  84. if (!todaySigned && date.isSame(today, 'day')) {
  85. todaySigned = true
  86. }
  87. if (date.isSame(baseDay, 'day')) {
  88. duration++
  89. baseDay = baseDay.subtract(1, 'day')
  90. }
  91. dates.push({
  92. date: date.format("YYYY-MM-DD"),
  93. info: date.date(),
  94. infoColor: '#FFFFFF',
  95. badge: true,
  96. })
  97. })
  98. this.signedDates = dates
  99. this.isSigned = todaySigned
  100. this.isSigned && (duration++)
  101. this.duration = duration
  102. this.total = total
  103. } catch (err) {
  104. }
  105. },
  106. async onSignIn() {
  107. try {
  108. await this.$fetch('sign')
  109. this.$store.commit('getUserCenterInfo')
  110. this.fetchSignedData()
  111. uni.showToast({
  112. title: '签到成功~',
  113. });
  114. } catch (err) {
  115. }
  116. }
  117. },
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .page {
  122. background-color: $uni-bg-color;
  123. position: relative;
  124. /deep/ .uv-calendar {
  125. width: calc(100vw - 14rpx*2);
  126. }
  127. /deep/ .uv-calendar__header {
  128. border: none;
  129. }
  130. /deep/ .uv-calendar__header-btn {
  131. border-color: $uni-color-light;
  132. }
  133. /deep/ .uv-calendar__backtoday,
  134. /deep/ .uv-calendar-item--isDay-text.uv-calendar-item__weeks-lunar-text {
  135. display: none;
  136. }
  137. /deep/ .uv-calendar__weeks-day {
  138. border-color: #E6E6E6;
  139. }
  140. /deep/ .uv-calendar-item__weeks-box-item {
  141. height: 72rpx;
  142. }
  143. /deep/ .uv-calendar-item--isDay {
  144. color: #333 !important;
  145. background-color: transparent !important;
  146. }
  147. /deep/ .uv-calendar-item__weeks-box-circle {
  148. top: 50%;
  149. left: 50%;
  150. width: 53rpx;
  151. height: 53rpx;
  152. transform: translate(-50%, -50%);
  153. border-radius: 50%;
  154. background-color: $uni-color-light;
  155. }
  156. /deep/ .uv-calendar-item__weeks-lunar-text {
  157. position: absolute;
  158. top: 50%;
  159. left: 50%;
  160. transform: translate(-50%, -50%);
  161. font-size: 28rpx;
  162. line-height: 1;
  163. }
  164. }
  165. .bg {
  166. width: 100vw;
  167. height: 550rpx;
  168. background-image: linear-gradient(#84A73F, #D8FF8F);
  169. }
  170. .content {
  171. position: absolute;
  172. left: 0;
  173. top: 0;
  174. }
  175. .info {
  176. margin-top: 102rpx;
  177. width: 100vw;
  178. box-sizing: border-box;
  179. padding: 0 48rpx;
  180. font-size: 0;
  181. justify-content: space-between;
  182. &-item {
  183. color: $uni-text-color-inverse;
  184. }
  185. &-value {
  186. font-size: 46rpx;
  187. }
  188. &-label {
  189. font-size: 26rpx;
  190. margin-top: 19rpx;
  191. }
  192. }
  193. .calendars {
  194. background-color: $uni-fg-color;
  195. margin: 56rpx 14rpx 0 14rpx;
  196. border-radius: 45rpx;
  197. overflow: hidden;
  198. .tips {
  199. padding: 30rpx 30rpx 38rpx 30rpx;
  200. color: $uni-color-light;
  201. justify-content: flex-start;
  202. &-icon {
  203. width: 36rpx;
  204. height: auto;
  205. margin-right: 11rpx;
  206. }
  207. }
  208. }
  209. .tools {
  210. margin-top: 146rpx;
  211. width: 100%;
  212. padding: 0 82rpx;
  213. box-sizing: border-box;
  214. }
  215. .btn {
  216. border: none;
  217. &-record {
  218. margin-top: 19rpx;
  219. margin-right: 28rpx;
  220. display: inline-flex;
  221. color: #999999;
  222. &-icon {
  223. width: 21rpx;
  224. height: auto;
  225. margin-left: 18rpx;
  226. }
  227. }
  228. &-sign {
  229. width: 100%;
  230. padding: 29rpx 0;
  231. color: $uni-text-color-inverse;
  232. font-size: 28rpx;
  233. line-height: 40rpx;
  234. border-radius: 44rpx;
  235. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  236. &.is-disabled {
  237. color: $uni-text-color-inverse;
  238. background: #C7C7C7;
  239. }
  240. }
  241. }
  242. </style>