index.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. prizeId:'', //填写地址,奖品id
  6. wheelId:'',//大转盘id
  7. winThePrize:{},//中奖奖品信息
  8. PrizeList:[],
  9. winPrizeList:[],
  10. tablePageInfo:{},
  11. tableSize:'',
  12. awardsList:[],
  13. pageIndex:1,
  14. runDegs:0,
  15. animationData:{},
  16. showAwardPopup:false, //奖品详情弹窗
  17. showRulesPopup:false, // 活动规则
  18. showPrizePopup:false, //中奖弹窗
  19. showtableStatus:false, //转盘状态
  20. showAddress:false, //地址弹窗
  21. prizeInfo:{}, //奖品详情页
  22. shareTitle:'',
  23. theam:'redContent', //redContent --0 blueContent --1 greenContent --2
  24. scrollTop:0,
  25. scrollIndex:'view0',
  26. timer:''//定时器
  27. },
  28. onLoad: function (options) {
  29. console.log('options',options)
  30. if (!util.isEmpty(options.id)) {
  31. this.setData({wheelId:options.id})
  32. }
  33. // 通过二维码进入
  34. if (!util.isEmpty(options.scene)) {
  35. console.log('scene',options.scene)
  36. this.setData({wheelId:options.scene})
  37. }
  38. this.setData({
  39. tableSize: wx.getSystemInfoSync().windowWidth - 40
  40. })
  41. },
  42. onReady: function () {
  43. },
  44. onShow: function () {
  45. this.getTableView()
  46. },
  47. // 再来一次
  48. tryAgain(){
  49. this.setData({
  50. showPrizePopup:false
  51. })
  52. setTimeout(() => {
  53. this.getPrize()
  54. }, 500);
  55. },
  56. // 填写地址
  57. inputAddress(e){
  58. this.setData({
  59. showPrizePopup:false,
  60. showAddress:true,
  61. prizeId:e.detail.id
  62. })
  63. },
  64. // 获取更多机会
  65. getMoreChange(){
  66. this.setData({showtableStatus:false})
  67. wx.navigateTo({
  68. url: '/pages/turntable/getPrizeTimes/index?wheelId='+this.data.wheelId+'&theam='+this.data.theam,
  69. })
  70. },
  71. // 获取分享标题
  72. getShareTitle(){
  73. let that=this;
  74. util.ajax({
  75. func: "v2/market/wheel/info",
  76. data: {wheelId:this.data.wheelId}
  77. }, function (res) {
  78. if (res.code==0) {
  79. that.setData({
  80. shareTitle:res.data.shareTitle
  81. })
  82. } else {
  83. util.showTips(res.reason)
  84. }
  85. })
  86. },
  87. // 滚动条滚动
  88. scrollTopBar(){
  89. let timer = setInterval(() => {
  90. let viewNum=this.data.scrollIndex.slice(4);
  91. this.setData({scrollIndex:parseInt(viewNum)>=this.data.winPrizeList.length-1?('view0'):('view'+(parseInt(viewNum)+2))})
  92. }, 2000);
  93. this.setData({timer})
  94. },
  95. // 获取大转盘页面显示信息
  96. getTableView(){
  97. let id = this.data.wheelId,that=this;
  98. util.ajax({
  99. func: "v2/market/wheel/index",
  100. data: {wheelId:id}
  101. }, function (res) {
  102. if (res.code==0) {
  103. that.setData({
  104. tablePageInfo:res.data,
  105. theam:that.selectTheme(res.data.theme)
  106. })
  107. that.initialization();
  108. that.getPrizeList();
  109. that.getWinprizeList();
  110. that.getShareTitle()
  111. } else {
  112. util.showTips(res.reason);
  113. }
  114. })
  115. },
  116. // 判定标题
  117. selectTheme(theme){
  118. let str=''
  119. switch (theme) {
  120. case 0:
  121. str='redContent'
  122. break;
  123. case 1:
  124. str='blueContent'
  125. break;
  126. case 2:
  127. str='greenContent'
  128. break;
  129. }
  130. return str;
  131. },
  132. // 初始化大转盘
  133. initialization(){
  134. let awardsConfig = this.data.tablePageInfo,
  135. len = awardsConfig.itemList.length,
  136. rotateDeg = 360 / len / 2 + 90,
  137. turnNum = 1 / len,
  138. html = [];
  139. // var ctx = wx.createContext()
  140. for (var i = 0; i < len; i++) {
  141. // 奖项列表
  142. html.push({turn: i * turnNum + 'turn', lineTurn: i * turnNum + turnNum / 2 + 'turn', award: awardsConfig.itemList[i].title,url:awardsConfig.itemList[i].logo,showWheelLogo: awardsConfig.itemList[i].showWheelLogo});
  143. }
  144. this.setData({
  145. awardsList: html,
  146. btnDisabled: ''
  147. });
  148. },
  149. // 点击抽奖
  150. getPrize(){
  151. this.setData({btnDisabled: 'disabled'})
  152. let that=this,wheelId=this.data.wheelId,peopleId=this.data.tablePageInfo.peopleId;
  153. util.ajax({
  154. func: `v2/market/wheel/${wheelId}/draw`,
  155. data: {
  156. peopleId:peopleId,
  157. wheelId:wheelId
  158. }
  159. }, function (res) {
  160. if (res.code==0) {
  161. if (res.data.status==1) {
  162. that.setData({winThePrize:res.data.item})
  163. let index=0,prize={};
  164. that.data.tablePageInfo.itemList.forEach((el,i) => {
  165. if (el.itemId==res.data.item.id) {
  166. index=i;
  167. prize=res.data;
  168. }
  169. });
  170. that.getLottery(index,prize)
  171. } else {
  172. if (res.data.status!=5) {
  173. that.setData({
  174. showtableStatus:true,
  175. status:res.data.status
  176. })
  177. }else{
  178. that.setData({btnDisabled: ''})
  179.   util.showTips(res.data.message);
  180. }
  181. }
  182. }else{
  183. util.showTips(res.reason);
  184. }
  185. })
  186. },
  187. getLottery(index,info) {
  188. var that = this
  189. var awardIndex =index;
  190. var awardsConfig = this.data.tablePageInfo, // 获取奖品配置
  191. runNum = 6 //旋转圈数
  192. // 旋转抽奖
  193. this.data.tablePageInfo.actnum=this.data.tablePageInfo.actnum <=0 ? 0:this.data.tablePageInfo.actnum-1;
  194. let len =360/awardsConfig.itemList.length/2;
  195. let random = this.random(-len+1,len-1)
  196. this.data.runDegs = this.data.runDegs || 0
  197. this.data.runDegs = this.data.runDegs + (360 - this.data.runDegs % 360) + (360 * runNum - awardIndex * (360 / awardsConfig.itemList.length))+random
  198. var animationRun = wx.createAnimation({
  199. duration: 6000,
  200. timingFunction: 'cubic-bezier(.42,.05,.2,.97)'
  201. })
  202. that.animationRun = animationRun
  203. animationRun.rotate(that.data.runDegs).step()
  204. that.setData({
  205. animationData: animationRun.export(),
  206. 'tablePageInfo.actnum':this.data.tablePageInfo.actnum
  207. })
  208. // 中奖提示
  209. setTimeout(function() {
  210. that.setData({
  211. showPrizePopup:true,
  212. winPrizeInfo:info
  213. })
  214. if (awardsConfig.chance) {
  215. that.setData({
  216. btnDisabled: ''
  217. })
  218. }
  219. }, 6500);
  220. },
  221. // 随机转动度数
  222. random(m,n) {
  223. return Math.floor(Math.random() * (n - m)) + m
  224. },
  225. // 跳转至中奖记录页面
  226. jumpRecord(){
  227. wx.navigateTo({
  228. url: '/pages/turntable/winRecord/index?wheelId='+this.data.wheelId+'&theam='+this.data.theam,
  229. })
  230. },
  231. // 奖品详情页弹窗
  232. openPrizeDetail(e){
  233. let data=e.currentTarget.dataset
  234. switch (data.name) {
  235. case 'rules':
  236. this.setData({
  237. showRulesPopup:true
  238. })
  239. break;
  240. case 'award':
  241. this.setData({
  242. showAwardPopup:true,
  243. prizeInfo:data.item
  244. })
  245. break;
  246. }
  247. },
  248. // 关闭上拉弹窗
  249. closeTip(e){
  250. let data = e.detail;
  251. switch (data.type) {
  252. case 'award':
  253. this.setData({
  254. showAwardPopup:data.status
  255. })
  256. break;
  257. case 'rules':
  258. this.setData({
  259. showRulesPopup:data.status
  260. })
  261. break;
  262. case 'notice':
  263. this.setData({
  264. showPrizePopup:data.status,
  265. btnDisabled: '',
  266. })
  267. break;
  268. case 'table':
  269. this.setData({
  270. showtableStatus:data.status,
  271. btnDisabled: '',
  272. })
  273. break;
  274. case 'address':
  275. this.setData({
  276. showAddress:data.status,
  277. btnDisabled: '',
  278. })
  279. break;
  280. }
  281. },
  282. // 获取奖品列表
  283. getPrizeList(){
  284. let that =this;
  285. util.ajax({
  286. func: `v2/market/wheel/item/list`,
  287. data: { wheelId:that.data.wheelId}
  288. }, function (res) {
  289. if (res.code==0) {
  290. that.setData({PrizeList:res.data})
  291. }else{
  292. util.showTips(res.reason);
  293. }
  294. })
  295. },
  296. // 获取中奖名单列表
  297. getWinprizeList(bol){
  298. let that =this;
  299. util.ajax({
  300. func: `v2/market/wheel/winning/list`,
  301. data: {
  302. wheelId:that.data.wheelId,
  303. }
  304. }, function (res) {
  305. if (res.code==0) {
  306. if (res.data.length>0) {
  307. that.setData({
  308. winPrizeList:res.data
  309. })
  310. that.scrollTopBar()
  311. }
  312. }else{util.showTips(res.reason);}
  313. })
  314. },
  315. // 用户点击右上角分享
  316. onShareAppMessage: function () {
  317. return {
  318. title:this.data.shareTitle,
  319. path:'/pages/turntable/index?id='+this.data.wheelId,
  320. }
  321. },
  322. onHide: function () {
  323. let e = this;
  324. clearInterval(e.data.timer);
  325. },
  326. // 页面卸载关闭定时器
  327. onUnload: function () {
  328. let e = this;
  329. clearInterval(e.data.timer);
  330. },
  331. })