receive.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <app-layout>
  3. <view class="receive" :class="[`${theme}-background`]" v-if="loading">
  4. <!-- 分享礼物标题 -->
  5. <view class="share-gift-text">
  6. <share-gift-text
  7. :big="big"
  8. :small="small"
  9. ></share-gift-text>
  10. </view>
  11. <!-- 礼物内容 -->
  12. <view class="page-width receive-content">
  13. <receive-content
  14. :theme="theme"
  15. :big_gift_pic="big_gift_pic"
  16. :small="small"
  17. :status="status"
  18. :is_status="gift_detail.status"
  19. :nickname="gift_detail.list.user.nickname"
  20. :type="gift_detail.list.type"
  21. :name="gift_detail.list.sendOrder[0].detail[0].goods.goodsWarehouse.name"
  22. :num="gift_detail.list.num"
  23. :goods_info="gift_detail.list.sendOrder[0].detail[0].goods_info"
  24. :cover_pic="gift_detail.list.sendOrder[0].detail[0].goods.goodsWarehouse.cover_pic"
  25. :is_big_gift="gift_detail.is_big_gift"
  26. :bless_word="gift_detail.list.bless_word"
  27. :avatar="gift_detail.list.user.userInfo.avatar"
  28. :userOrder="gift_detail.list.userOrder"
  29. :winUser="gift_detail.list.winUser"
  30. :open_type="gift_detail.list.open_type"
  31. :open_status="gift_detail.open_status"
  32. :gift_status="gift_status"
  33. :gift_id="gift_detail.list.id"
  34. :win_time="gift_detail.win_time"
  35. :address_status="gift_detail.address_status"
  36. :win_goods_status="gift_detail.win_goods_status"
  37. :user_id="gift_detail.user_id"
  38. :bless_music="gift_detail.list.bless_music"
  39. :is_play="is_play"
  40. @play="play"
  41. @share="hShareAppMessage"
  42. ></receive-content>
  43. </view>
  44. </view>
  45. </app-layout>
  46. </template>
  47. <script>
  48. import {mapState} from 'vuex';
  49. import shareGiftText from '../components/announcement/share-gift-text.vue';
  50. import receiveContent from '../components/receive/receive-content.vue';
  51. export default {
  52. name: 'receive',
  53. data() {
  54. return {
  55. loading: false,
  56. big: "",
  57. small: "",
  58. status: '',
  59. gift_status: -1,
  60. gift_id: -1,
  61. gift_detail: {
  62. list: {
  63. type: 'direct_open'
  64. }
  65. },
  66. is_play: false,
  67. }
  68. },
  69. onLoad(options) { this.$commonLoad.onload(options);
  70. this.gift_id = options.gift_id;
  71. this.gift_status = options.status;
  72. this.$store.dispatch('gift/getConfig', this.$api.gift.config);
  73. this.request();
  74. // #ifdef MP-ALIPAY || MP-WEIXIN
  75. uni.hideShareMenu();
  76. // #endif
  77. let self = this;
  78. this.innerAudioContext = uni.createInnerAudioContext();
  79. this.innerAudioContext.autoplay = true;
  80. this.innerAudioContext.onEnded(function (res) {
  81. self.is_play = false;
  82. });
  83. // #ifdef H5
  84. this.$shareAppMessage({
  85. path: '/plugins/gift/index/index',
  86. title: this.gift_detail.list.bless_word,
  87. params: {
  88. gift_id: this.gift_id,
  89. },
  90. imageUrl: this.gift_detail.is_big_gift === 0 ? this.gift_detail.list.sendOrder[0].detail[0].goods.goodsWarehouse.cover_pic : this.big_gift_pic,
  91. });
  92. // #endif
  93. },
  94. onHide() {
  95. this.is_play = false;
  96. this.innerAudioContext.stop();
  97. },
  98. // #ifdef MP
  99. onShareAppMessage() {
  100. return this.hShareAppMessage();
  101. },
  102. // #endif
  103. methods: {
  104. hShareAppMessage(s = false) {
  105. return this.$shareAppMessage({
  106. path: '/plugins/gift/index/index',
  107. title: this.gift_detail.list.bless_word,
  108. params: {
  109. gift_id: this.gift_id,
  110. },
  111. // #ifdef MP-ALIPAY
  112. bgImgUrl: this.gift_detail.is_big_gift === 0 ? this.gift_detail.list.sendOrder[0].detail[0].goods.goodsWarehouse.cover_pic : this.big_gift_pic,
  113. // #endif
  114. imageUrl: this.gift_detail.is_big_gift === 0 ? this.gift_detail.list.sendOrder[0].detail[0].goods.goodsWarehouse.cover_pic : this.big_gift_pic,
  115. }, s);
  116. },
  117. async request() {
  118. this.$utils.showLoading();
  119. const res = await this.$request({
  120. url: this.$api.gift.gift,
  121. methods: 'get',
  122. data: {
  123. gift_id: this.gift_id,
  124. }
  125. });
  126. this.$utils.hideLoading();
  127. this.gift_detail = res.data;
  128. if (this.gift_status != 0) {
  129. if (this.gift_detail.list.type === 'num_open') {
  130. if (this.gift_detail.open_status === 0) {
  131. this.big = '参与成功,等待开奖';
  132. this.small = `满${this.gift_detail.list.open_num}人开奖`;
  133. } else {
  134. if (this.gift_detail.status === 0) {
  135. this.big = '很遗憾,你未中奖';
  136. this.status = '未中奖';
  137. } else {
  138. this.big = '恭喜你,中奖了';
  139. this.status = '中奖了';
  140. }
  141. }
  142. } else if (this.gift_detail.list.type === 'time_open') {
  143. if (this.gift_detail.open_status === 0) {
  144. this.big = '参与成功,等待开奖';
  145. let date = new Date(this.gift_detail.list.open_time.replace(/-/g, '/'));
  146. let month = date.getMonth() + 1;
  147. let day = date.getDate();
  148. this.small = `${month > 10 ? month : '0' + month}月${day > 10 ? day : '0' + day}日 ${date.getHours()}:${date.getMinutes() > 10 ? date.getMinutes() : '0' + date.getMinutes()}:00 开奖`;
  149. } else {
  150. if (this.gift_detail.status === 0) {
  151. this.big = '很遗憾,你未中奖';
  152. this.status = '未中奖';
  153. } else {
  154. this.big = '恭喜你,中奖了';
  155. this.status = '中奖了';
  156. }
  157. }
  158. } else if (this.gift_detail.list.type === 'direct_open') {
  159. if (this.gift_detail.status === 1) {
  160. this.big = '礼物领取成功';
  161. this.status = '已领取';
  162. } else {
  163. this.big = '礼物已被抢光';
  164. this.status = '已抢光';
  165. }
  166. }
  167. } else {
  168. this.big = this.gift_detail.win_goods_name;
  169. if (this.gift_detail.list.type === 'time_open') {
  170. let date = new Date(this.gift_detail.list.open_time.replace(/-/g, '/'));
  171. this.small = `${date.getMonth() + 1 > 10 ? date.getMonth() + 1 : '0' + date.getMonth() + 1}月${date.getDate() > 10 ? date.getDate() : '0' + date.getDate()}日 ${date.getHours()}:${date.getMinutes() > 10 ? date.getMinutes() : '0' + date.getMinutes()}:00 开奖`;
  172. }
  173. }
  174. this.loading = true;
  175. },
  176. play(status, bless_music) {
  177. this.is_play = status;
  178. if (status) {
  179. this.innerAudioContext.src = bless_music;
  180. this.innerAudioContext.play();
  181. } else {
  182. this.innerAudioContext.stop();
  183. }
  184. }
  185. },
  186. computed: {
  187. ...mapState('gift', {
  188. theme: state => state.theme,
  189. big_gift_pic: state => state.big_gift_pic,
  190. }),
  191. },
  192. components: {
  193. 'share-gift-text': shareGiftText,
  194. 'receive-content': receiveContent,
  195. }
  196. }
  197. </script>
  198. <style scoped lang="scss">
  199. /* 首页 */
  200. .receive {
  201. position: absolute;
  202. min-height: 100%;
  203. width: 100%;
  204. overflow: auto;
  205. }
  206. </style>