invite.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <!-- 邀请页 -->
  3. <div class="area-process">
  4. <v-head :left-data="state.detail.postUserInfo || null" :rightData="state.detail.remainAmountUsdValue"></v-head>
  5. <div class="box-process">
  6. <div class="item" v-for="item, i in state.boxs">
  7. <hover-tip :txt="item.txt" v-show="item.show || item.openStatus" :icon="item.hover_icon"></hover-tip>
  8. <img :src="item.icon" alt="" @mouseenter="mouseItem(i)" @mouseleave="mouseLeaveItem(i)" />
  9. <img :src="require('@/assets/img/icon-flash-active.png')" alt="" class="flash"
  10. v-if="item.openStatus == 0 && item.taskFinishStatus == 1" />
  11. </div>
  12. <div class="line">
  13. <div class="full" ref="line_full"></div>
  14. </div>
  15. </div>
  16. <div class="area-success-message" @mouseover="mouseOver" @mouseleave="mouseLeave">
  17. <div class="content-success-message" ref="content_success_message">
  18. <div class="success-message" v-for="item, index in state.success_message_list" :key="index">
  19. <img :src="item.userInfo.avatarUrl" alt="" />
  20. <span>{{ item.userInfo.nickName }} </span> &nbsp;
  21. <span>Opened Treasure Chest</span>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="area-nav">
  27. <div class="item" :class="{ active: state.tab_index == i }" @click="state.tab_index = i"
  28. v-for="item, i in state.tabs">
  29. {{ item.txt }}
  30. </div>
  31. </div>
  32. <div class="area-info">
  33. <invite-friends v-show="state.tab_index == 0"></invite-friends>
  34. <invite-list v-show="state.tab_index == 1"></invite-list>
  35. </div>
  36. <v-dialog v-show="state.dialog.show"></v-dialog>
  37. </template>
  38. <script setup>
  39. import { ref, onMounted, watch, inject } from 'vue'
  40. import { receiveList } from '@/http/treasure.js'
  41. import VHead from '@/view/iframe/treasure-hunt/components/head.vue'
  42. import InviteList from '@/view/iframe/treasure-hunt/components/invite-list.vue'
  43. import HoverTip from '@/view/iframe/treasure-hunt/components/hover-tip.vue'
  44. import InviteFriends from '@/view/iframe/treasure-hunt/components/invite-friends.vue'
  45. import VDialog from '@/view/iframe/treasure-hunt/components/dialog.vue'
  46. let content_success_message = ref(null)
  47. let state = inject('state')
  48. // ---- 走马灯
  49. state.success_message_list = []
  50. // ---- box 区域
  51. let silver_close_box = require('@/assets/img/icon-silver-close-box.png')
  52. let silver_open_box = require('@/assets/img/icon-silver-open-box.png')
  53. let gold_open_box = require('@/assets/img/icon-gold-open-box.png')
  54. let gold_close_box = require('@/assets/img/icon-gold-close-box.png')
  55. // ---- tab区域 ----
  56. state.tab_index = 0
  57. state.tabs = [{
  58. txt: 'invite friends'
  59. }, {
  60. txt: 'invited'
  61. }]
  62. watch(state, () => {
  63. if (content_success_message && content_success_message.value) {
  64. let dom = content_success_message.value
  65. let width = dom.clientWidth
  66. let s = parseInt(width / 80)
  67. dom.style.animationDuration = s + 's'
  68. }
  69. })
  70. state.boxs = []
  71. let line_full = ref(null)
  72. onMounted(() => {
  73. state.inviteInit()
  74. setInterval(() => {
  75. state.init(() => {
  76. state.inviteInit()
  77. })
  78. }, 30000)
  79. })
  80. state.inviteInit = () => {
  81. if (state.detail.inviteCount > 0) {
  82. state.tabs[1].txt = `invited(${state.detail.inviteCount})`
  83. }
  84. state.boxs = []
  85. state.detail.treasureRecords.forEach((item, index) => {
  86. if (item.openStatus == 0) {
  87. item.hover_icon = require('@/assets/svg/icon-user.svg')
  88. if (index > 0) {
  89. item.icon = gold_close_box
  90. } else {
  91. item.icon = silver_close_box
  92. }
  93. item.txt = item.inviteProgress
  94. } else {
  95. item.icon = silver_open_box
  96. item.hover_icon = require('@/assets/svg/icon-green-yes.svg')
  97. // 最后一条
  98. if (index > 0) {
  99. item.icon = gold_open_box
  100. } else {
  101. item.icon = silver_open_box
  102. }
  103. item.txt = '$' + item.amountValue
  104. }
  105. state.boxs.push(item)
  106. })
  107. receiveList({
  108. params: {
  109. postId: state.postId,
  110. pageNum: 1,
  111. pageSize: 10,
  112. }
  113. }).then((res) => {
  114. if (res.code == 0) {
  115. state.success_message_list = res.data
  116. state.success_message_list = state.success_message_list.concat(state.success_message_list)
  117. state.success_message_list = state.success_message_list.concat(state.success_message_list)
  118. }
  119. })
  120. btnStatus()
  121. }
  122. const setLineFull = (box_num = 0, finishNeedInviteCount = 0, successInviteCount = 0) => {
  123. if (box_num == 0) {
  124. line_full.value.style.width = (successInviteCount / finishNeedInviteCount) * 80 + 'px'
  125. } else if (box_num == 1) {
  126. line_full.value.style.width = ((successInviteCount / finishNeedInviteCount) * 100 + 80) + 'px'
  127. } else if (box_num == 2) {
  128. line_full.value.style.width = ((successInviteCount / finishNeedInviteCount) * 100 + 180) + 'px'
  129. }
  130. }
  131. const btnStatus = () => {
  132. for (let i in state.boxs) {
  133. if (state.boxs[i].taskFinishStatus == 0) {
  134. let num = state.boxs[i].finishNeedInviteCount - state.boxs[i].successInviteCount
  135. if (num == 1) {
  136. state.open_btn.txt = 'Invite a friend to open the chest'
  137. } else {
  138. state.open_btn.txt = `Invite ${num} friends to open the chest`
  139. }
  140. state.open_btn.disabled = true
  141. break
  142. }
  143. }
  144. state.treasureId = ''
  145. let open_num = 0
  146. // 有打开的箱子 Open the chest
  147. state.boxs.forEach((item, index) => {
  148. if (item.taskFinishStatus == 1 && item.openStatus == 0) {
  149. state.open_btn.txt = 'Open the Chest'
  150. state.open_btn.disabled = false
  151. if (!state.treasureId) {
  152. state.treasureId = item.id
  153. }
  154. }
  155. if (item.taskFinishStatus == 1) {
  156. setLineFull(index, item.finishNeedInviteCount, item.successInviteCount)
  157. }
  158. // 三个箱子全部打开了
  159. if (item.openStatus == 1) {
  160. open_num++
  161. }
  162. if (open_num == state.boxs.length) {
  163. state.open_btn.txt = 'All Chests are Open'
  164. state.open_btn.disabled = true
  165. }
  166. })
  167. }
  168. const mouseItem = (i) => {
  169. state.boxs[i].show = true
  170. }
  171. const mouseLeaveItem = (i) => {
  172. state.boxs[i].show = false
  173. }
  174. const mouseOver = () => {
  175. if (content_success_message && content_success_message.value && content_success_message.value.style) {
  176. content_success_message.value.style.animationPlayState = 'paused'
  177. }
  178. }
  179. const mouseLeave = () => {
  180. if (content_success_message && content_success_message.value && content_success_message.value.style) {
  181. content_success_message.value.style.animationPlayState = 'running'
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .area-process {
  187. width: 375px;
  188. height: 170px;
  189. background: linear-gradient(179.96deg, #735931 0.04%, #0E0803 53.64%);
  190. position: relative;
  191. .box-process {
  192. width: 350px;
  193. height: 90px;
  194. margin: 0 auto;
  195. display: flex;
  196. align-items: center;
  197. position: absolute;
  198. top: 32px;
  199. left: 13px;
  200. img {
  201. width: 60px;
  202. height: 60px;
  203. z-index: 2;
  204. }
  205. .item {
  206. z-index: 2;
  207. display: flex;
  208. justify-content: center;
  209. position: relative;
  210. .flash {
  211. position: absolute;
  212. top: 0;
  213. left: 0;
  214. z-index: 0;
  215. width: 100%;
  216. height: 100%;
  217. }
  218. }
  219. .item:nth-child(1) {
  220. margin-left: 56px;
  221. }
  222. .item:nth-child(2) {
  223. width: 60px;
  224. height: 60px;
  225. margin-left: 40px;
  226. }
  227. .item:nth-child(3) {
  228. img {
  229. width: 90px;
  230. height: 90px;
  231. }
  232. margin-left: 40px;
  233. }
  234. .line {
  235. width: 300px;
  236. height: 4px;
  237. background: rgba(255, 210, 59, 0.2);
  238. position: absolute;
  239. border-radius: 100px;
  240. overflow: hidden;
  241. left: 13px;
  242. top: 45px;
  243. .full {
  244. position: absolute;
  245. left: 0;
  246. top: 0;
  247. height: 4px;
  248. width: 0px;
  249. background: #FFD23B;
  250. }
  251. }
  252. }
  253. .area-success-message {
  254. height: 30px;
  255. width: 100%;
  256. position: absolute;
  257. bottom: 13px;
  258. overflow: hidden;
  259. .content-success-message {
  260. width: fit-content;
  261. display: flex;
  262. animation: rolling 18s linear infinite;
  263. .success-message {
  264. cursor: default;
  265. width: fit-content;
  266. height: 30px;
  267. padding: 0 9px;
  268. border-radius: 100px;
  269. background: rgba(255, 255, 255, 0.1);
  270. display: flex;
  271. align-items: center;
  272. overflow: hidden;
  273. margin-right: 15px;
  274. img {
  275. width: 20px;
  276. height: 20px;
  277. border-radius: 100px;
  278. margin-right: 8px;
  279. }
  280. span {
  281. font-style: normal;
  282. font-weight: 500;
  283. font-size: 12px;
  284. line-height: 14px;
  285. white-space: nowrap;
  286. }
  287. span:nth-child(2) {
  288. color: #1D9BF0;
  289. }
  290. span:nth-child(3) {
  291. color: #A8A8A8;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. @keyframes rolling {
  298. from {
  299. transform: translateX(0);
  300. }
  301. to {
  302. transform: translateX(-50%);
  303. }
  304. }
  305. .area-nav {
  306. width: 375px;
  307. height: 38px;
  308. display: flex;
  309. .item {
  310. user-select: none;
  311. color: #757575;
  312. background: #F0F0F0;
  313. text-align: center;
  314. width: 50%;
  315. font-weight: 500;
  316. font-size: 14px;
  317. line-height: 38px;
  318. cursor: pointer;
  319. }
  320. .active {
  321. background: #FFFFFF;
  322. color: #000000;
  323. }
  324. }
  325. .area-info {
  326. width: 375px;
  327. }
  328. </style>