index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <template>
  2. <main-layout>
  3. <template>
  4. <!-- 用户信息区 -->
  5. <view class="user-info">
  6. <view class="user-icon">
  7. <uni-icons type="person" size="30"></uni-icons>
  8. </view>
  9. <span class="nickname" v-if="!userInfo" @click="goUserInfoPage">登录</span>
  10. <span class="user-btn" v-if="userInfo" @click="goUserInfoPage">用户中心</span>
  11. </view>
  12. <!-- 结算 -->
  13. <view class="settle-container">
  14. <!-- 刮刮乐、奖励数相关区域 -->
  15. <view class="left-box">
  16. <view class="split-box">
  17. <view class="line-box">
  18. <span>投入</span>
  19. <span class="number-box">¥{{userInfo.lotteryInvestAmount}}</span>
  20. </view>
  21. <view class="under-line-box">
  22. <span>中奖</span>
  23. <span class="number-box">¥{{userInfo.lotteryWinAmount}}</span>
  24. </view>
  25. </view>
  26. <view class="split-box">
  27. <view class="line-box">
  28. <span>已领取</span>
  29. <span class="number-box">{{userInfo.claimedRewardNum}}</span>
  30. </view>
  31. <view class="under-line-box">
  32. <span>总奖励</span>
  33. <span class="number-box">{{userInfo.totalRewardNum}}</span>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 待领取奖励区 -->
  38. <view class="right-box">
  39. <view class="reward-title">待领取奖励数</view>
  40. <view class="reward-num">{{userInfo.unclaimedRewardNum}}</view>
  41. <view class="reward-btn-group">
  42. <view class="reward-btn-left">全部领取</view>
  43. <view class="reward-btn-right">部分领取</view>
  44. </view>
  45. </view>
  46. <!-- 刷新按钮 -->
  47. <view class="refresh-btn" @click="getUserInfo">
  48. <uni-icons type="refreshempty" color="#406CE7"></uni-icons>
  49. </view>
  50. </view>
  51. <!-- 打卡任务 -->
  52. <view class="task-container">
  53. <view class="task-header">
  54. <view class="task-title" v-if="punchIns.length && punchIns.length > 0">任务({{punchIns.length}}个)
  55. </view>
  56. <view class="task-title" v-else>任务</view>
  57. <view class="task-add-btn" @click="goPunchInEditPage">
  58. <uni-icons type="plusempty" size="30" color="#406CE7"></uni-icons>
  59. </view>
  60. </view>
  61. <view class="task-item" v-for="punchIn in punchIns" :key="punchIn.punchInId">
  62. <view class="main-box" @click="goPunchInDetailPage(punchIn.punchInId)">
  63. <view class="item-header">
  64. <span class="item-title">{{punchIn.taskName}}</span>
  65. <span class="item-reward">x{{punchIn.rewardNum}}</span>
  66. <view class="item-tag" v-if="punchIn.fullAttendanceFlag">全勤奖励</view>
  67. <view class="item-tag" v-if="punchIn.weekendDoubleFlag">周末双倍</view>
  68. </view>
  69. <view class="item-desc">
  70. 规则:{{punchIn.description}}
  71. </view>
  72. <view class="item-detail-list">
  73. <view class="item-detail" v-for="punchInRecord in punchIn.punchInRecords"
  74. :key="punchInRecord.punchInDate">
  75. <view class="detail-text">
  76. <uni-dateformat :date="punchInRecord.punchInDate" format="M/d"></uni-dateformat>
  77. </view>
  78. <view class="detail-box" style="background-color: #E5E5E5;"
  79. v-if="punchInRecord.punchInStatus == 'uncreated'"></view>
  80. <view class="detail-box" style="background-color: #A5D63F;"
  81. v-if="punchInRecord.punchInStatus == 'punchIn'"></view>
  82. <view class="detail-box" style="background-color: #D43030;"
  83. v-if="punchInRecord.punchInStatus == 'unPunchIn'"></view>
  84. <view class="detail-box"
  85. v-if="punchInRecord.punchInStatus == 'futureTime' || punchInRecord.punchInStatus == 'todayUnknown'">
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <view class="func-box" v-if="punchIn.category == 0" @click="doPunchIn(punchIn.punchInId)">
  91. <span>完成</span>
  92. </view>
  93. <view class="func-box" v-if="punchIn.category == 1" @click="doPunchIn(punchIn.punchInId)">
  94. <span>{{punchIn.countTrack}}</span>
  95. <span>计数</span>
  96. </view>
  97. <view class="func-box" v-if="punchIn.category == 2" @click="doPunchIn(punchIn.punchInId)">
  98. <span>
  99. {{punchIn.timeTrack.slice(0, 5)}}
  100. </span>
  101. <span>计时</span>
  102. </view>
  103. </view>
  104. </view>
  105. <!-- 弹出框 -->
  106. <view>
  107. <uni-popup ref="claimRewardDialog" type="dialog">
  108. <uni-popup-dialog ref="inputClose" mode="input" title="领取奖励" value="对话框预置提示内容!" placeholder="请输入领取的奖励数"
  109. @confirm="claimRewardConfirm"></uni-popup-dialog>
  110. </uni-popup>
  111. </view>
  112. </template>
  113. </main-layout>
  114. </template>
  115. <script setup>
  116. import { onMounted, ref } from 'vue';
  117. import { onLoad, onPullDownRefresh, onShow } from "@dcloudio/uni-app";
  118. import { rewardApi, punchInApi, userApi } from '@/service/apis.js';
  119. import router from '@/common/constants/router.js';
  120. /**
  121. * 用户信息
  122. */
  123. const userInfo = ref({
  124. totalRewardNum: 0,
  125. unclaimedRewardNum: 0,
  126. claimedRewardNum: 0,
  127. lotteryInvestAmount: 0.00,
  128. lotteryWinAmount: 0.00
  129. });
  130. /**
  131. * 打卡任务
  132. */
  133. const punchIns = ref([]);
  134. /**
  135. * 获取用户信息
  136. */
  137. const getUserInfo = async () => {
  138. let res = await userApi.queryUserInfo();
  139. userInfo.value = res;
  140. }
  141. /**
  142. * 获取打卡
  143. */
  144. const getPunchIns = async () => {
  145. let res = await punchInApi.queryPunchIns();
  146. punchIns.value = res;
  147. }
  148. /**
  149. * 领取奖励对话框
  150. */
  151. const claimRewardDialog = ref(null);
  152. /**
  153. * 领取奖励
  154. */
  155. const claimReward = () => {
  156. claimRewardDialog.value.open();
  157. }
  158. /**
  159. * 确认领取奖励
  160. */
  161. const claimRewardConfirm = async (val) => {
  162. await rewardApi.claimReward({
  163. "claimRewardNum": val
  164. });
  165. // getReward();
  166. claimRewardDialog.value.close();
  167. }
  168. /**
  169. * 打卡
  170. */
  171. const doPunchIn = async (id) => {
  172. await punchInApi.doPunchIn({
  173. id
  174. });
  175. getPunchIns();
  176. }
  177. /**
  178. * 跳转用户用心
  179. */
  180. const goUserInfoPage = () => {
  181. uni.navigateTo({
  182. url: router.USER_INFO_URL
  183. });
  184. }
  185. /**
  186. * 跳转打卡编辑页面
  187. */
  188. const goPunchInEditPage = () => {
  189. uni.navigateTo({
  190. url: router.PUNCHIN_EDIT_URL
  191. });
  192. };
  193. /**
  194. * 跳转打卡详情页面
  195. */
  196. const goPunchInDetailPage = (id) => {
  197. uni.navigateTo({
  198. url: router.PUNCHIN_DETAIL_URL + "?id=" + id
  199. });
  200. };
  201. /**
  202. * 加载数据
  203. */
  204. const loadData = async () => {
  205. let token = uni.getStorageSync("token");
  206. // 如果还没登录就结束获取数据
  207. console.log(token);
  208. if (!token) {
  209. userInfo.value = ref({
  210. totalRewardNum: 0,
  211. unclaimedRewardNum: 0,
  212. claimedRewardNum: 0,
  213. lotteryInvestAmount: 0.00,
  214. lotteryWinAmount: 0.00
  215. });
  216. punchIns.value = [];
  217. return;
  218. }
  219. console.log("开始啦啦啦");
  220. try {
  221. uni.showLoading({
  222. title: '加载中',
  223. mask: true
  224. });
  225. // 获取用户信息
  226. getUserInfo();
  227. // 获取打卡
  228. getPunchIns();
  229. } finally {
  230. uni.hideLoading();
  231. }
  232. };
  233. onShow(() => {
  234. userInfo.value = uni.getStorageSync("userInfo");
  235. loadData();
  236. });
  237. onPullDownRefresh(() => {
  238. console.log('触发下拉刷星');
  239. loadData();
  240. uni.stopPullDownRefresh();
  241. });
  242. </script>
  243. <style lang="scss" scoped>
  244. .user-info {
  245. display: flex;
  246. align-items: center;
  247. position: relative;
  248. .user-icon {
  249. display: inline-flex !important;
  250. width: 72rpx;
  251. height: 72rpx;
  252. background: #FFFFFF;
  253. border-radius: 50%;
  254. justify-content: center;
  255. align-items: center;
  256. }
  257. .nickname {
  258. margin-left: 16rpx;
  259. font-size: 24rpx;
  260. font-weight: 400;
  261. letter-spacing: 0rpx;
  262. line-height: 34.75rpx;
  263. color: #000000;
  264. }
  265. .user-btn {
  266. position: absolute;
  267. right: 0px;
  268. width: 122rpx;
  269. height: 40rpx;
  270. opacity: 1;
  271. border-radius: 24rpx;
  272. background: #FFFFFF;
  273. border: 1px solid #406CE7;
  274. /** 文本1 */
  275. font-size: 18rpx;
  276. font-weight: 400;
  277. letter-spacing: 0rpx;
  278. line-height: 26.06rpx;
  279. color: #406CE7;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. }
  284. }
  285. .settle-container {
  286. margin-top: 16rpx;
  287. display: flex;
  288. padding: 16rpx 24rpx;
  289. height: 266rpx;
  290. opacity: 1;
  291. background: #406CE7;
  292. border-radius: 21.35rpx;
  293. border: 0.5px solid #E4E4E4;
  294. box-shadow: 0px 1px 6px #D8D8D8;
  295. position: relative;
  296. .left-box {
  297. flex: 1;
  298. display: flex;
  299. flex-direction: column;
  300. border-right: 1px solid #FFFFFF;
  301. padding-right: 24rpx;
  302. font-size: 22rpx;
  303. font-weight: 400;
  304. letter-spacing: 0rpx;
  305. line-height: 31.86rpx;
  306. color: #FFFFFF;
  307. .line-box {
  308. padding-bottom: 16rpx;
  309. border-bottom: 1px solid #FFFFFF;
  310. position: relative;
  311. }
  312. .under-line-box {
  313. padding-top: 16rpx;
  314. position: relative;
  315. }
  316. .number-box {
  317. position: absolute;
  318. right: 0px;
  319. text-align: right;
  320. }
  321. .split-box {
  322. flex: 1;
  323. display: flex;
  324. justify-content: center;
  325. align-content: center;
  326. flex-direction: column;
  327. }
  328. }
  329. .right-box {
  330. flex: 2;
  331. display: flex;
  332. flex-direction: column;
  333. align-items: center;
  334. .reward-title {
  335. font-size: 26rpx;
  336. font-weight: 400;
  337. letter-spacing: 0rpx;
  338. line-height: 37.65rpx;
  339. color: #FFFFFF;
  340. }
  341. .reward-num {
  342. flex-grow: 1;
  343. font-size: 120rpx;
  344. font-weight: 700;
  345. letter-spacing: 0rpx;
  346. color: #FFFFFF;
  347. }
  348. .reward-btn-group {
  349. width: 100%;
  350. height: 36rpx;
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. .reward-btn-left {
  355. display: flex;
  356. justify-content: center;
  357. align-items: center;
  358. width: 108rpx;
  359. height: 36rpx;
  360. opacity: 1;
  361. border-radius: 24rpx 0rpx 0rpx 24rpx;
  362. background: #FFFFFF;
  363. font-size: 20rpx;
  364. font-weight: 700;
  365. letter-spacing: 0rpx;
  366. line-height: 28.96rpx;
  367. color: #406CE7;
  368. }
  369. .reward-btn-right {
  370. margin-left: 5rpx;
  371. display: flex;
  372. justify-content: center;
  373. align-items: center;
  374. width: 108rpx;
  375. height: 36rpx;
  376. opacity: 1;
  377. border-radius: 0rpx 24rpx 24rpx 0rpx;
  378. background: #FFFFFF;
  379. font-size: 20rpx;
  380. font-weight: 700;
  381. letter-spacing: 0rpx;
  382. line-height: 28.96rpx;
  383. color: #406CE7;
  384. }
  385. }
  386. }
  387. .refresh-btn {
  388. position: absolute;
  389. top: 16rpx;
  390. right: 24rpx;
  391. border-radius: 50%;
  392. width: 36rpx;
  393. height: 36rpx;
  394. opacity: 1;
  395. background: #F7F7F7;
  396. display: flex;
  397. justify-content: center;
  398. align-items: center;
  399. }
  400. }
  401. .task-container {
  402. margin-top: 16rpx;
  403. .task-header {
  404. position: relative;
  405. height: 80rpx;
  406. display: flex;
  407. justify-content: center;
  408. /* 水平居中 */
  409. align-items: center;
  410. /* 垂直居中 */
  411. .task-title {
  412. position: absolute;
  413. left: 0rpx;
  414. font-size: 30rpx;
  415. font-weight: 400;
  416. line-height: 43.44rpx;
  417. color: rgba(0, 0, 0, 1);
  418. }
  419. .task-add-btn {
  420. display: inline-flex;
  421. justify-content: center;
  422. align-items: center;
  423. position: absolute;
  424. right: 0rpx;
  425. width: 60rpx;
  426. height: 60rpx;
  427. border-radius: 10rpx;
  428. border: 3px solid rgba(64, 108, 231, 1);
  429. }
  430. }
  431. .task-item {
  432. margin-top: 16rpx;
  433. width: 100%;
  434. // height: 239rpx;
  435. border-radius: 24rpx;
  436. background: #FFFFFF;
  437. border: 0.5px solid #E4E4E4;
  438. box-shadow: 0px 1px 6px #D8D8D8;
  439. display: flex;
  440. .main-box {
  441. flex-grow: 1;
  442. padding: 16rpx 16rpx 16rpx 24rpx;
  443. .item-header {
  444. // position: relative;
  445. display: flex;
  446. align-items: center;
  447. .item-title {
  448. font-size: 30rpx;
  449. font-weight: 400;
  450. letter-spacing: 0rpx;
  451. line-height: 43.44rpx;
  452. color: #000000;
  453. }
  454. .item-reward {
  455. margin-left: 8rpx;
  456. font-size: 24rpx;
  457. font-weight: 400;
  458. letter-spacing: 0rpx;
  459. line-height: 34.75rpx;
  460. color: #000000;
  461. }
  462. .item-tag:first-child {
  463. margin-left: 24rpx;
  464. }
  465. .item-tag {
  466. margin-left: 16rpx;
  467. width: 94rpx;
  468. height: 38rpx;
  469. opacity: 1;
  470. border-radius: 24rpx;
  471. background: #FFFFFF;
  472. border: 1px solid #406CE7;
  473. display: inline-flex;
  474. justify-content: center;
  475. align-items: center;
  476. font-size: 18rpx;
  477. font-weight: 400;
  478. letter-spacing: 0rpx;
  479. // line-height: 26.06rpx;
  480. color: #406CE7;
  481. }
  482. .item-btn {
  483. display: inline-flex;
  484. position: absolute;
  485. right: 0rpx;
  486. width: 123rpx;
  487. height: 42rpx;
  488. border-radius: 30rpx;
  489. border: 1rpx solid #2A82E4;
  490. justify-content: center;
  491. align-items: center;
  492. font-size: 20rpx;
  493. font-weight: 400;
  494. line-height: 28.96px;
  495. color: rgba(64, 108, 231, 1);
  496. }
  497. }
  498. .item-desc {
  499. margin-top: 16rpx;
  500. font-size: 24rpx;
  501. font-weight: 400;
  502. letter-spacing: 0rpx;
  503. line-height: 34.75rpx;
  504. color: #000000;
  505. }
  506. .item-detail-list {
  507. margin-top: 16rpx;
  508. display: grid;
  509. grid-template-columns: repeat(7, 1fr);
  510. .item-detail {
  511. display: flex;
  512. flex-direction: column;
  513. justify-content: center;
  514. align-items: center;
  515. .detail-text {
  516. font-size: 20rpx;
  517. font-weight: 400;
  518. letter-spacing: 0rpx;
  519. line-height: 28.96rpx;
  520. color: rgba(0, 0, 0, 1);
  521. }
  522. .detail-box {
  523. // display: block;
  524. width: 42rpx;
  525. height: 42rpx;
  526. margin-top: 5rpx;
  527. border: 5rpx solid #000000;
  528. }
  529. }
  530. }
  531. }
  532. .func-box {
  533. flex-shrink: 0;
  534. width: 160rpx;
  535. border-radius: 0rpx 24rpx 24rpx 0rpx;
  536. background: #406CE7;
  537. font-size: 36rpx;
  538. font-weight: 400;
  539. letter-spacing: 0rpx;
  540. line-height: 52.13rpx;
  541. color: #FFFFFF;
  542. display: flex;
  543. justify-content: center;
  544. align-items: center;
  545. flex-direction: column;
  546. }
  547. }
  548. }
  549. </style>