index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. <div class="bg"></div>
  6. <i class="el-icon-close" @click="visible = false"></i>
  7. <div class="user-info" :class="{'small': info.ext.redpack_status == 1}">
  8. <img class="avatar" v-if="itemUserInfo.cover_photo" :src="itemUserInfo.cover_photo" alt="">
  9. <div v-else class="avatar no-avatar" :class="'avatar_bg' + info.userId % 9">{{itemUserInfo.nick_name && itemUserInfo.nick_name.slice(0,2).toUpperCase()}}</div>
  10. <span class="name">{{itemUserInfo.nick_name}}</span>
  11. <div class="text" v-if="info.ext.redpack_status == 0">{{info.content.title}}</div>
  12. </div>
  13. <!-- redpack_status: 0 => 进行中, 1 => 已抢完, 2 => 已过期 -->
  14. <div class="open-btn" :class="{'loading': isLoading}" v-if="info.ext.redpack_status == 0" @click="openPacket">{{$t('redPacket.open')}}</div>
  15. <div class="redpack-tips" v-else-if="info.ext.redpack_status == 1">
  16. {{$t('redPacket.noPacketTips')}}
  17. </div>
  18. <div class="redpack-tips" v-else-if="info.ext.redpack_status == 2">
  19. {{$t('redPacket.expiredPacketTips')}}
  20. </div>
  21. <div class="detail" v-if="userId == info.userId || info.ext.redpack_status == 1" @click="showDetail">{{$t('redPacket.seePacketDetail')}}</div>
  22. </div>
  23. <div class="detail-bg" :class="{'is-quantity':quantity}" v-else @touchstart="touchstartForH5" @touchend="touchendForH5">
  24. <i class="el-icon-close" @click="visible = false"></i>
  25. <nav class="nav-bar">
  26. <i class="el-icon-arrow-left" @click="visible = false"></i>
  27. <!-- <a class="packet-record">红包记录</a> -->
  28. </nav>
  29. <img class="avatar" v-if="itemUserInfo.cover_photo" :src="itemUserInfo.cover_photo" alt="">
  30. <div v-else class="avatar no-avatar" :class="'avatar_bg' + info.userId % 9">{{itemUserInfo.nick_name && itemUserInfo.nick_name.slice(0,2).toUpperCase()}}</div>
  31. <span class="name">{{itemUserInfo.nick_name}}</span>
  32. <div class="text">{{info.content.title}}</div>
  33. <div class="money" v-if="quantity">
  34. {{formatNum(quantity)}} <em>{{openInfo.tokenType}}</em>
  35. </div>
  36. <p class="state" v-if="quantity">{{$t('redPacket.transferTo')}}</p>
  37. <p class="state-num">
  38. {{ $t('redPacket.tip4', { total: openInfo.num_total, num: openInfo.num_total - openInfo.num_left, unit: $t('redPacket.unit') }) }}
  39. </p>
  40. <ul class="packet-list pub-scroll-box">
  41. <li v-for="(item, key) in openInfo.logs" :key="key">
  42. <img class="avatar" v-if="item.cover_photo" :src="`${item.cover_photo}?imageview/0/w/180`" alt="">
  43. <div v-else class="avatar no-avatar" :class="'avatar_bg' + item.user_id % 9">
  44. {{item.nick_name.slice(0,2).toUpperCase()}}
  45. </div>
  46. <div class="content">
  47. <div class="top">
  48. <span class="user-name">{{item.nick_name}}</span>
  49. <span class="amount">{{formatNum(item.quantity_int)}} {{openInfo.tokenType}}</span>
  50. </div>
  51. <div class="bottom">
  52. <span class="time">{{formatTime(item.update_time_int)}}</span>
  53. <span class="best" v-if="item.best"></span>
  54. </div>
  55. </div>
  56. </li>
  57. </ul>
  58. <p class="tips">{{$t('redPacket.tip3')}}</p>
  59. </div>
  60. </div>
  61. </transition>
  62. </template>
  63. <script>
  64. import API from '@/api'
  65. import NP from 'number-precision'
  66. import { mapState } from 'vuex'
  67. import { Message } from 'element-ui'
  68. import { getMeechatType } from '@/util/util'
  69. import dayjs from 'dayjs'
  70. export default {
  71. name: 'packetGet',
  72. data () {
  73. return {
  74. openInfo: null,
  75. isLoading: false,
  76. isHasDetail: false,
  77. meechatType: getMeechatType(),
  78. startClientX: 0,
  79. itemUserInfo: {}
  80. }
  81. },
  82. computed: {
  83. ...mapState([
  84. 'userId',
  85. 'account',
  86. 'userInfo',
  87. 'group'
  88. ]),
  89. trxId () {
  90. return this.info.content.trxId
  91. },
  92. quantity () {
  93. if (this.openInfo && this.openInfo.logs && this.openInfo.logs.length) {
  94. let arr = this.openInfo.logs
  95. let item = arr.find(v => {
  96. return v.user_id == this.userId
  97. })
  98. return item ? item.quantity_int : 0
  99. } else {
  100. return 0
  101. }
  102. },
  103. isPrivate () {
  104. return this.$store.getters.isPrivate
  105. }
  106. },
  107. methods: {
  108. // 检测是否有领红包权限
  109. checkCanSend () {
  110. let checksSymbol = this.info.content.tokenType.toLowerCase()
  111. // 群聊加群验证
  112. if (!this.isPrivate && !this.group.isJoin) {
  113. Message({
  114. message: this.$t('group.joinTip'),
  115. type: 'error'
  116. })
  117. return false
  118. }
  119. // 绑定验证
  120. let flag = true
  121. if (checksSymbol == 'eos' || checksSymbol == 'meetone' || checksSymbol == 'eth') {
  122. flag = this.userInfo.binds.some((item) => {
  123. return item.type == checksSymbol && item.account
  124. })
  125. if (!flag) {
  126. Message({
  127. message: this.$t('redPacket.bindForEosTips', { 'type': checksSymbol }),
  128. type: 'error'
  129. })
  130. }
  131. }
  132. return flag
  133. },
  134. openPacket () {
  135. if (!this.checkCanSend()) return
  136. this.isLoading = true
  137. API.redpack.grabPacket({
  138. trx_id: this.trxId
  139. }).then(({ data }) => {
  140. // 抢光
  141. if (data.code === -1001) {
  142. this.$store.commit('unpdatePacketItem', {
  143. type: 'redpack_status',
  144. trxId: this.trxId,
  145. data: 1
  146. })
  147. } else {
  148. this.openInfo = data.data
  149. this.$store.commit('unpdatePacketItem', {
  150. type: 'grabbed',
  151. trxId: this.trxId,
  152. data: 1
  153. })
  154. }
  155. }).finally(() => {
  156. this.isLoading = false
  157. })
  158. },
  159. showDetail () {
  160. API.redpack.grabDetail({
  161. trx_id: this.trxId
  162. }).then(({ data }) => {
  163. this.visible = true
  164. this.openInfo = data.data
  165. this.itemUserInfo = this.group.members[data.data.from] || {}
  166. if (this.meechatType == 'h5') this.initSwipeForH5()
  167. })
  168. },
  169. formatNum (num) {
  170. return NP.divide(Number(num), 10000)
  171. },
  172. formatTime (timestamp) {
  173. return dayjs(timestamp).format('HH:mm')
  174. },
  175. preHandleOpenInfo (openInfo) {
  176. if (openInfo && openInfo.logs && openInfo.logs.length === openInfo.num_total) {
  177. let best = openInfo.logs[0]
  178. openInfo.logs.forEach(item => {
  179. if (item.quantity_int > best.quantity_int) {
  180. best = item
  181. }
  182. })
  183. best.best = true
  184. }
  185. },
  186. touchstartForH5 (ev) {
  187. if (this.meechatType != 'h5') return
  188. this.startClientX = ev.changedTouches[0].clientX
  189. },
  190. touchendForH5 (ev) {
  191. if (this.meechatType != 'h5') return
  192. let clientX = ev.changedTouches[0].clientX
  193. if (Math.abs(clientX - this.startClientX) > 60) this.visible = false
  194. }
  195. },
  196. created () {
  197. if (this.isShowDetail) {
  198. this.showDetail()
  199. } else if (this.userId) {
  200. API.redpack.grabDetail({
  201. trx_id: this.trxId
  202. }).then(({ data }) => {
  203. if ((this.info.userId == this.userId && this.isPrivate) || this.info.ext.grabbed) {
  204. // 已经领取
  205. this.openInfo = data.data
  206. } else if (data.data.num_left == 0) {
  207. // 没领取
  208. this.$store.commit('unpdatePacketItem', {
  209. type: 'redpack_status',
  210. trxId: this.trxId,
  211. data: data.data.redpack_status
  212. })
  213. }
  214. this.visible = true
  215. this.itemUserInfo = this.group.members[data.data.from] || {}
  216. })
  217. } else {
  218. Message({
  219. message: this.$t('public.loginTip'),
  220. type: 'warning'
  221. })
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. @import './style.scss';
  228. </style>