wzry.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import Vue from 'vue'
  2. import lib from 'lib'
  3. var host = location.host;
  4. var domain;
  5. if (host.indexOf("127.0.0.1") > -1) {
  6. domain = " //yankam.webdev2.duowan.com/";
  7. } else if(host.indexOf("test.h5-glance.duowan.com") > -1){
  8. domain = "//test.mka.duowan.com";
  9. } else {
  10. domain = "//mka.duowan.com";
  11. }
  12. class Lottery{
  13. constructor(callback){
  14. this.$lotterys = $('.lottery-item')
  15. this.lottering = false
  16. this.callback = callback
  17. this.scoreRet = null
  18. }
  19. start(){
  20. let self = this
  21. let len = self.$lotterys.length
  22. self.lottering = true
  23. self.scoreRet = null
  24. self.lotteryIndex = 0
  25. self.lotteryTimer = setInterval(function () {
  26. self.$lotterys.removeClass('active')
  27. let $current = self.$lotterys.filter('[data-order=' + self.lotteryIndex + ']').addClass('active')
  28. let score = $current.attr('data-score')*100
  29. if (self.scoreRet && self.scoreRet.amount == score) {
  30. self.stop()
  31. }
  32. self.lotteryIndex = (self.lotteryIndex + 1) % len
  33. }, 500)
  34. }
  35. stop(){
  36. let self = this
  37. self.lottering = false
  38. clearInterval(self.lotteryTimer)
  39. if(self.scoreRet.amount==0) {
  40. let msg = `<section class="dialog-wzry-lotmsg">
  41. <p>邀请1个好友安装微剧院,可再抽奖一次,邀请越多,中奖机率越高。</p>
  42. </section>`
  43. lib.showDialog(msg,self.callback,"抱歉,你没有中奖","马上邀请好友")
  44. } else {
  45. let msg = `<section class="dialog-wzry-lotmsg">
  46. <ul class="list-process">
  47. <li>
  48. <label>奖品:</label>
  49. <p>获得1Q币</p>
  50. </li>
  51. <li>
  52. <label>领取方式:</label>
  53. <p>关注微信“duowanmall”,回复“领奖”领取</p>
  54. </li>
  55. </ul>
  56. <p>再邀请1个好友安装微剧院,抽588点券!</p>
  57. </section>`
  58. lib.showDialog(msg,self.callback,"恭喜,中奖了","马上邀请好友")
  59. }
  60. }
  61. }
  62. export default {
  63. methods: {
  64. startLottery(){
  65. let self = this
  66. if(self.gachaCount==0) {
  67. return;
  68. }
  69. if(self.lottery.lottering) {
  70. return;
  71. }
  72. self.lottery.start()
  73. self.glanceGacha()
  74. },
  75. showModGuide(){
  76. this.isShowGuide = true
  77. },
  78. closeModGuide(){
  79. this.isShowGuide = false
  80. },
  81. showModAward(){
  82. this.isShowAward = true
  83. },
  84. closeModAward(){
  85. this.isShowAward = false
  86. },
  87. glanceLottery(){
  88. let self = this
  89. let url = domain+"/activity/glanceLottery";
  90. let param = {
  91. _from : location.href
  92. }
  93. $.ajax({
  94. type: "get",
  95. url: url,
  96. data: param,
  97. dataType: "jsonp",
  98. success: function(ret){
  99. ret = lib.formatHttpProtocol(ret);
  100. if (ret.code == -7) {
  101. location.href = ret.url
  102. } else if (ret.code ==0) {
  103. let data = ret.data
  104. self.bingoList = data.bingoList
  105. self.gachaCount = data.gachaCount
  106. self.glanceId = data.glanceId
  107. self.glanceNick = data.glanceNick
  108. self.isLoginedWjy = data.glanceId ? true : false
  109. self.invitedList = data.invitedList
  110. self.userBingo = data.userBingo
  111. if(self.isLoginedWjy) {
  112. self.shareTitle = `${self.glanceNick}邀你来看【微剧院】`
  113. self.shareLink = `//${location.host}/?page=act-invite&uid=${self.glanceId}`
  114. }
  115. } else {
  116. lib.showDialog(ret.msg)
  117. }
  118. lib.setWxShare({
  119. title: self.shareTitle,
  120. desc: `电影解说APP,五分钟呈现电影的精彩。`,
  121. link: self.shareLink,
  122. imgUrl: `//h5-glance.duowan.com/_src/img/icon-logo.png`
  123. });
  124. }
  125. });
  126. },
  127. glanceGacha(){
  128. let self = this
  129. let url = domain+"/activity/glanceGacha"
  130. let param = {
  131. glanceId : self.glanceId
  132. }
  133. $.ajax({
  134. type: "get",
  135. url: url,
  136. data: param,
  137. dataType: "jsonp",
  138. success: function(ret){
  139. ret = lib.formatHttpProtocol(ret);
  140. if (ret.code ==0) {
  141. let data = ret.data
  142. --self.gachaCount
  143. if(data.amount>0) {
  144. self.glanceLottery()
  145. }
  146. setTimeout(function () {
  147. self.lottery.scoreRet = data
  148. }, 4000);
  149. } else {
  150. lib.showDialog(ret.msg)
  151. }
  152. }
  153. });
  154. },
  155. setWxShare(){
  156. let self = this
  157. lib.setWxShare({
  158. title: self.shareTitle,
  159. desc: `电影解说APP,五分钟呈现电影的精彩。`,
  160. link: self.shareLink,
  161. imgUrl: `//h5-glance.duowan.com/_src/img/icon-logo.png`
  162. });
  163. }
  164. },
  165. mounted () {
  166. let self = this;
  167. lib.setTitle("微剧院X王者荣耀活动")
  168. if (lib.checkWXAgent()) {
  169. self.isWx = true
  170. self.glanceLottery()
  171. self.lottery = new Lottery(function(){
  172. self.showModGuide()
  173. })
  174. } else {
  175. lib.showDialog("请在微信端打开活动页面")
  176. }
  177. },
  178. watch: {
  179. },
  180. data() {
  181. return {
  182. downloadUrl : lib.downloadUrl,
  183. bingoList: [],
  184. gachaCount: 0,
  185. glanceId: 0,
  186. invitedList: [],
  187. userBingo: {},
  188. isLoginedWjy: false,
  189. isWx: false,
  190. lottery : {}, //抽奖对象
  191. isShowGuide : false,
  192. isShowGuideAct : false,
  193. isShowAward : false,
  194. shareTitle : "微剧院X王者荣耀活动",
  195. shareLink : `//${location.host}/?page=act-wzry`
  196. };
  197. }
  198. };