uplottory.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import Vue from 'vue'
  2. import lib from 'lib'
  3. import ext from 'extSdk'
  4. import _ from 'underscore'
  5. let uid = lib.getParam("uid")
  6. let token = lib.getParam("token")
  7. let upId = lib.getParam("upId")
  8. class scrollCode {
  9. constructor(code){
  10. this.type = [
  11. [0,1,2,3,4,5,6,7,8,9],
  12. ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],
  13. ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
  14. ]
  15. this.code = code
  16. this.codeArr = []
  17. this.typeArr = []
  18. this.init()
  19. }
  20. init(){
  21. let self = this
  22. _.each(this.code,(key)=>{
  23. self.typeArr.push(self.cheakCharacter(key))
  24. })
  25. }
  26. cheakCharacter(key){
  27. let reg1 = /\d/
  28. let reg2 = /[a-z]/
  29. let reg3 = /[A-Z]/
  30. let obj = {}
  31. let self = this
  32. if(reg1.test(key)) return 0
  33. if(reg2.test(key)) return 1
  34. if(reg3.test(key)) return 2
  35. }
  36. getRandomCharacter(index){
  37. let self = this
  38. let len = self.type[index].length
  39. let random = Math.floor(Math.random() * len)
  40. return self.type[index][random]
  41. }
  42. getRandomCode(){
  43. let self = this
  44. let arr = []
  45. _.each(this.typeArr,(type)=>{
  46. arr.push(self.getRandomCharacter(type))
  47. })
  48. return arr.join("")
  49. }
  50. }
  51. export default {
  52. methods: {
  53. getLotteryInfo(){
  54. let self = this
  55. let url = `${lib.upAdminDomain}/act/lotteryInfo`;
  56. let param = {
  57. uid : uid,
  58. upId : upId,
  59. token : token
  60. }
  61. $.ajax({
  62. type: "get",
  63. url: url,
  64. data: param,
  65. dataType: "jsonp",
  66. success: (ret) => {
  67. ret = lib.formatHttpProtocol(ret);
  68. if(ret.code==0) {
  69. let data = ret.data
  70. self.bingoUsers = data.bingoUsers
  71. self.reward = data.reward
  72. self.userRecord = data.reward.userRecord
  73. self.lotteryStatus = data.reward.lotteryStatus
  74. self.upInfo = data.upInfo
  75. self.lottoryId = data.reward.id
  76. lib.setTitle(`${data.upInfo.name}的抽奖池`)
  77. self.scrollTimer = window.setInterval(()=>{
  78. self.scrollMenu()
  79. },2000)
  80. self.initLottoryTip()
  81. if(data.reward.lotteryStatus==3) {
  82. self.scrollCodeObj = new scrollCode(data.reward.userRecord.code)
  83. self.changeCode()
  84. }
  85. } else {
  86. lib.showTip(ret.msg);
  87. }
  88. }
  89. });
  90. },
  91. doLottery(){
  92. let self = this
  93. let url = `${lib.upAdminDomain}/act/doLottery`;
  94. let param = {
  95. uid : uid,
  96. token : token,
  97. id : self.lottoryId
  98. }
  99. let msg = `参与成功,今日抽奖将在${self.reward.rewardHour}:00开奖,为避免您错过开奖消息,建议您开启消息栏通知提醒。`
  100. $.ajax({
  101. type: "get",
  102. url: url,
  103. data: param,
  104. dataType: "jsonp",
  105. success: (ret)=>{
  106. ret = lib.formatHttpProtocol(ret)
  107. if(ret.code==0) {
  108. self.getLotteryInfo()
  109. setTimeout(()=>{
  110. ext.openNotificationSettingIfNeeded(msg)
  111. },800)
  112. } else {
  113. lib.showTip(ret.msg)
  114. }
  115. }
  116. });
  117. },
  118. initLottoryTip(){
  119. let self = this
  120. let duration = ""
  121. //1未开始,2进行中,3,待开奖,4已结束,5没中奖,6中奖
  122. switch(self.lotteryStatus) {
  123. case 1 :
  124. duration = self.getDuration(1)
  125. self.lottoryTip = `距离抽奖还有 ${duration}`
  126. break;
  127. case 2 :
  128. self.lottoryTip = `今天抽奖剩余1次抽奖`
  129. break;
  130. case 3 :
  131. duration = self.getDuration(3)
  132. self.lottoryTip = `距离开奖还有 ${duration}`
  133. break;
  134. case 4 :
  135. case 5 :
  136. case 6 :
  137. duration = self.getDuration(4)
  138. self.lottoryTip = `距离下次抽奖还有 ${duration}`
  139. break;
  140. }
  141. },
  142. getDuration(type){ //1未开始,3,待开奖,4已结束
  143. let self = this,duration
  144. let now = new Date()
  145. let todayStartTime = self.reward.dayStart*1000
  146. let todayRewardTime = self.reward.dayReward*1000
  147. let TomorrowStartTime = todayStartTime+24*60*60*1000
  148. let nowTime = now.getTime()
  149. switch(type) {
  150. case 1 :
  151. duration = self.handldTime(todayStartTime-nowTime)
  152. break;
  153. case 3 :
  154. duration = self.handldTime(todayRewardTime-nowTime)
  155. break;
  156. case 4 :
  157. duration = self.handldTime(TomorrowStartTime-nowTime)
  158. break;
  159. }
  160. return duration
  161. },
  162. handldTime(restTime) {
  163. restTime = restTime / 1000
  164. let hour = Math.floor(restTime%(60*60*24)/(60*60))
  165. let min = Math.floor(restTime%(60*60*24)%(60*60)/(60))
  166. if(hour>0) {
  167. return hour+" 小时 "+min+" 分钟"
  168. } else {
  169. return min+" 分钟"
  170. }
  171. },
  172. parseNum(num){
  173. return (num >= 10 ? num : "0"+num)
  174. },
  175. changeCode(){
  176. let self = this
  177. let timeLen = 800,timeInterval=50,timeStart=0
  178. let timer = window.setInterval(()=>{
  179. timeStart += timeInterval
  180. self.scrollCode = self.scrollCodeObj.getRandomCode()
  181. if(timeStart>=timeLen) {
  182. self.scrollCode = self.userRecord.code
  183. clearInterval(timer)
  184. }
  185. },timeInterval)
  186. },
  187. //中奖滚动
  188. scrollMenu(){
  189. let self = this
  190. let $list = $(".list-menu"),$item = $(".list-menu li"),$scroll=$(".menu-scroll")
  191. let listHeight = $list.height(),listLen = self.bingoUsers.length
  192. let itemHeight = listHeight / listLen
  193. let viewHeight = $scroll.height()
  194. if(listLen <= 5) {
  195. clearInterval(self.scrollTimer)
  196. return
  197. }
  198. if(viewHeight-self.scrollHeight+10 > listHeight) {
  199. self.scrollHeight = 0;
  200. } else {
  201. self.scrollHeight = self.scrollHeight-itemHeight;
  202. }
  203. }
  204. },
  205. mounted () {
  206. let self = this
  207. self.getLotteryInfo()
  208. },
  209. watch: {
  210. },
  211. data() {
  212. return {
  213. scrollHeight : 0,
  214. scrollTimer : {},
  215. bingoUsers : [], //中奖名单
  216. reward : {}, //奖品
  217. upInfo : {}, //up主信息
  218. userRecord : {},
  219. lotteryStatus : 2, //1未开始,2进行中,3,待开奖,4已结束,5没中奖,6中奖
  220. lottoryTip : "",
  221. lottoryId : 0,
  222. scrollCode : '--------',
  223. scrollCodeObj : {}//滚动数字对象
  224. };
  225. },
  226. filters : {
  227. cutTime(value){
  228. return value ? value.substring(0,11) : ""
  229. }
  230. }
  231. };