welfare.vue 12 KB

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