welfare.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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="20" color="#ffbc00"></uni-icons>
  13. </view>
  14. </view>
  15. <view class="name">
  16. <text v-if="useUserStore.isLogin" @tap="toInfo" class="active">
  17. {{ useUserStore?.baseInfo?.name || useUserStore?.userInfo?.phone }}
  18. </text>
  19. <text v-else @tap="handleLogin">点击登录</text>
  20. </view>
  21. </view>
  22. <view class="wallet-content-integral wallet-content-item" @tap="handleTo('integral')">
  23. <text>{{ balance.point || 0 }}</text>
  24. <text class="title">积分</text>
  25. </view>
  26. <view class="wallet-content-cash wallet-content-item" @tap="handleTo('balance')">
  27. <text>{{ balance.balance > 0 ? (balance?.balance / 100.0).toFixed(2) : 0 }}</text>
  28. <text class="title">余额</text>
  29. </view>
  30. <view class="wallet-content-coupon wallet-content-item" @tap="handleTo('coupon')">
  31. <text>{{ myCoupon }}</text>
  32. <text class="title">优惠券</text>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 签到 -->
  37. <view class="signIn">
  38. <view class="signIn-content">
  39. <view class="signIn-content-items">
  40. <view class="item" v-for="(sign, i) in SignItems" :key="sign.day">
  41. <view class="box" :class="{ active: i < continuousDay }">
  42. <uni-icons type="vip" size="30" color="#ffbc00" style="text-align: center;"></uni-icons>
  43. <text class="text">+{{ sign.point }}</text>
  44. </view>
  45. <view class="day">
  46. <text>{{ i === todayNumber ? '今' : '第' + sign.day }}天</text>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="tips">
  51. <button
  52. :disabled="todaySignIn"
  53. :class="{ disabled: todaySignIn }"
  54. @tap="handleSignIn"
  55. >
  56. {{ todaySignIn ? '已签到' : '签到'}}
  57. </button>
  58. </view>
  59. </view>
  60. </view>
  61. <!-- 福利 -->
  62. <view class="welfare">
  63. <view
  64. v-for="item in items"
  65. :key="item.id"
  66. class="item"
  67. :class="{ disabled: !item.canTake }"
  68. @tap="onGetCoupon(item.id, item.canTake)"
  69. >
  70. <view class="img">
  71. <image
  72. src="/static/img/ticket.png"
  73. mode="scaleToFill"
  74. />
  75. </view>
  76. <text>{{ item.name }}</text>
  77. </view>
  78. </view>
  79. <uni-load-more :status="more" />
  80. </view>
  81. </scroll-view>
  82. </view>
  83. </layout-page>
  84. </template>
  85. <script setup>
  86. import { ref, watch } from 'vue'
  87. import layoutPage from '@/layout'
  88. import {
  89. getRewardSignInConfigList,
  90. getRewardSignInRecordSummary,
  91. createRewardSignInRecord,
  92. getAccountBalance,
  93. getUserAccount,
  94. getDiyTemplateUsed,
  95. getDiyTemplate,
  96. getCouponTemplatePage,
  97. takeCoupon,
  98. getCouponPage
  99. } from '@/api/sign'
  100. import { onShow, onLoad } from '@dcloudio/uni-app'
  101. import { userStore } from '@/store/user'
  102. import { showAuthModal } from '@/hooks/useModal'
  103. const useUserStore = userStore()
  104. // 设置自定义tabBar选中值
  105. const SignItems = ref([])
  106. // 连续签到天数
  107. const continuousDay = ref(0)
  108. // 今天有无签到
  109. const todaySignIn = ref(false)
  110. // 今天
  111. const todayNumber = ref()
  112. const balance = ref({})
  113. const pageInfo = ref({
  114. pageNo: 1,
  115. pageSize: 20
  116. })
  117. const total = ref(0)
  118. const items = ref([])
  119. const more = ref('more')
  120. const myCoupon = ref(0)
  121. // watch(() => useUserStore.isLogin, () => {
  122. // if (useUserStore.isLogin) {
  123. // init()
  124. // }
  125. // })
  126. watch([() => useUserStore.refreshToken, () => useUserStore.isLogin], () => {
  127. if (useUserStore.isLogin) {
  128. getMyCoupon()
  129. initCoupon()
  130. getSummary()
  131. getBalance()
  132. }
  133. })
  134. onShow(() => {
  135. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  136. const currentTabBar = currentPage?.getTabBar?.();
  137. // 设置当前tab页的下标index
  138. currentTabBar?.setData({ selected: 2 });
  139. init()
  140. })
  141. function init () {
  142. // 获取签到列表
  143. getSignIn()
  144. // 获取签到信息
  145. getSummary()
  146. // 获取余额积分
  147. getBalance()
  148. // 获取优惠券列表
  149. initCoupon()
  150. // 获取我的优惠券总数
  151. getMyCoupon()
  152. }
  153. // 获取积分余额
  154. async function getBalance() {
  155. const { data } = await getAccountBalance()
  156. const { data: _data } = await getUserAccount()
  157. balance.value = {
  158. ...data,
  159. point: _data.point
  160. }
  161. }
  162. // 获取个人签到统计
  163. async function getSummary() {
  164. const { data } = await getRewardSignInRecordSummary()
  165. if (!data) return
  166. continuousDay.value = data.continuousDay // 连续签到第n天
  167. todaySignIn.value = data.todaySignIn // 今天有无签到
  168. todayNumber.value = todaySignIn.value ? continuousDay.value - 1 : continuousDay.value
  169. }
  170. // 获取签到列表
  171. async function getSignIn () {
  172. try {
  173. const { data } = await getRewardSignInConfigList()
  174. SignItems.value = data
  175. } catch (error) {
  176. }
  177. }
  178. // 签到
  179. async function handleSignIn () {
  180. uni.showLoading({
  181. title: '正在签到'
  182. })
  183. try {
  184. const { code } = await createRewardSignInRecord()
  185. if (code !== 0) {
  186. return
  187. }
  188. setTimeout(async () => {
  189. const { code: _code } = await getSummary()
  190. if (_code !== 0) {
  191. return
  192. }
  193. uni.showToast({
  194. title: '签到成功',
  195. icon: 'success',
  196. mask: true
  197. })
  198. // 更新积分
  199. getBalance()
  200. }, 1000)
  201. } catch (error) {
  202. } finally {
  203. uni.hideLoading()
  204. }
  205. }
  206. // 获取优惠券分页
  207. async function getAllCouponPage () {
  208. try {
  209. const { data } = await getCouponTemplatePage({ ...pageInfo.value })
  210. // console.log(data)
  211. if (!data || !data.list || !data.list.length) {
  212. if (pageInfo.value.pageNo === 1) {
  213. more.value = 'more'
  214. return
  215. }
  216. pageInfo.value.pageNo--
  217. more.value = 'more'
  218. return
  219. }
  220. items.value.push(...data.list)
  221. total.value = +data.total
  222. more.value = total.value === items.value.length ? 'noMore' : 'more'
  223. } catch (error) {
  224. if (pageInfo.value.pageNo === 1) {
  225. more.value = 'more'
  226. return
  227. }
  228. pageInfo.value.pageNo--
  229. more.value = 'more'
  230. }
  231. }
  232. async function getMyCoupon () {
  233. const { data } = await getCouponPage({ pageNo:1, pageSize: 1, status: 1 })
  234. if (data) {
  235. myCoupon.value = +data.total
  236. }
  237. }
  238. // 优惠券列表
  239. // async function handleGetTmpUsed () {
  240. // try {
  241. // const { data } = await getDiyTemplateUsed()
  242. // if (!data?.home?.components) {
  243. // uni.showToast({
  244. // title: '暂无优惠券',
  245. // icon: 'none',
  246. // mask: true
  247. // })
  248. // return
  249. // }
  250. // const idsItem = data.home.components.find(e => e.id === 'CouponCard')
  251. // if (!idsItem) {
  252. // uni.showToast({
  253. // title: '暂无优惠券',
  254. // icon: 'none',
  255. // mask: true
  256. // })
  257. // return
  258. // }
  259. // const ids = idsItem?.property?.couponIds
  260. // if (!ids) {
  261. // uni.showToast({
  262. // title: '暂无优惠券',
  263. // icon: 'none',
  264. // mask: true
  265. // })
  266. // return
  267. // }
  268. // const { data: _data } = await getDiyTemplate(ids.join(','))
  269. // items.value = _data
  270. // more.value = 'noMore'
  271. // } catch (error) {
  272. // }
  273. // }
  274. async function loadingMore () {
  275. if (more.value === 'noMore') {
  276. return
  277. }
  278. more.value = 'loading'
  279. pageInfo.value.pageNo++
  280. getAllCouponPage()
  281. }
  282. function initCoupon () {
  283. pageInfo.value.pageNo = 1
  284. items.value = []
  285. getAllCouponPage()
  286. }
  287. function handleLogin () {
  288. if (!useUserStore.isLogin) {
  289. showAuthModal()
  290. return
  291. }
  292. }
  293. function toInfo () {
  294. uni.navigateTo({
  295. url: '/pagesA/info/index'
  296. })
  297. }
  298. async function onGetCoupon(id, canTake) {
  299. if (!canTake) {
  300. return
  301. }
  302. uni.showLoading({
  303. title: '领取中'
  304. })
  305. try {
  306. const {
  307. code,
  308. msg
  309. } = await takeCoupon(id)
  310. if (code !== 0) {
  311. uni.showToast({
  312. title: msg,
  313. icon: 'none'
  314. })
  315. return
  316. }
  317. uni.showToast({
  318. title: '领取成功',
  319. icon: 'success'
  320. })
  321. getMyCoupon()
  322. initCoupon()
  323. } catch (error) {
  324. } finally {
  325. uni.hideLoading()
  326. }
  327. }
  328. function handleTo (page) {
  329. if (!useUserStore.isLogin) {
  330. showAuthModal()
  331. return
  332. }
  333. uni.navigateTo({
  334. url: `/pagesA/${page}/index`
  335. })
  336. }
  337. </script>
  338. <style scoped lang="scss">
  339. $px: 20rpx;
  340. .box {
  341. overflow: hidden;
  342. height: 100vh;
  343. padding: $px 0 0 0;
  344. box-sizing: border-box;
  345. .scrollBox{
  346. height: 100%;
  347. padding-bottom: 120rpx;
  348. box-sizing: border-box;
  349. }
  350. .content {
  351. padding-bottom: 24rpx;
  352. box-sizing: border-box;
  353. }
  354. .wallet {
  355. // padding: 0 $px;
  356. box-sizing: border-box;
  357. height: 200rpx;
  358. margin-bottom: 20rpx;
  359. &-content {
  360. display: flex;
  361. height: 100%;
  362. // border: 2rpx solid #E5E5E5;
  363. border-radius: 10rpx;
  364. background: #FFF;
  365. &-member {
  366. width: 50%;
  367. display: flex;
  368. align-items: center;
  369. position: relative;
  370. &:after {
  371. content: '';
  372. position: absolute;
  373. width: 4rpx;
  374. height: 30%;
  375. right: 0;
  376. top: 35%;
  377. background: #00897B;
  378. }
  379. .iconBox {
  380. width: 100rpx;
  381. height: 100%;
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. &-line {
  386. border: 4rpx solid #ffbc00;
  387. border-radius: 180rpx;
  388. padding: 10rpx;
  389. }
  390. }
  391. .name {
  392. flex: 1;
  393. .actvie {
  394. color: #ffbc00;
  395. }
  396. }
  397. }
  398. &-item {
  399. width: 16.6%;
  400. display: flex;
  401. flex-direction: column;
  402. align-items: center;
  403. justify-content: center;
  404. .title {
  405. font-size: .85em;
  406. }
  407. }
  408. &-integral {
  409. }
  410. &-cash {
  411. }
  412. }
  413. }
  414. .signIn {
  415. // padding: 0 $px;
  416. box-sizing: border-box;
  417. &-content {
  418. border-radius: 10rpx;
  419. background: #FFF;
  420. &-items {
  421. padding: 20rpx $px;
  422. display: flex;
  423. height: 220rpx;
  424. box-sizing: border-box;
  425. .item {
  426. height: 140rpx;
  427. width: 100%;
  428. align-items: center;
  429. justify-content: center;
  430. padding: 0 10rpx;
  431. .box {
  432. height: 100%;
  433. width: 100%;
  434. display: flex;
  435. flex-direction: column;
  436. background: #f2f4f7;
  437. border-radius: 10rpx;
  438. &.active {
  439. background: rgba(16,137,123, .66);
  440. }
  441. .text {
  442. font-size: .75em;
  443. text-align: center;
  444. }
  445. }
  446. .day {
  447. margin-top: 10rpx;
  448. height: 60rpx;
  449. text-align: center;
  450. font-size: .5em;
  451. }
  452. }
  453. }
  454. .tips {
  455. display: flex;
  456. align-items: center;
  457. justify-content: flex-end;
  458. height: 80rpx;
  459. font-size: .75em;
  460. color: #999;
  461. &-light {
  462. color: #00897B;
  463. padding: 0 10rpx;
  464. }
  465. button {
  466. width: 180rpx;
  467. height: 60rpx;
  468. font-size: 24rpx;
  469. margin: 0 10rpx;
  470. border: unset;
  471. background-color: #00897B;
  472. color: #FFF;
  473. &.disabled {
  474. background-color: #a7a7a7 !important;
  475. }
  476. }
  477. }
  478. }
  479. }
  480. .welfare {
  481. display: grid;
  482. grid-template-columns: repeat(2, 1fr);
  483. grid-gap: 20rpx;
  484. padding: 20rpx $px;
  485. .item {
  486. text-align: center;
  487. background: #FFF;
  488. padding: $px;
  489. font-size: .85em;
  490. &.disabled {
  491. position: relative;
  492. &::after {
  493. content: '已领取';
  494. display: flex;
  495. align-items: center;
  496. justify-content: center;
  497. position: absolute;
  498. top: 0;
  499. left: 0;
  500. width: 100%;
  501. height: 100%;
  502. background: rgba(255,255,255,.75);
  503. }
  504. }
  505. .img {
  506. image {
  507. width: 128rpx;
  508. height: 128rpx;
  509. }
  510. }
  511. }
  512. }
  513. }
  514. </style>