index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.splice(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" 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" @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.splice(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>EOS</em>
  30. </div>
  31. <p class="state" v-if="quantity">已转账到EOS账户</p>
  32. <p class="state-num">
  33. 已领取{{openInfo.num_total - openInfo.num_left}}/{{openInfo.num_total}}.
  34. 共{{formatNum(openInfo.quantity_total - openInfo.quantity_left)}}/{{formatNum(openInfo.quantity_total)}}元
  35. </p>
  36. <ul class="packet-list pub-scroll-box">
  37. <li v-for="(item, key) in openInfo.logs" :key="key">
  38. <img class="avatar" v-if="item.cover_photo" :src="item.cover_photo" alt="">
  39. <div v-else class="avatar no-avatar" :class="'avatar_bg' + item.user_id % 9">
  40. {{item.nick_name.slice(0,2).toUpperCase()}}
  41. </div>
  42. <div class="content">
  43. <div class="top">
  44. <span class="user-name">{{item.nick_name}}</span>
  45. <span class="amount">{{formatNum(item.quantity_int)}} EOS</span>
  46. </div>
  47. <span class="time">{{item.create_time}}</span>
  48. </div>
  49. </li>
  50. </ul>
  51. <p class="tips">未领取的红包,将于24小时后发起退款</p>
  52. </div>
  53. </div>
  54. </transition>
  55. </template>
  56. <script>
  57. import API from '@/api'
  58. import NP from 'number-precision'
  59. import { mapState } from 'vuex'
  60. export default {
  61. name: 'packetGet',
  62. data () {
  63. return {
  64. openInfo: null
  65. }
  66. },
  67. computed: {
  68. ...mapState([
  69. 'userId'
  70. ]),
  71. trxId () {
  72. return this.info.content.trxId
  73. },
  74. quantity () {
  75. if (this.openInfo && this.openInfo.logs.length) {
  76. let arr = this.openInfo.logs
  77. let item = arr.find(v => {
  78. return v.user_id == this.userId
  79. })
  80. if (item) {
  81. return item.quantity_int
  82. } else {
  83. return 0
  84. }
  85. } else {
  86. return 0
  87. }
  88. }
  89. },
  90. methods: {
  91. openPacket () {
  92. API.redpack.grabPacket({
  93. trx_id: this.trxId
  94. }).then(({ data }) => {
  95. this.openInfo = data.data
  96. this.$store.commit('unpdatePacketItem', {
  97. type: 'grabbed',
  98. trxId: this.trxId,
  99. data: 1
  100. })
  101. })
  102. },
  103. showDetail () {
  104. API.redpack.grabDetail({
  105. trx_id: this.trxId
  106. }).then(({ data }) => {
  107. this.openInfo = data.data
  108. })
  109. },
  110. formatNum (num) {
  111. return NP.divide(Number(num), 10000)
  112. }
  113. },
  114. created () {
  115. API.redpack.grabDetail({
  116. trx_id: this.trxId
  117. }).then(({ data }) => {
  118. // 已经领取 并且 红包未过期 打开显示详情页面
  119. if (this.info.ext.grabbed && this.info.ext.status !== 2) {
  120. this.openInfo = data.data
  121. } else if (data.data.quantity_left == 0) {
  122. // 没领取
  123. this.$store.commit('unpdatePacketItem', {
  124. type: 'redpack_status',
  125. trxId: this.trxId,
  126. data: data.data.redpack_status
  127. })
  128. }
  129. this.visible = true
  130. })
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. @import './style.scss';
  136. </style>