index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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" v-loading='isLoading'>
  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">{{$t('redPacket.open')}}</div>
  14. <div class="redpack-tips" v-else-if="info.ext.redpack_status == 1">
  15. {{$t('redPacket.noPacketTips')}}
  16. </div>
  17. <div class="redpack-tips" v-else-if="info.ext.redpack_status == 2">
  18. {{$t('redPacket.expiredPacketTips')}}
  19. </div>
  20. <div class="detail" v-if="userId == info.userId || info.ext.redpack_status == 1" @click="showDetail">{{$t('redPacket.seePacketDetail')}}</div>
  21. </div>
  22. <div class="detail-bg" :class="{'is-quantity':quantity}" v-else>
  23. <i class="el-icon-close" @click="visible = false"></i>
  24. <nav class="nav-bar">
  25. <i class="el-icon-arrow-left" @click="visible = false"></i>
  26. <!-- <a class="packet-record">红包记录</a> -->
  27. </nav>
  28. <img class="avatar" v-if="info.avatar" :src="info.avatar" alt="">
  29. <div v-else class="avatar no-avatar" :class="'avatar_bg' + userId % 9">{{info.name.slice(0,2).toUpperCase()}}</div>
  30. <span class="name">{{info.name}}</span>
  31. <div class="text">{{info.content.title}}</div>
  32. <div class="money" v-if="quantity">
  33. {{formatNum(quantity)}} <em>{{openInfo.tokenType}}</em>
  34. </div>
  35. <p class="state" v-if="quantity">{{$t('redPacket.transferTo')}}{{openInfo.type.toUpperCase()}}{{$t('redPacket.account')}}</p>
  36. <p class="state-num">
  37. {{ $t('redPacket.tip4', { total: openInfo.num_total, num: openInfo.num_total - openInfo.num_left, unit: $t('redPacket.unit') }) }}
  38. </p>
  39. <ul class="packet-list pub-scroll-box">
  40. <li v-for="(item, key) in openInfo.logs" :key="key">
  41. <img class="avatar" v-if="item.cover_photo" :src="item.cover_photo" alt="">
  42. <div v-else class="avatar no-avatar" :class="'avatar_bg' + item.user_id % 9">
  43. {{item.nick_name.slice(0,2).toUpperCase()}}
  44. </div>
  45. <div class="content">
  46. <div class="top">
  47. <span class="user-name">{{item.nick_name}}</span>
  48. <span class="amount">{{formatNum(item.quantity_int)}} {{openInfo.tokenType}}</span>
  49. </div>
  50. <div class="bottom">
  51. <span class="time">{{formatTime(item.update_time_int)}}</span>
  52. <span class="best" v-if="item.best"></span>
  53. </div>
  54. </div>
  55. </li>
  56. </ul>
  57. <p class="tips">{{$t('redPacket.tip3')}}</p>
  58. </div>
  59. </div>
  60. </transition>
  61. </template>
  62. <script>
  63. import API from '@/api'
  64. import NP from 'number-precision'
  65. import { mapState } from 'vuex'
  66. import { Message } from 'element-ui'
  67. import { getMeechatType } from '@/util/util'
  68. import dayjs from 'dayjs'
  69. export default {
  70. name: 'packetGet',
  71. data () {
  72. return {
  73. openInfo: null,
  74. isLoading: false,
  75. isHasDetail: false,
  76. meechatType: getMeechatType()
  77. }
  78. },
  79. computed: {
  80. ...mapState([
  81. 'userId',
  82. 'account'
  83. ]),
  84. trxId () {
  85. return this.info.content.trxId
  86. },
  87. quantity () {
  88. if (this.openInfo && this.openInfo.logs.length) {
  89. let arr = this.openInfo.logs
  90. let item = arr.find(v => {
  91. return v.user_id == this.userId
  92. })
  93. if (item) {
  94. return item.quantity_int
  95. } else {
  96. return 0
  97. }
  98. } else {
  99. return 0
  100. }
  101. },
  102. isPrivate () {
  103. return this.$store.getters.isPrivate
  104. }
  105. },
  106. methods: {
  107. openPacket () {
  108. this.isLoading = true
  109. API.redpack.grabPacket({
  110. trx_id: this.trxId
  111. }).then(({ data }) => {
  112. // 抢光
  113. if (data.code === -1001) {
  114. this.$store.commit('unpdatePacketItem', {
  115. type: 'redpack_status',
  116. trxId: this.trxId,
  117. data: 1
  118. })
  119. } else {
  120. this.openInfo = data.data
  121. this.$store.commit('unpdatePacketItem', {
  122. type: 'grabbed',
  123. trxId: this.trxId,
  124. data: 1
  125. })
  126. }
  127. }).finally(() => {
  128. this.isLoading = false
  129. })
  130. },
  131. showDetail () {
  132. API.redpack.grabDetail({
  133. trx_id: this.trxId
  134. }).then(({ data }) => {
  135. this.openInfo = data.data
  136. if (this.meechatType == 'h5') this.initSwipeForH5()
  137. })
  138. },
  139. formatNum (num) {
  140. return NP.divide(Number(num), 10000)
  141. },
  142. formatTime (timestamp) {
  143. return dayjs(timestamp).format('HH:mm')
  144. },
  145. preHandleOpenInfo (openInfo) {
  146. if (openInfo && openInfo.logs.length === openInfo.num_total) {
  147. let best = openInfo.logs[0]
  148. openInfo.logs.forEach(item => {
  149. if (item.quantity_int > best.quantity_int) {
  150. best = item
  151. }
  152. })
  153. best.best = true
  154. }
  155. },
  156. initSwipeForH5 () {
  157. }
  158. },
  159. created () {
  160. if (this.account) {
  161. API.redpack.grabDetail({
  162. trx_id: this.trxId
  163. }).then(({ data }) => {
  164. // 已经领取
  165. if ((this.info.userId == this.userId && this.isPrivate) || this.info.ext.grabbed) {
  166. this.openInfo = data.data
  167. } else if (data.data.num_left == 0) {
  168. // 没领取
  169. this.$store.commit('unpdatePacketItem', {
  170. type: 'redpack_status',
  171. trxId: this.trxId,
  172. data: data.data.redpack_status
  173. })
  174. }
  175. this.visible = true
  176. })
  177. } else {
  178. Message({
  179. message: this.$t('public.loginTip'),
  180. type: 'warning'
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. @import './style.scss';
  188. </style>