index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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="itemUserInfo.cover_photo" :src="itemUserInfo.cover_photo" alt="">
  8. <div v-else class="avatar no-avatar" :class="'avatar_bg' + info.userId % 9">{{itemUserInfo.nick_name && itemUserInfo.nick_name.slice(0,2).toUpperCase()}}</div>
  9. <span class="name">{{itemUserInfo.nick_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 @touchstart="touchstartForH5" @touchend="touchendForH5">
  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="itemUserInfo.cover_photo" :src="itemUserInfo.cover_photo" alt="">
  29. <div v-else class="avatar no-avatar" :class="'avatar_bg' + info.userId % 9">{{itemUserInfo.nick_name && itemUserInfo.nick_name.slice(0,2).toUpperCase()}}</div>
  30. <span class="name">{{itemUserInfo.nick_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')}}</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. startClientX: 0,
  78. itemUserInfo: {}
  79. }
  80. },
  81. computed: {
  82. ...mapState([
  83. 'userId',
  84. 'account',
  85. 'userInfo',
  86. 'group'
  87. ]),
  88. trxId () {
  89. return this.info.content.trxId
  90. },
  91. quantity () {
  92. if (this.openInfo && this.openInfo.logs && this.openInfo.logs.length) {
  93. let arr = this.openInfo.logs
  94. let item = arr.find(v => {
  95. return v.user_id == this.userId
  96. })
  97. if (item) {
  98. return item.quantity_int
  99. } else {
  100. return 0
  101. }
  102. } else {
  103. return 0
  104. }
  105. },
  106. isPrivate () {
  107. return this.$store.getters.isPrivate
  108. }
  109. },
  110. methods: {
  111. // 检测是否有领红包权限
  112. checkCanSend () {
  113. let checksSymbol = this.info.content.tokenType.toLowerCase()
  114. // 群聊加群验证
  115. if (!this.isPrivate && !this.group.isJoin) {
  116. Message({
  117. message: this.$t('group.joinTip'),
  118. type: 'error'
  119. })
  120. return false
  121. }
  122. // 绑定验证
  123. let flag = true
  124. if (checksSymbol == 'eos' || checksSymbol == 'meetone') {
  125. flag = this.userInfo.binds.some((item) => {
  126. return item.type == checksSymbol && item.account
  127. })
  128. if (!flag) {
  129. Message({
  130. message: this.$t('redPacket.bindForEosTips', { 'type': checksSymbol }),
  131. type: 'error'
  132. })
  133. }
  134. }
  135. return flag
  136. },
  137. openPacket () {
  138. if (!this.checkCanSend()) return
  139. this.isLoading = true
  140. API.redpack.grabPacket({
  141. trx_id: this.trxId
  142. }).then(({ data }) => {
  143. // 抢光
  144. if (data.code === -1001) {
  145. this.$store.commit('unpdatePacketItem', {
  146. type: 'redpack_status',
  147. trxId: this.trxId,
  148. data: 1
  149. })
  150. } else {
  151. this.openInfo = data.data
  152. this.$store.commit('unpdatePacketItem', {
  153. type: 'grabbed',
  154. trxId: this.trxId,
  155. data: 1
  156. })
  157. }
  158. }).finally(() => {
  159. this.isLoading = false
  160. })
  161. },
  162. showDetail () {
  163. API.redpack.grabDetail({
  164. trx_id: this.trxId
  165. }).then(({ data }) => {
  166. this.visible = true
  167. this.openInfo = data.data
  168. this.itemUserInfo = this.group.members[data.data.from] || {}
  169. if (this.meechatType == 'h5') this.initSwipeForH5()
  170. })
  171. },
  172. formatNum (num) {
  173. return NP.divide(Number(num), 10000)
  174. },
  175. formatTime (timestamp) {
  176. return dayjs(timestamp).format('HH:mm')
  177. },
  178. preHandleOpenInfo (openInfo) {
  179. if (openInfo && openInfo.logs && openInfo.logs.length === openInfo.num_total) {
  180. let best = openInfo.logs[0]
  181. openInfo.logs.forEach(item => {
  182. if (item.quantity_int > best.quantity_int) {
  183. best = item
  184. }
  185. })
  186. best.best = true
  187. }
  188. },
  189. touchstartForH5 (ev) {
  190. if (this.meechatType != 'h5') return
  191. this.startClientX = ev.changedTouches[0].clientX
  192. },
  193. touchendForH5 (ev) {
  194. if (this.meechatType != 'h5') return
  195. let clientX = ev.changedTouches[0].clientX
  196. if (Math.abs(clientX - this.startClientX) > 60) this.visible = false
  197. }
  198. },
  199. created () {
  200. if (this.isShowDetail) {
  201. this.showDetail()
  202. } else if (this.userId) {
  203. API.redpack.grabDetail({
  204. trx_id: this.trxId
  205. }).then(({ data }) => {
  206. if ((this.info.userId == this.userId && this.isPrivate) || this.info.ext.grabbed) {
  207. // 已经领取
  208. this.openInfo = data.data
  209. } else if (data.data.num_left == 0) {
  210. // 没领取
  211. this.$store.commit('unpdatePacketItem', {
  212. type: 'redpack_status',
  213. trxId: this.trxId,
  214. data: data.data.redpack_status
  215. })
  216. }
  217. this.visible = true
  218. this.itemUserInfo = this.group.members[data.data.from] || {}
  219. })
  220. } else {
  221. Message({
  222. message: this.$t('public.loginTip'),
  223. type: 'warning'
  224. })
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. @import './style.scss';
  231. </style>