welfare.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <layout-page>
  3. <view class="box defaultBgc">
  4. <scroll-view class="scrollBox" scroll-y="true">
  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>
  31. </view>
  32. <!-- 签到 -->
  33. <view class="signIn">
  34. <view class="signIn-content">
  35. <view class="signIn-content-items">
  36. <view class="item" v-for="(sign, i) in SignItems" :key="sign.day">
  37. <view class="box" :class="{ active: i < continuousDay }">
  38. <uni-icons type="vip" size="30" color="#ffbc00" style="text-align: center;"></uni-icons>
  39. <text class="text">+{{ sign.point }}</text>
  40. </view>
  41. <view class="day">
  42. <text>{{ i === todayNumber ? '今' : '第' + sign.day }}天</text>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="tips">
  47. <button
  48. :disabled="todaySignIn"
  49. :class="{ disabled: todaySignIn }"
  50. @tap="handleSignIn"
  51. >
  52. {{ todaySignIn ? '已签到' : '签到'}}
  53. </button>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 积分规则、积分兑换 -->
  58. <view class="ss-m-t-20">
  59. <uni-section title="积分规则" type="line" style="background-color: #fff;">
  60. <uni-list>
  61. <uni-list-item v-for="(k, i) in integralRules" :key="i" :showArrow="false">
  62. <template v-slot:header>
  63. <text class="ss-m-t-10">{{ k.title }}</text>
  64. </template>
  65. <template v-slot:footer>
  66. <view class="d-flex align-center" style="width: 130px; text-align: start; position: relative;">
  67. <image src="/static/svg/integral.svg" style="width: 30px; height: 30px;"></image>
  68. <view class="color-primary ss-m-l-10">{{ k.point }}</view>
  69. <uni-tag :inverted="true" :text="k.complete ? '已完成' : '未完成'" :type="k.complete ? 'success' : 'error'" style="position: absolute; right: 0;" />
  70. </view>
  71. </template>
  72. </uni-list-item>
  73. </uni-list>
  74. </uni-section>
  75. <view class="ss-m-t-20">
  76. <uni-section title="积分兑换" type="line" style="background-color: #fff;">
  77. <view class="goods" >
  78. <view class="goods-item" v-for="(item,index) in goodsList" :key="index" @tap.stop="handleClickGoods">
  79. <image :src="item.url" class="goods-item-img" mode="widthFix"></image>
  80. <view class="goods-item-name">{{ item.name }}</view>
  81. <view>消耗积分<text class="goods-item-price">{{ item.point }}</text></view>
  82. </view>
  83. </view>
  84. </uni-section>
  85. </view>
  86. </view>
  87. </view>
  88. </scroll-view>
  89. </view>
  90. </layout-page>
  91. </template>
  92. <script setup>
  93. import { ref, watch } from 'vue'
  94. import layoutPage from '@/layout'
  95. import {
  96. getRewardSignInConfigList,
  97. getRewardSignInRecordSummary,
  98. createRewardSignInRecord,
  99. getAccountBalance,
  100. getUserAccount,
  101. } from '@/api/sign'
  102. import { getTaskList } from '@/api/integral'
  103. import { onShow } from '@dcloudio/uni-app'
  104. import { userStore } from '@/store/user'
  105. import { showAuthModal } from '@/hooks/useModal'
  106. const useUserStore = userStore()
  107. // 设置自定义tabBar选中值
  108. const SignItems = ref([])
  109. // 积分规则
  110. const integralRules = ref([])
  111. const getTask = async () => {
  112. const { data } = await getTaskList({ mark: '推荐任务', type: 0 })
  113. integralRules.value = data
  114. }
  115. // 商品列表
  116. const goodsList = [
  117. { name: '房券-高端酒店房券', point: 12000, url: 'https://minio.menduner.com/dev/menduner/hotalRoomVoucher.png' },
  118. { name: '门墩儿酒店英语学习年卡', point: 8000, url: 'https://minio.menduner.com/dev/menduner/englishCourses.png' },
  119. { name: '红酒-经典年份葡萄酒', point: 5000, url: 'https://minio.menduner.com/dev/menduner/redWine.png' },
  120. { name: '瑞幸咖啡券-瑞幸咖啡精致享受券', point: 2000, url: 'https://minio.menduner.com/dev/menduner/coffee.png' },
  121. { name: '减压捏捏乐', point: 500, url: 'https://minio.menduner.com/dev/menduner/pinchMusic.png' }
  122. ]
  123. const handleClickGoods = () => {
  124. uni.showToast({
  125. icon: 'none',
  126. title: '请前往网页版门墩儿商城兑换'
  127. })
  128. }
  129. // 连续签到天数
  130. const continuousDay = ref(0)
  131. // 今天有无签到
  132. const todaySignIn = ref(false)
  133. // 今天
  134. const todayNumber = ref()
  135. const balance = ref({})
  136. watch([() => useUserStore.refreshToken, () => useUserStore.isLogin], () => {
  137. if (useUserStore.isLogin) {
  138. getSummary()
  139. getBalance()
  140. }
  141. })
  142. onShow(() => {
  143. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  144. const currentTabBar = currentPage?.getTabBar?.();
  145. // 设置当前tab页的下标index
  146. currentTabBar?.setData({ selected: 2 });
  147. init()
  148. })
  149. function init () {
  150. // 获取签到列表
  151. getSignIn()
  152. // 获取签到信息
  153. getSummary()
  154. // 获取余额积分
  155. getBalance()
  156. // 获取积分规则列表
  157. getTask()
  158. }
  159. // 获取积分余额
  160. async function getBalance() {
  161. const { data } = await getAccountBalance()
  162. const { data: _data } = await getUserAccount()
  163. balance.value = {
  164. ...data,
  165. point: _data.point
  166. }
  167. }
  168. // 获取个人签到统计
  169. async function getSummary() {
  170. const { data } = await getRewardSignInRecordSummary()
  171. if (!data) return
  172. continuousDay.value = data.continuousDay // 连续签到第n天
  173. todaySignIn.value = data.todaySignIn // 今天有无签到
  174. todayNumber.value = todaySignIn.value ? continuousDay.value - 1 : continuousDay.value
  175. }
  176. // 获取签到列表
  177. async function getSignIn () {
  178. try {
  179. const { data } = await getRewardSignInConfigList()
  180. SignItems.value = data
  181. } catch (error) {
  182. }
  183. }
  184. // 签到
  185. async function handleSignIn () {
  186. uni.showLoading({
  187. title: '正在签到'
  188. })
  189. try {
  190. const { code } = await createRewardSignInRecord()
  191. if (code !== 0) {
  192. return
  193. }
  194. setTimeout(async () => {
  195. const { code: _code } = await getSummary()
  196. if (_code !== 0) {
  197. return
  198. }
  199. uni.showToast({
  200. title: '签到成功',
  201. icon: 'success',
  202. mask: true
  203. })
  204. // 更新积分
  205. getBalance()
  206. }, 1000)
  207. } catch (error) {
  208. } finally {
  209. uni.hideLoading()
  210. }
  211. }
  212. function handleLogin () {
  213. if (!useUserStore.isLogin) {
  214. showAuthModal()
  215. return
  216. }
  217. }
  218. function toInfo () {
  219. uni.navigateTo({
  220. url: '/pagesA/info/index'
  221. })
  222. }
  223. function handleTo (page) {
  224. if (!useUserStore.isLogin) {
  225. showAuthModal()
  226. return
  227. }
  228. uni.navigateTo({
  229. url: `/pagesA/${page}/index`
  230. })
  231. }
  232. </script>
  233. <style scoped lang="scss">
  234. .box {
  235. overflow: hidden;
  236. height: 100vh;
  237. padding: 20rpx 0 0 0;
  238. box-sizing: border-box;
  239. .scrollBox{
  240. height: 100%;
  241. padding-bottom: 120rpx;
  242. box-sizing: border-box;
  243. }
  244. .content {
  245. padding-bottom: 24rpx;
  246. box-sizing: border-box;
  247. }
  248. .wallet {
  249. box-sizing: border-box;
  250. height: 200rpx;
  251. margin-bottom: 20rpx;
  252. &-content {
  253. display: flex;
  254. height: 100%;
  255. border-radius: 10rpx;
  256. background: #FFF;
  257. &-member {
  258. width: 50%;
  259. display: flex;
  260. align-items: center;
  261. position: relative;
  262. &:after {
  263. content: '';
  264. position: absolute;
  265. width: 4rpx;
  266. height: 30%;
  267. right: 0;
  268. top: 35%;
  269. background: #00897B;
  270. }
  271. .iconBox {
  272. width: 100rpx;
  273. height: 100%;
  274. display: flex;
  275. align-items: center;
  276. justify-content: center;
  277. &-line {
  278. border: 4rpx solid #ffbc00;
  279. border-radius: 180rpx;
  280. padding: 10rpx;
  281. }
  282. }
  283. .name {
  284. flex: 1;
  285. .actvie {
  286. color: #ffbc00;
  287. }
  288. }
  289. }
  290. &-item {
  291. width: 25%;
  292. display: flex;
  293. flex-direction: column;
  294. align-items: center;
  295. justify-content: center;
  296. .title {
  297. font-size: .85em;
  298. }
  299. }
  300. &-integral {
  301. }
  302. &-cash {
  303. }
  304. }
  305. }
  306. .signIn {
  307. // padding: 0 20rpx;
  308. box-sizing: border-box;
  309. &-content {
  310. border-radius: 10rpx;
  311. background: #FFF;
  312. &-items {
  313. padding: 20rpx 20rpx;
  314. display: flex;
  315. height: 220rpx;
  316. box-sizing: border-box;
  317. .item {
  318. height: 140rpx;
  319. width: 100%;
  320. align-items: center;
  321. justify-content: center;
  322. padding: 0 10rpx;
  323. .box {
  324. height: 100%;
  325. width: 100%;
  326. display: flex;
  327. flex-direction: column;
  328. background: #f2f4f7;
  329. border-radius: 10rpx;
  330. &.active {
  331. color: #fff;
  332. background: rgba(16,137,123, .66);
  333. }
  334. .text {
  335. font-size: .75em;
  336. text-align: center;
  337. }
  338. }
  339. .day {
  340. margin-top: 10rpx;
  341. height: 60rpx;
  342. text-align: center;
  343. font-size: .5em;
  344. }
  345. }
  346. }
  347. .tips {
  348. display: flex;
  349. align-items: center;
  350. justify-content: flex-end;
  351. height: 80rpx;
  352. font-size: .75em;
  353. color: #999;
  354. &-light {
  355. color: #00897B;
  356. padding: 0 10rpx;
  357. }
  358. button {
  359. width: 180rpx;
  360. height: 60rpx;
  361. font-size: 24rpx;
  362. margin: 0 10rpx;
  363. border: unset;
  364. background-color: #00897B;
  365. color: #FFF;
  366. &.disabled {
  367. // background-color: #a7a7a7 !important;
  368. opacity: .5;
  369. }
  370. }
  371. }
  372. }
  373. }
  374. .goods {
  375. padding: 0 15upx;
  376. display: flex;
  377. flex-wrap: wrap;
  378. justify-content: space-between;
  379. &-item {
  380. background: #FFFFFF;
  381. width: 48%;
  382. margin: 10upx 0;
  383. box-sizing: border-box;
  384. &-img {
  385. width: 100%;
  386. height: 250upx;
  387. display: block;
  388. margin: auto;
  389. }
  390. &-price {
  391. padding-top: 10upx;
  392. color: #00897B;
  393. font-size: 32upx;
  394. }
  395. &-name {
  396. width: 100%;
  397. white-space: nowrap;
  398. font-size: 28upx;
  399. line-height: 50upx;
  400. padding-bottom: 10upx;
  401. padding-top: 10upx;
  402. overflow:hidden;
  403. text-overflow:ellipsis;
  404. -webkit-box-orient:vertical;
  405. -webkit-line-clamp:2;
  406. }
  407. }
  408. }
  409. }
  410. :deep(.uni-section .uni-section-header__decoration) {
  411. background-color: #00897B !important;
  412. }
  413. </style>