gorgelottery.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import Vue from 'vue'
  2. import lib from 'lib'
  3. var host = location.host;
  4. var domain;
  5. var from_uid = lib.getParam("from_uid"),openid = lib.getParam("openid")
  6. if (host.indexOf("127.0.0.1") > -1 || host.indexOf("baichun.duowan.com") > -1) {
  7. // domain = " //yankam.webdev2.duowan.com/";
  8. domain = "//new.mka.duowan.com";
  9. } else if(host.indexOf("test.h5-glance.duowan.com") > -1){
  10. // domain = "//test.mka.duowan.com";
  11. domain = "//new.mka.duowan.com";
  12. } else {
  13. domain = "//mka.duowan.com";
  14. }
  15. class Lottery{
  16. constructor(callback){
  17. this.$lotterys = $('.lottery-item')
  18. this.lottering = false
  19. this.callback = callback
  20. this.scoreRet = null
  21. }
  22. init(){
  23. this.$lotterys.removeClass('active')
  24. this.stop()
  25. }
  26. start(){
  27. let self = this
  28. let len = self.$lotterys.length
  29. self.lottering = true
  30. self.scoreRet = null
  31. self.lotteryIndex = 0
  32. self.lotteryTimer = setInterval(function () {
  33. self.$lotterys.removeClass('active')
  34. let $current = self.$lotterys.filter('[data-order=' + self.lotteryIndex + ']').addClass('active')
  35. let score = $current.attr('data-score')*100
  36. if (self.scoreRet && self.scoreRet.amount == score) {
  37. self.stop()
  38. }
  39. self.lotteryIndex = (self.lotteryIndex + 1) % len
  40. }, 200)
  41. }
  42. stop(){
  43. clearInterval(this.lotteryTimer)
  44. this.lottering = false
  45. this.callback(this.scoreRet)
  46. }
  47. }
  48. export default {
  49. methods: {
  50. startLottery(){
  51. let self = this
  52. if(self.times==0) {
  53. return;
  54. }
  55. if(self.lottery.lottering) {
  56. return;
  57. }
  58. self.lottery.start()
  59. self.gorgeGacha()
  60. },
  61. toggleModGuide(){
  62. this.isShowGuide = this.isShowGuide ? false : true
  63. },
  64. toggleModAward(){
  65. this.isShowAward = this.isShowAward ? false : true
  66. },
  67. toggleModResult(){
  68. this.isShowResult = this.isShowResult ? false : true
  69. },
  70. //中奖滚动
  71. scrollMenu(){
  72. let self = this
  73. let $list = $(".list-menu"),$item = $(".list-menu li"),$scroll=$(".menu-scroll")
  74. let listHeight = $list.height(),listLen = self.bingoList.length
  75. let itemHeight = 56,viewHeight = 336
  76. if(listLen <= 5) {
  77. clearInterval(self.scrollTimer)
  78. return
  79. }
  80. if(viewHeight-self.scrollHeight+10 > listHeight) {
  81. self.scrollHeight = 0;
  82. } else {
  83. self.scrollHeight = self.scrollHeight-itemHeight;
  84. }
  85. },
  86. gorgeLottery(){
  87. let self = this
  88. let url = domain+"/activity/gorgeLottery";
  89. let param = {
  90. from_uid : from_uid,
  91. openid : openid
  92. }
  93. lib.showLoading()
  94. $.ajax({
  95. type: "get",
  96. url: url,
  97. data: param,
  98. dataType: "jsonp",
  99. success: function(ret){
  100. lib.hideLoading()
  101. ret = lib.formatHttpProtocol(ret);
  102. if (ret.code == -5) {
  103. self.wxLogin()
  104. }else if (ret.code == -7) {
  105. location.href = ret.url
  106. } else if (ret.code ==0) {
  107. let data = ret.data
  108. self.bingoList = data.bingoList
  109. self.friendTotal = data.friendTotal
  110. self.friends = data.friends
  111. self.times = data.times
  112. self.userBingo = data.userBingo
  113. self.getLotteryCount = data.getLotteryCount
  114. lib.setWxShare({
  115. title: `邀您参与王者荣耀送英雄活动`,
  116. desc: `帮我增加一次抽奖机会,提高中奖概率`,
  117. link: `${self.shareLink}&from_uid=${data.userId}`,
  118. imgUrl: `//h5-glance.duowan.com/build/gorge.jpg`
  119. });
  120. self.scrollTimer = window.setInterval(()=>{
  121. self.scrollMenu()
  122. },2000)
  123. } else {
  124. lib.showDialog(ret.msg)
  125. }
  126. }
  127. });
  128. },
  129. gorgeGacha(){
  130. let self = this
  131. let url = domain+"/activity/gorgeGacha"
  132. let param = {
  133. }
  134. $.ajax({
  135. type: "get",
  136. url: url,
  137. data: param,
  138. dataType: "jsonp",
  139. success: function(ret){
  140. ret = lib.formatHttpProtocol(ret);
  141. if (ret.code ==0) {
  142. let data = ret.data
  143. --self.times
  144. if(data.amount>0) {
  145. self.gorgeLottery()
  146. }
  147. setTimeout(function () {
  148. self.lottery.scoreRet = data
  149. }, 4000);
  150. } else {
  151. setTimeout(function () {
  152. self.lottery.init();
  153. lib.showDialog(ret.msg)
  154. }, 4000);
  155. }
  156. }
  157. });
  158. },
  159. wxLogin(){
  160. var url = "//mka.duowan.com/login/wxAjax?url="+encodeURIComponent(location.href);
  161. $.ajax({
  162. type : "get",
  163. url : url,
  164. dataType : "jsonp",
  165. success : function(ret){
  166. if (ret.code == 0) {
  167. location.reload();
  168. } else if(ret.code == -7){
  169. location.href = ret.data;
  170. } else {
  171. lib.showTip(ret.msg);
  172. }
  173. }
  174. });
  175. }
  176. },
  177. activated (){
  178. let url = `http://h5game.nbwx.com/act/?page=act-gorgelottery`
  179. if(from_uid) url += `&from_uid=${from_uid}`
  180. if(openid) url += `&openid=${openid}`
  181. location.replace(url)
  182. },
  183. mounted () {
  184. let self = this;
  185. let user_id = lib.getCookie("user_id")
  186. lib.setTitle("王者荣耀英雄抽奖活动")
  187. if(user_id==null) user_id=""
  188. if (lib.checkWXAgent() || 1) {
  189. self.isWx = true
  190. self.gorgeLottery()
  191. self.lottery = new Lottery(function(data){
  192. self.scoreRet = data
  193. self.toggleModResult()
  194. })
  195. } else {
  196. lib.showTip("请在微信端打开活动页面")
  197. }
  198. },
  199. watch: {
  200. },
  201. data() {
  202. return {
  203. downloadUrl : lib.downloadUrl,
  204. bingoList : [],
  205. friendTotal : 0,
  206. friends : [],
  207. times : 0, //抽奖次数
  208. getLotteryCount : 0, //历史邀请抽奖次数
  209. userBingo : [],
  210. isWx: false,
  211. lottery : {}, //抽奖对象
  212. isShowGuide : false,
  213. isShowResult : false,
  214. isShowAward : false,
  215. scoreRet : {}, //抽奖结果
  216. scrollHeight : 0, //中奖滚动
  217. shareLink : `https://${location.host}/?page=act-gorgelottery`
  218. };
  219. }
  220. };
  221. window.Lottery = Lottery