welfare.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <layout-page>
  3. <view class="box defaultBgc">
  4. <scroll-view class="scrollBox" scroll-y="true" @scrolltolower="loadingMore">
  5. <view class="content">
  6. <!-- 钱包 -->
  7. <view class="wallet">
  8. <view class="wallet-content">
  9. <view class="wallet-content-member">
  10. <view class="iconBox">
  11. <view class="iconBox-line">
  12. <uni-icons type="vip-filled" size="40" color="#ffbc00"></uni-icons>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="wallet-content-integral wallet-content-item">
  17. <text>{{ balance.point || 0 }}</text>
  18. <text>积分</text>
  19. </view>
  20. <view class="wallet-content-cash wallet-content-item">
  21. <text>{{ balance.balance > 0 ? (balance?.balance / 100.0).toFixed(2) : 0 }}</text>
  22. <text>余额</text>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 签到 -->
  27. <view class="signIn">
  28. <view class="signIn-content">
  29. <view class="signIn-content-items">
  30. <view class="item" v-for="(sign, i) in SignItems" :key="sign.day">
  31. <view class="box" :class="{ active: i < continuousDay }">
  32. <uni-icons type="vip" size="30" color="#ffbc00" style="text-align: center;"></uni-icons>
  33. <text class="text">+{{ sign.point }}</text>
  34. </view>
  35. <view class="day">
  36. <text>{{ i === todayNumber ? '今' : '第' + sign.day }}天</text>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="tips">
  41. <button
  42. :disabled="todaySignIn"
  43. :class="{ disabled: todaySignIn }"
  44. @tap="handleSignIn"
  45. >
  46. {{ todaySignIn ? '已签到' : '签到'}}
  47. </button>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 福利 -->
  52. <view class="welfare">
  53. <view
  54. v-for="item in items"
  55. :key="item.id"
  56. class="item"
  57. >
  58. <view class="img">
  59. <image
  60. src="/static/img/ticket.png"
  61. mode="scaleToFill"
  62. />
  63. </view>
  64. <text>{{ item.name }}</text>
  65. </view>
  66. </view>
  67. <uni-load-more :status="more" />
  68. </view>
  69. </scroll-view>
  70. </view>
  71. </layout-page>
  72. </template>
  73. <script setup>
  74. import { ref } from 'vue'
  75. import layoutPage from '@/layout'
  76. import {
  77. getRewardSignInConfigList,
  78. getRewardSignInRecordSummary,
  79. createRewardSignInRecord,
  80. getAccountBalance,
  81. getUserAccount,
  82. getDiyTemplateUsed,
  83. getDiyTemplate
  84. } from '@/api/sign'
  85. import { onShow, onLoad } from '@dcloudio/uni-app'
  86. // 设置自定义tabBar选中值
  87. const SignItems = ref([])
  88. // 连续签到天数
  89. const continuousDay = ref(0)
  90. // 今天有无签到
  91. const todaySignIn = ref(false)
  92. // 今天
  93. const todayNumber = ref()
  94. // 加载
  95. const signLoading = ref(false)
  96. const balance = ref({})
  97. const items = ref([])
  98. const more = ref('noMore')
  99. onShow(() => {
  100. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  101. const currentTabBar = currentPage?.getTabBar?.();
  102. // 设置当前tab页的下标index
  103. currentTabBar?.setData({ selected: 2 });
  104. })
  105. onLoad(() => {
  106. // 获取签到列表
  107. getSignIn()
  108. // 获取签到信息
  109. getSummary()
  110. // 获取余额积分
  111. getBalance()
  112. // 获取模板
  113. handleGetTmpUsed()
  114. })
  115. // 获取积分余额
  116. async function getBalance() {
  117. const { data } = await getAccountBalance()
  118. const { data: _data } = await getUserAccount()
  119. balance.value = {
  120. ...data,
  121. point: _data.point
  122. }
  123. }
  124. // 获取个人签到统计
  125. async function getSummary() {
  126. const { data } = await getRewardSignInRecordSummary()
  127. if (!data) return
  128. continuousDay.value = data.continuousDay // 连续签到第n天
  129. todaySignIn.value = data.todaySignIn // 今天有无签到
  130. todayNumber.value = todaySignIn.value ? continuousDay.value - 1 : continuousDay.value
  131. }
  132. // 获取签到列表
  133. async function getSignIn () {
  134. try {
  135. const { data } = await getRewardSignInConfigList()
  136. SignItems.value = data
  137. } catch (error) {
  138. }
  139. }
  140. // 签到
  141. async function handleSignIn () {
  142. if (signLoading.value) {
  143. return
  144. }
  145. try {
  146. signLoading.value = true
  147. await createRewardSignInRecord()
  148. setTimeout(async () => {
  149. await getSummary()
  150. uni.showToast({
  151. title: '签到成功',
  152. icon: 'success',
  153. mask: true
  154. })
  155. // 更新积分
  156. getBalance()
  157. }, 1000)
  158. } catch (error) {
  159. } finally {
  160. signLoading.value = false
  161. }
  162. }
  163. async function handleGetTmpUsed () {
  164. try {
  165. const { data } = await getDiyTemplateUsed()
  166. if (!data?.home?.components) {
  167. uni.showToast({
  168. title: '暂无优惠券',
  169. icon: 'none',
  170. mask: true
  171. })
  172. return
  173. }
  174. const idsItem = data.home.components.find(e => e.id === 'CouponCard')
  175. if (!idsItem) {
  176. uni.showToast({
  177. title: '暂无优惠券',
  178. icon: 'none',
  179. mask: true
  180. })
  181. return
  182. }
  183. const ids = idsItem?.property?.couponIds
  184. if (!ids) {
  185. uni.showToast({
  186. title: '暂无优惠券',
  187. icon: 'none',
  188. mask: true
  189. })
  190. return
  191. }
  192. const { data: _data } = await getDiyTemplate(ids.join(','))
  193. items.value.push(..._data)
  194. more.value = 'noMore'
  195. } catch (error) {
  196. }
  197. }
  198. async function loadingMore () {}
  199. </script>
  200. <style scoped lang="scss">
  201. $px: 20rpx;
  202. .box {
  203. overflow: hidden;
  204. height: 100vh;
  205. padding: $px 0 0 0;
  206. box-sizing: border-box;
  207. .scrollBox{
  208. height: 100%;
  209. padding-bottom: 120rpx;
  210. box-sizing: border-box;
  211. }
  212. .content {
  213. padding-bottom: 24rpx;
  214. box-sizing: border-box;
  215. }
  216. .wallet {
  217. // padding: 0 $px;
  218. box-sizing: border-box;
  219. height: 200rpx;
  220. margin-bottom: 20rpx;
  221. &-content {
  222. display: flex;
  223. height: 100%;
  224. // border: 2rpx solid #E5E5E5;
  225. border-radius: 10rpx;
  226. background: #FFF;
  227. &-member {
  228. width: 50%;
  229. .iconBox {
  230. width: 100%;
  231. height: 100%;
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. &-line {
  236. border: 10rpx solid #ffbc00;
  237. border-radius: 180rpx;
  238. padding: 10rpx;
  239. }
  240. }
  241. }
  242. &-item {
  243. width: 25%;
  244. display: flex;
  245. flex-direction: column;
  246. align-items: center;
  247. justify-content: center;
  248. }
  249. &-integral {
  250. }
  251. &-cash {
  252. }
  253. }
  254. }
  255. .signIn {
  256. // padding: 0 $px;
  257. box-sizing: border-box;
  258. &-content {
  259. border-radius: 10rpx;
  260. background: #FFF;
  261. &-items {
  262. padding: 20rpx $px;
  263. display: flex;
  264. height: 220rpx;
  265. box-sizing: border-box;
  266. .item {
  267. height: 140rpx;
  268. width: 100%;
  269. align-items: center;
  270. justify-content: center;
  271. padding: 0 10rpx;
  272. .box {
  273. height: 100%;
  274. width: 100%;
  275. display: flex;
  276. flex-direction: column;
  277. background: #f2f4f7;
  278. border-radius: 10rpx;
  279. &.active {
  280. background: rgba(16,137,123, .66);
  281. }
  282. .text {
  283. font-size: .75em;
  284. text-align: center;
  285. }
  286. }
  287. .day {
  288. margin-top: 10rpx;
  289. height: 60rpx;
  290. text-align: center;
  291. font-size: .5em;
  292. }
  293. }
  294. }
  295. .tips {
  296. display: flex;
  297. align-items: center;
  298. justify-content: flex-end;
  299. height: 80rpx;
  300. font-size: .75em;
  301. color: #999;
  302. &-light {
  303. color: #00897B;
  304. padding: 0 10rpx;
  305. }
  306. button {
  307. width: 180rpx;
  308. height: 60rpx;
  309. font-size: 24rpx;
  310. margin: 0 10rpx;
  311. border: unset;
  312. background-color: #00897B;
  313. color: #FFF;
  314. &.disabled {
  315. background-color: #a7a7a7 !important;
  316. }
  317. }
  318. }
  319. }
  320. }
  321. .welfare {
  322. display: grid;
  323. grid-template-columns: repeat(2, 1fr);
  324. grid-gap: 20rpx;
  325. padding: 20rpx $px;
  326. .item {
  327. text-align: center;
  328. background: #FFF;
  329. padding: $px;
  330. font-size: .85em;
  331. .img {
  332. image {
  333. width: 128rpx;
  334. height: 128rpx;
  335. }
  336. }
  337. }
  338. }
  339. }
  340. </style>