index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <transition name="msgbox-fade">
  3. <div class="pub-modal-mask pub-scroll-box" v-if="visible">
  4. <div class="packet-bg" v-if="!openInfo">
  5. <i class="el-icon-close" @click="visible = false"></i>
  6. <div class="user-info" :class="{'small': info.ext.redpack_status == 1}">
  7. <img class="avatar" v-if="info.avatar" :src="info.avatar" alt="">
  8. <div v-else class="avatar no-avatar" :class="'avatar_bg' + userId % 9">{{info.name.slice(0,2).toUpperCase()}}</div>
  9. <span class="name">{{info.name}}</span>
  10. <div class="text" v-if="info.ext.redpack_status == 0">{{info.content.title}}</div>
  11. </div>
  12. <!-- redpack_status: 0 => 进行中, 1 => 已抢完, 2 => 已过期 -->
  13. <div class="open-btn" :class="{'loading': isLoading}" v-if="info.ext.redpack_status == 0" @click="openPacket">開</div>
  14. <div class="redpack-tips" v-else-if="info.ext.redpack_status == 1">
  15. 手慢了,红包派完了
  16. </div>
  17. <div class="redpack-tips" v-else-if="info.ext.redpack_status == 2">
  18. 该红包已经过期。
  19. </div>
  20. <div class="detail" v-if="userId == info.userId || info.ext.redpack_status == 1" @click="showDetail">查看领取详情</div>
  21. </div>
  22. <div class="detail-bg" v-else>
  23. <i class="el-icon-close" @click="visible = false"></i>
  24. <img class="avatar" v-if="info.avatar" :src="info.avatar" alt="">
  25. <div v-else class="avatar no-avatar" :class="'avatar_bg' + userId % 9">{{info.name.slice(0,2).toUpperCase()}}</div>
  26. <span class="name">{{info.name}}</span>
  27. <div class="text">{{info.content.title}}</div>
  28. <div class="money" v-if="quantity">
  29. {{formatNum(quantity)}} <em>{{openInfo.tokenType}}</em>
  30. </div>
  31. <p class="state" v-if="quantity">已转账到{{openInfo.type.toUpperCase()}}账户</p>
  32. <p class="state-num">
  33. 共 {{openInfo.num_total}} 个,已领取 {{openInfo.num_total - openInfo.num_left}} 个
  34. </p>
  35. <ul class="packet-list pub-scroll-box">
  36. <li v-for="(item, key) in openInfo.logs" :key="key">
  37. <img class="avatar" v-if="item.cover_photo" :src="item.cover_photo" alt="">
  38. <div v-else class="avatar no-avatar" :class="'avatar_bg' + item.user_id % 9">
  39. {{item.nick_name.slice(0,2).toUpperCase()}}
  40. </div>
  41. <div class="content">
  42. <div class="top">
  43. <span class="user-name">{{item.nick_name}}</span>
  44. <span class="amount">{{formatNum(item.quantity_int)}} {{openInfo.tokenType}}</span>
  45. </div>
  46. <span class="time">{{formatTime(item.update_time_int)}}</span>
  47. </div>
  48. </li>
  49. </ul>
  50. <p class="tips">未领取的红包,将于24小时后发起退款</p>
  51. </div>
  52. </div>
  53. </transition>
  54. </template>
  55. <script>
  56. import API from '@/api'
  57. import NP from 'number-precision'
  58. import { mapState } from 'vuex'
  59. import { Message } from 'element-ui'
  60. import dayjs from 'dayjs'
  61. export default {
  62. name: 'packetGet',
  63. data () {
  64. return {
  65. openInfo: null,
  66. isLoading: false
  67. }
  68. },
  69. computed: {
  70. ...mapState([
  71. 'userId',
  72. 'account'
  73. ]),
  74. trxId () {
  75. return this.info.content.trxId
  76. },
  77. quantity () {
  78. if (this.openInfo && this.openInfo.logs.length) {
  79. let arr = this.openInfo.logs
  80. let item = arr.find(v => {
  81. return v.user_id == this.userId
  82. })
  83. if (item) {
  84. return item.quantity_int
  85. } else {
  86. return 0
  87. }
  88. } else {
  89. return 0
  90. }
  91. }
  92. },
  93. methods: {
  94. openPacket () {
  95. this.isLoading = true
  96. API.redpack.grabPacket({
  97. trx_id: this.trxId
  98. }).then(({ data }) => {
  99. // 抢光
  100. if (data.code === -1001) {
  101. this.$store.commit('unpdatePacketItem', {
  102. type: 'redpack_status',
  103. trxId: this.trxId,
  104. data: 1
  105. })
  106. } else {
  107. this.openInfo = data.data
  108. this.$store.commit('unpdatePacketItem', {
  109. type: 'grabbed',
  110. trxId: this.trxId,
  111. data: 1
  112. })
  113. }
  114. }).finally(() => {
  115. this.isLoading = false
  116. })
  117. },
  118. showDetail () {
  119. API.redpack.grabDetail({
  120. trx_id: this.trxId
  121. }).then(({ data }) => {
  122. this.openInfo = data.data
  123. })
  124. },
  125. formatNum (num) {
  126. return NP.divide(Number(num), 10000)
  127. },
  128. formatTime (timestamp) {
  129. return dayjs(timestamp).format('HH:mm')
  130. }
  131. },
  132. created () {
  133. if (this.account) {
  134. API.redpack.grabDetail({
  135. trx_id: this.trxId
  136. }).then(({ data }) => {
  137. // 已经领取
  138. if (this.info.ext.grabbed) {
  139. this.openInfo = data.data
  140. } else if (data.data.num_left == 0) {
  141. // 没领取
  142. this.$store.commit('unpdatePacketItem', {
  143. type: 'redpack_status',
  144. trxId: this.trxId,
  145. data: data.data.redpack_status
  146. })
  147. }
  148. this.visible = true
  149. })
  150. } else {
  151. Message({
  152. message: '请先登录',
  153. type: 'warning'
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. @import './style.scss';
  161. </style>