red-packet.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <template>
  2. <div class="content">
  3. <!-- open -->
  4. <div v-if="data.status == 'opened'" class="opened">
  5. <div class="header">
  6. <div class="title">Awesome! You Will Get</div>
  7. <div class="money">
  8. <img :src="require('../assets/svg/icon-dollar.svg')" alt />
  9. <span class="big">{{ data.money / 100 }}</span>
  10. <span class="small">{{ data.detail.amountCurrencyCode || '' }}</span>
  11. </div>
  12. </div>
  13. <div class="list">
  14. <div class="item" v-for="item, i in data.detail.taskCondition" v-bind:key="i">
  15. <template v-if="item.type == 1">
  16. <img :src="require('../assets/svg/icon-follow.svg')" alt />
  17. <div class="item-content">
  18. <div class="item-title">Follow</div>
  19. <span v-for="item2, i in item.relatedUsers" v-bind:key="i">@{{ item2.name }}</span>
  20. </div>
  21. <div class="btn">Follow</div>
  22. </template>
  23. <template v-if="item.type == 2">
  24. <img :src="require('../assets/svg/icon-like.svg')" alt />
  25. <div class="item-content">
  26. <div class="item-title">Like</div>
  27. </div>
  28. <div class="btn">Like</div>
  29. </template>
  30. <template v-if="item.type == 3">
  31. <img :src="require('../assets/svg/icon-retweet.svg')" alt />
  32. <div class="item-content">
  33. <div class="item-title">Retweet</div>
  34. </div>
  35. <div class="btn">Retweet</div>
  36. </template>
  37. </div>
  38. </div>
  39. <div class="people" @click="clickRoad">
  40. <div
  41. class="txt"
  42. >Total ${{ data.detail.amountValue }} USD,{{ data.detail.finishCount || 0 }}/{{ data.detail.totalCount || 0 }} People Got</div>
  43. <div class="right">
  44. <img :src="require('../assets/svg/icon-dollar.svg')" alt />
  45. <img :src="require('../assets/svg/icon-dollar.svg')" alt />
  46. <img :src="require('../assets/svg/icon-dollar.svg')" alt />
  47. <img :src="require('../assets/svg/icon-right.svg')" alt class="road" />
  48. </div>
  49. </div>
  50. <div class="footer">
  51. <div class="first">
  52. <div class="validity">Validity</div>
  53. <div class="time">{{ data.detail.validity || '' }}</div>
  54. </div>
  55. <div class="btn" @click="clickGetGiveways">Get Giveaways</div>
  56. </div>
  57. </div>
  58. <!-- success -->
  59. <div v-else-if="data.status == 'success'" class="success">
  60. <div class="header">
  61. <div class="money">
  62. <img :src="require('../assets/svg/icon-dollar.svg')" alt />
  63. <span class="big">{{ data.money / 100 }}</span>
  64. <span class="small">USD</span>
  65. </div>
  66. </div>
  67. <div class="luck-list-title">
  68. <div>{{ data.detail.finishCount || 0 }}/{{ data.detail.totalCount || 0 }} People Got</div>
  69. <div>Total ${{ data.detail.amountValue || '' }} {{ data.detail.amountCurrencyCode || '' }}</div>
  70. </div>
  71. <div class="luck-list">
  72. <div class="luck-item" v-for="item, i in data.detail.allReceived" v-bind:key="i">
  73. <img :src="item.simpleUserInfoVO.avatarUrl" alt />
  74. <div class="luck-content">
  75. <div class="luck-title">{{ item.simpleUserInfoVO.nickName }}</div>
  76. <div class="luck-time">{{ moment(item.finishTimestamp).format('MM-DD hh:mm:ss') }}</div>
  77. </div>
  78. <div class="luck-money">
  79. <img :src="require('../assets/svg/icon-dollar.svg')" alt />
  80. <div class="luck-money-txt">{{ showLastTwoPlace(item.amountValue) || 0 }}</div>
  81. </div>
  82. <div class="luck-king" v-if="item.isMaxAmount">
  83. <img :src="require('../assets/svg/icon-king-hat.svg')" alt />
  84. <span>Luckiest Draw</span>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. <!-- no-open -->
  90. <div v-else-if="data.status == 'not-open'" class="not-open">
  91. <img :src="require('../assets/img/up.png')" alt class="up" />
  92. <img :src="require('../assets/img/down.png')" alt class="down" />
  93. <div class="open" @click="clickOpenRedPacket">OPEN</div>
  94. </div>
  95. <!-- 领取列表 -->
  96. <div v-else-if="data.status == 'luck-peopel-list'" class="luck-peopel-list">
  97. <div class="head">
  98. <img :src="require('../assets/svg/icon-back.svg')" alt @click="clickBack" />
  99. </div>
  100. <div class="luck-list-title">
  101. <div>{{ data.detail.finishCount || 0 }}/{{ data.detail.totalCount || 0 }} People Got</div>
  102. <div>Total ${{ data.detail.amountValue || 0 }} {{ data.detail.amountCurrencyCode || '' }}</div>
  103. </div>
  104. <div class="luck-list">
  105. <div class="luck-item" v-for="item, i in data.detail.allReceived" v-bind:key="i">
  106. <img :src="item.simpleUserInfoVO.avatarUrl" alt />
  107. <div class="luck-content">
  108. <div class="luck-title">{{ item.simpleUserInfoVO.nickName }}</div>
  109. <div class="luck-time">{{ moment(item.finishTimestamp).format('MM-DD hh:mm:ss') }}</div>
  110. </div>
  111. <div class="luck-money">
  112. <img :src="require('../assets/svg/icon-dollar.svg')" alt />
  113. <div class="luck-money-txt">{{ showLastTwoPlace(item.amountValue) }}</div>
  114. </div>
  115. <div class="luck-king" v-if="item.isMaxAmount">
  116. <img :src="require('../assets/svg/icon-king-hat.svg')" alt />
  117. <span>Luckiest Draw</span>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <!-- 红包被领完了 -->
  123. <div v-else-if="data.status == 'close'" class="close">
  124. <div class="header">
  125. <div class="close-title">{{ data.close_title }}</div>
  126. </div>
  127. <div class="luck-list-title">
  128. <div>{{ data.detail.finishCount || 0 }}/{{ data.detail.totalCount || 0 }} People Got</div>
  129. <div>Total ${{ data.detail.amountValue || 0 }} {{ data.detail.amountCurrencyCode || '' }}</div>
  130. </div>
  131. <div class="luck-list">
  132. <div class="luck-item" v-for="item, i in data.detail.allReceived" v-bind:key="i">
  133. <img :src="item.simpleUserInfoVO.avatarUrl" alt />
  134. <div class="luck-content">
  135. <div class="luck-title">{{ item.simpleUserInfoVO.nickName }}</div>
  136. <div class="luck-time">{{ moment(item.finishTimestamp).format('MM-DD hh:mm:ss') }}</div>
  137. </div>
  138. <div class="luck-money">
  139. <img :src="require('../assets/svg/icon-dollar.svg')" alt />
  140. <div class="luck-money-txt">{{ showLastTwoPlace(item.amountValue) || 0 }}</div>
  141. </div>
  142. <div class="luck-king" v-if="item.isMaxAmount">
  143. <img :src="require('../assets/svg/icon-king-hat.svg')" alt />
  144. <span>Luckiest Draw</span>
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </template>
  151. <script>
  152. export default {
  153. name: 'redPacket',
  154. }
  155. </script>
  156. <script setup>
  157. /* eslint-disable */
  158. import { onMounted, reactive } from "vue";
  159. import { getPostDetail, getRedPacket, finishRedPacket } from '../http/redPacket.js'
  160. import { getQueryString } from '../uilts/help.js'
  161. var moment = require('moment');
  162. let data = reactive({
  163. status: '',
  164. detail: {},
  165. close_title: 'Better luck next time!',
  166. receiveAmount: 0,
  167. money: 0
  168. })
  169. function getValidity() {
  170. let timer = setInterval(() => {
  171. let _time = new Date().getTime()
  172. if (data.detail.endTimestamp - _time > 0) {
  173. data.detail.validity = moment(data.detail.endTimestamp - _time).format('HH:mm:ss')
  174. } else {
  175. clearInterval(timer)
  176. }
  177. }, 1000)
  178. }
  179. function showLastTwoPlace(n) {
  180. return n / 100
  181. // n = n / 100
  182. // let _s = n
  183. // // 如果是整数
  184. // if (Math.floor(n) === n) {
  185. // _s = n + '.00'
  186. // return _s
  187. // }
  188. // // 如果小数只有一位
  189. // if (_s.split('.')[1].length > 2) {
  190. // _s = _s + '0'
  191. // return _s
  192. // }
  193. // return _s
  194. }
  195. function init() {
  196. getPostDetail({
  197. params: {
  198. postId: data.postId
  199. }
  200. }).then((res) => {
  201. switch (res.code.toString()) {
  202. case "0":
  203. // 未开始
  204. if (res.data.postType == 0) {
  205. data.status = 'not-open'
  206. }
  207. // 进行中
  208. if (res.data.postType == 1) {
  209. data.status = 'opened'
  210. data.detail = JSON.parse(res.data.postBizData)
  211. if (data.detail.myReceived) {
  212. data.status = 'opened'
  213. if (data.detail.myReceived.taskFinishStatus == 1) {
  214. data.status = 'success'
  215. }
  216. if (data.detail.myReceived.taskFinishStatus == 2) {
  217. data.status = 'close'
  218. data.close_title = res.msg
  219. }
  220. } else {
  221. data.status = 'not-open'
  222. }
  223. data.detail.taskCondition = JSON.parse(data.detail.taskCondition)
  224. data.detail.amountValue = showLastTwoPlace(data.detail.amountValue)
  225. data.detail.receiveAmountValue = showLastTwoPlace(data.detail.receiveAmountValue)
  226. data.money = data.detail.myReceived.amountValue
  227. console.log(data.detail)
  228. getValidity()
  229. }
  230. // 已结束
  231. if (res.data.postType == 2) {
  232. data.status = 'close'
  233. }
  234. break
  235. }
  236. })
  237. }
  238. onMounted(() => {
  239. data.postId = getQueryString('postId')
  240. init()
  241. })
  242. function clickOpenRedPacket() {
  243. getRedPacket({
  244. params: {
  245. postId: data.postId
  246. }
  247. }).then((res) => {
  248. switch (res.code.toString()) {
  249. case "0":
  250. data.status = 'opened'
  251. data.money = res.data.receiveAmount
  252. break
  253. case "2008":
  254. data.status = 'close'
  255. data.close_title = 'Better luck next time!'
  256. break
  257. }
  258. })
  259. }
  260. function clickGetGiveways() {
  261. finishRedPacket({
  262. params: {
  263. postId: data.postId
  264. }
  265. }).then((res) => {
  266. if (res.code != 0) {
  267. alert(res.msg)
  268. } else {
  269. if (res.data.finished) {
  270. data.status = 'success'
  271. data.receiveAmount = res.data.receiveAmount
  272. init()
  273. } else {
  274. let _data = res.data.conditionResult
  275. for (let i in _data) {
  276. if (!_data[i].finished) {
  277. switch (_data[i].type.toString()) {
  278. case '1':
  279. alert('关注未完成')
  280. break
  281. case '2':
  282. alert('喜欢未完成')
  283. break
  284. case '3':
  285. alert('转推未完成')
  286. break
  287. }
  288. }
  289. }
  290. }
  291. }
  292. })
  293. }
  294. function clickBack() {
  295. data.status = 'opened'
  296. }
  297. function clickRoad() {
  298. data.status = 'luck-peopel-list'
  299. }
  300. </script>
  301. <style lang="scss">
  302. html,
  303. body {
  304. margin: 0;
  305. padding: 0;
  306. }
  307. .content {
  308. width: 375px;
  309. height: 500px;
  310. background: #fafafa;
  311. border-radius: 11px;
  312. font-family: "SF Pro Display";
  313. font-style: normal;
  314. .success,
  315. .close,
  316. .luck-peopel-list {
  317. filter: drop-shadow(0px 4px 94px rgba(0, 0, 0, 0.3));
  318. width: 100%;
  319. height: 100%;
  320. border-radius: 11px;
  321. background: #fff;
  322. .close-title {
  323. font-weight: 600;
  324. font-size: 27px;
  325. line-height: 32px;
  326. text-align: center;
  327. letter-spacing: 0.3px;
  328. color: #ffffff;
  329. }
  330. .head {
  331. padding: 14px 16px;
  332. img {
  333. cursor: pointer;
  334. width: 24px;
  335. height: 24px;
  336. }
  337. }
  338. .header {
  339. text-align: center;
  340. height: 120px;
  341. width: 100%;
  342. background: #ef4545;
  343. padding-top: 30px;
  344. .title {
  345. color: #fff7e4;
  346. opacity: 0.6;
  347. font-weight: 700;
  348. font-size: 18px;
  349. line-height: 21px;
  350. letter-spacing: -0.3px;
  351. }
  352. .money {
  353. img {
  354. width: 40px;
  355. height: 40px;
  356. }
  357. .big {
  358. font-weight: 700;
  359. font-size: 46px;
  360. line-height: 55px;
  361. /* identical to box height */
  362. letter-spacing: 0.3px;
  363. color: #fff8e6;
  364. }
  365. .small {
  366. font-weight: 700;
  367. font-size: 13px;
  368. line-height: 16px;
  369. /* identical to box height */
  370. letter-spacing: 0.5px;
  371. color: #fff8e6;
  372. }
  373. }
  374. }
  375. .luck-list-title {
  376. padding: 0 16px;
  377. background: #fff;
  378. color: #9b9b9b;
  379. display: flex;
  380. justify-content: space-between;
  381. }
  382. .luck-list {
  383. background: #fff;
  384. .luck-item {
  385. display: flex;
  386. padding: 12px 16px;
  387. border-top: 1px solid #d1d1d1;
  388. justify-content: space-between;
  389. position: relative;
  390. img:first-child {
  391. border-radius: 50%;
  392. }
  393. .luck-king {
  394. position: absolute;
  395. top: 36px;
  396. right: 16px;
  397. display: flex;
  398. align-items: center;
  399. img {
  400. width: 22px;
  401. height: 19px;
  402. margin: 0;
  403. }
  404. span {
  405. font-weight: 500;
  406. font-size: 12px;
  407. line-height: 14px;
  408. letter-spacing: 0.3px;
  409. color: #f5b945;
  410. }
  411. }
  412. img {
  413. width: 42px;
  414. height: 42px;
  415. margin-right: 12px;
  416. }
  417. .luck-content {
  418. flex: auto;
  419. .luck-title {
  420. font-weight: 500;
  421. font-size: 16px;
  422. letter-spacing: 0.3px;
  423. color: #444444;
  424. }
  425. .luck-time {
  426. font-weight: 400;
  427. font-size: 12px;
  428. line-height: 14px;
  429. color: #9b9b9b;
  430. }
  431. }
  432. .luck-money {
  433. display: flex;
  434. height: 17px;
  435. align-items: center;
  436. img {
  437. width: 14px;
  438. height: 14px;
  439. margin-right: 6px;
  440. }
  441. .luck-money-txt {
  442. font-weight: 500;
  443. font-size: 14px;
  444. /* identical to box height */
  445. text-align: right;
  446. letter-spacing: 0.3px;
  447. color: #444444;
  448. }
  449. }
  450. }
  451. }
  452. }
  453. .opened {
  454. filter: drop-shadow(0px 4px 94px rgba(0, 0, 0, 0.3));
  455. width: 100%;
  456. height: 100%;
  457. display: flex;
  458. flex-direction: column;
  459. justify-content: space-between;
  460. .header {
  461. text-align: center;
  462. height: 120px;
  463. width: 100%;
  464. background: #ef4545;
  465. padding-top: 30px;
  466. .title {
  467. color: #fff7e4;
  468. opacity: 0.6;
  469. font-weight: 700;
  470. font-size: 18px;
  471. line-height: 21px;
  472. letter-spacing: -0.3px;
  473. }
  474. .money {
  475. img {
  476. width: 40px;
  477. height: 40px;
  478. }
  479. .big {
  480. font-weight: 700;
  481. font-size: 46px;
  482. line-height: 55px;
  483. /* identical to box height */
  484. letter-spacing: 0.3px;
  485. color: #fff8e6;
  486. }
  487. .small {
  488. font-weight: 700;
  489. font-size: 13px;
  490. line-height: 16px;
  491. /* identical to box height */
  492. letter-spacing: 0.5px;
  493. color: #fff8e6;
  494. }
  495. }
  496. }
  497. .list {
  498. padding: 0 16px 0 16px;
  499. background: #ffffff;
  500. flex: 1;
  501. .item {
  502. display: flex;
  503. align-items: center;
  504. min-height: 50px;
  505. border-bottom: 1px solid #f0f0f0;
  506. img {
  507. width: 24px;
  508. height: 24px;
  509. }
  510. .item-content {
  511. flex: 1;
  512. .item-title {
  513. font-weight: 500;
  514. font-size: 16px;
  515. letter-spacing: 0.3px;
  516. color: #000000;
  517. }
  518. span {
  519. font-weight: 400;
  520. font-size: 11px;
  521. line-height: 13px;
  522. letter-spacing: 0.3px;
  523. color: #000000;
  524. opacity: 0.4;
  525. }
  526. }
  527. .btn {
  528. width: 72px;
  529. height: 29px;
  530. line-height: 29px;
  531. background: #389aff;
  532. border-radius: 500px;
  533. text-align: center;
  534. letter-spacing: 0.3px;
  535. color: #ffffff;
  536. cursor: pointer;
  537. }
  538. }
  539. .item:last-child {
  540. border: 0;
  541. }
  542. }
  543. .people {
  544. cursor: pointer;
  545. padding-left: 16px;
  546. height: 44px;
  547. line-height: 44px;
  548. background: #faf9f8;
  549. box-shadow: 0px 1px 0px #f2f2f2;
  550. display: flex;
  551. align-items: center;
  552. justify-content: space-between;
  553. .txt {
  554. font-weight: 400;
  555. font-size: 12px;
  556. line-height: 14px;
  557. letter-spacing: 0.3px;
  558. color: #000000;
  559. opacity: 0.4;
  560. }
  561. .right {
  562. cursor: pointer;
  563. margin-right: 22px;
  564. display: flex;
  565. align-items: center;
  566. img {
  567. width: 22px;
  568. height: 22px;
  569. }
  570. }
  571. }
  572. .footer {
  573. background: #ffffff;
  574. display: flex;
  575. padding: 20px 22px 20px 17px;
  576. .first {
  577. flex: 1;
  578. .validity {
  579. font-weight: 400;
  580. font-size: 12px;
  581. line-height: 14px;
  582. letter-spacing: 0.3px;
  583. color: #000000;
  584. opacity: 0.4;
  585. margin: 2px 0 8px 0;
  586. }
  587. .time {
  588. font-weight: 500;
  589. font-size: 13px;
  590. line-height: 16px;
  591. /* identical to box height */
  592. color: #000000;
  593. }
  594. }
  595. .btn {
  596. background: #ef4545;
  597. border-radius: 100px;
  598. color: #fff;
  599. width: 258px;
  600. height: 52px;
  601. font-weight: 600;
  602. font-size: 18px;
  603. line-height: 52px;
  604. text-align: center;
  605. cursor: pointer;
  606. }
  607. }
  608. }
  609. .not-open {
  610. filter: drop-shadow(0px 4px 94px rgba(0, 0, 0, 0.3));
  611. position: relative;
  612. img {
  613. width: 100%;
  614. }
  615. .up {
  616. position: absolute;
  617. top: 0;
  618. box-shadow: 0px 4px 44px rgba(0, 0, 0, 0.1);
  619. z-index: 1;
  620. }
  621. .down {
  622. position: absolute;
  623. top: 253px;
  624. }
  625. .open {
  626. width: 110px;
  627. height: 110px;
  628. text-align: center;
  629. font-size: 26px;
  630. font-weight: 600;
  631. background: #ffe9b5;
  632. color: #ef4545;
  633. cursor: pointer;
  634. border-radius: 50%;
  635. line-height: 110px;
  636. position: absolute;
  637. top: 235px;
  638. left: 50%;
  639. margin-left: -55px;
  640. z-index: 2;
  641. }
  642. }
  643. }
  644. </style>