东风启辰小程序端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

619 líneas
16KB

  1. // pages/luckyStar/luckyStar.js
  2. const app = getApp();
  3. var query = null;
  4. var certificationInfoValue = 0;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgUrl: app.globalData.urlStatic,//图片路径
  11. httpState:false,
  12. buyState:false,
  13. ruleShow: false,//是否显示游戏玩法
  14. ruleCloseShow: true,//是否显示游戏玩法关闭按钮
  15. clawTop:-440,//爪子的top值
  16. clawLeft: 268,//爪子的left值
  17. clawScale: 1,//爪子的scale值
  18. downNum:15,//倒计时时间
  19. setInt:null,//倒计时元素
  20. pizeTip:0,//抓奖提示框
  21. pageUnload:false,//页面是否退出了
  22. setGroup:{
  23. left:null,
  24. right: null,
  25. top: null,
  26. bottom: null,
  27. },
  28. btnGroup:{
  29. left: false,
  30. right: false,
  31. top: false,
  32. bottom: false,
  33. claw:false
  34. },
  35. gameSign: null, //游戏结束时需要
  36. gameState:false,//游戏状态
  37. endGameData:null,//中奖数据
  38. isAddress:false,//是否有地址
  39. configure:{
  40. page:1,
  41. count:10
  42. },
  43. gameAwardList:"",
  44. gameAwardListArr:"",
  45. userData:null,
  46. scrollNum:0,
  47. setInt:null,
  48. startDown:-1,//游戏开始倒计时
  49. clawType:false,//是否正在抓取
  50. gameEnd:true,
  51. ani:null,
  52. certificationInfo:false,//是否车主认证了
  53. addressShow:false,
  54. isChanceShow:true,//是否还有机会
  55. operationExampleShow:false,
  56. operationExampleNum:0
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad: function (options) {
  62. if (app.globalData.isFirstLucky){
  63. this.setData({
  64. ruleShow:true
  65. })
  66. app.globalData.isFirstLucky = false;
  67. }
  68. query = wx.createSelectorQuery();
  69. app.globalData.nowPage = 3;
  70. if (app.globalData.openid) {
  71. this.loadFun();
  72. } else {
  73. app.globalData.openidSuccessFuc = this.loadFun;
  74. }
  75. },
  76. loadFun: function () {
  77. if (!app.globalData.addPageEnterState.luckyStar) {
  78. app.addPageEnter("FF975289E95B64D590C9A106B898574F");
  79. app.globalData.addPageEnterState.luckyStar = true;
  80. }
  81. if (app.globalData.userInfoData) {
  82. this.setData({
  83. userData: app.globalData.userInfoData
  84. })
  85. }
  86. if (!app.globalData.certificationInfo){
  87. // this.getCertificationInfo();
  88. }else{
  89. this.setData({
  90. certificationInfo: true
  91. })
  92. }
  93. this.getAddress();
  94. this.getGameAwardList();
  95. this.getBuyState();
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload: function () {
  116. this.data.pageUnload = true;
  117. clearInterval(this.data.setInt);
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage: function () {
  133. return {
  134. title: '能抓到头等舱机票的神仙娃娃机,快来一起玩!',
  135. imageUrl: "",
  136. path: "/pages/luckyStar/luckyStar"
  137. }
  138. // return app.sharePack();
  139. },
  140. closeRule:function(){//关闭游戏玩法
  141. this.setData({
  142. ruleShow:false
  143. })
  144. },
  145. openGameRule: function () {//打开游戏玩法
  146. if(!this.data.gameState){
  147. this.setData({
  148. ruleShow: true
  149. })
  150. }
  151. },
  152. gameStart: function () {//开始游戏按钮
  153. // this.setData({
  154. // ruleShow: false,
  155. // ruleCloseShow: true
  156. // })
  157. this.beginGame();
  158. },
  159. beginGame: function () {//开始游戏
  160. if(this.data.httpState){
  161. return;
  162. }
  163. this.data.httpState = true;
  164. app.wxRequest(app.globalData.urlRoot + "dollGame/beginGame", {}, res => {
  165. this.data.httpState = false;
  166. if (res.code == 200) {
  167. this.data.gameSign = res.data.sign;
  168. this.setData({
  169. operationExampleShow: true,
  170. operationExampleNum: 1
  171. })
  172. var setInt = setInterval(() => {
  173. if (!this.data.operationExampleShow) {
  174. clearInterval(setInt);
  175. this.setData({
  176. operationExampleNum: 0
  177. })
  178. }
  179. if (this.data.operationExampleNum == 4) {
  180. this.setData({
  181. operationExampleNum: 1
  182. })
  183. } else {
  184. this.setData({
  185. operationExampleNum: this.data.operationExampleNum += 1
  186. })
  187. }
  188. }, 800)
  189. }else{
  190. this.setData({
  191. isChanceShow:false
  192. })
  193. }
  194. },this)
  195. },
  196. endGame:function(){//结束游戏
  197. app.wxRequest(app.globalData.urlRoot + "dollGame/endGame", { sign:this.data.gameSign}, res => {
  198. if(res.code=200){
  199. this.setData({
  200. endGameData: res.data
  201. })
  202. }else{
  203. console.log(res);
  204. }
  205. }, this,"POST")
  206. },
  207. startClaw:function(e){//开始控制爪子方向
  208. if(!this.data.gameState){
  209. return;
  210. }
  211. let direction = e.currentTarget.dataset.direction;
  212. if (direction == "L") {//向左
  213. this.data.btnGroup.left = true;
  214. this.setData({
  215. btnGroup: this.data.btnGroup
  216. })
  217. if (this.data.clawLeft <= 110) {
  218. return;
  219. }
  220. this.data.setGroup.left = setInterval(() => {
  221. this.setData({
  222. clawLeft: this.data.clawLeft-=2
  223. })
  224. if (this.data.clawLeft <= 110) {
  225. clearInterval(this.data.setGroup.left);
  226. }
  227. },20);
  228. } else if (direction == "R") {//向右
  229. this.data.btnGroup.right = true;
  230. this.setData({
  231. btnGroup: this.data.btnGroup
  232. })
  233. if (this.data.clawLeft >= 415) {
  234. return;
  235. }
  236. this.data.setGroup.right = setInterval(() => {
  237. this.setData({
  238. clawLeft: this.data.clawLeft += 2
  239. })
  240. if (this.data.clawLeft >= 415) {
  241. clearInterval(this.data.setGroup.right);
  242. }
  243. }, 20);
  244. } else if (direction == "T") {//向后
  245. this.data.btnGroup.top = true;
  246. this.setData({
  247. btnGroup: this.data.btnGroup
  248. })
  249. if (this.data.clawScale <= 0.8) {
  250. return;
  251. }
  252. this.data.setGroup.top = setInterval(() => {
  253. this.setData({
  254. clawScale: this.data.clawScale -= 0.01
  255. })
  256. if (this.data.clawScale <= 0.8) {
  257. clearInterval(this.data.setGroup.top);
  258. }
  259. }, 20);
  260. } else if (direction == "B") {//向前
  261. this.data.btnGroup.bottom = true;
  262. this.setData({
  263. btnGroup: this.data.btnGroup
  264. })
  265. if (this.data.clawScale >= 1.2) {
  266. return;
  267. }
  268. this.data.setGroup.bottom = setInterval(() => {
  269. this.setData({
  270. clawScale: this.data.clawScale += 0.01
  271. })
  272. if (this.data.clawScale >= 1.2) {
  273. clearInterval(this.data.setGroup.bottom);
  274. }
  275. }, 20);
  276. }
  277. },
  278. endClaw: function (e) {//结束爪子动作
  279. if (!this.data.gameState) {
  280. return;
  281. }
  282. let direction = e.currentTarget.dataset.direction;
  283. if (direction == "L") {//向左
  284. this.data.btnGroup.left = false;
  285. this.setData({
  286. btnGroup: this.data.btnGroup
  287. })
  288. clearInterval(this.data.setGroup.left);
  289. } else if (direction == "R") {//向右
  290. this.data.btnGroup.right = false;
  291. this.setData({
  292. btnGroup: this.data.btnGroup
  293. })
  294. clearInterval(this.data.setGroup.right);
  295. } else if (direction == "T") {//向后
  296. this.data.btnGroup.top = false;
  297. this.setData({
  298. btnGroup: this.data.btnGroup
  299. })
  300. clearInterval(this.data.setGroup.top);
  301. } else if (direction == "B") {//向前
  302. this.data.btnGroup.bottom = false;
  303. this.setData({
  304. btnGroup: this.data.btnGroup
  305. })
  306. clearInterval(this.data.setGroup.bottom);
  307. }
  308. },
  309. getClaw: function () {//抓取
  310. this.endGame();
  311. clearInterval(this.data.setGroup.top);
  312. clearInterval(this.data.setGroup.left);
  313. clearInterval(this.data.setGroup.right);
  314. clearInterval(this.data.setGroup.bottom);
  315. this.setData({
  316. clawType:true
  317. })
  318. this.setData({
  319. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440 )
  320. })
  321. this.closeSetInt();
  322. setTimeout(() => {
  323. this.setData({
  324. clawType: false,
  325. gameState: false
  326. })
  327. if (this.data.endGameData) {
  328. this.setData({
  329. pizeTip: 1
  330. })
  331. } else {
  332. this.setData({
  333. pizeTip: 2
  334. })
  335. }
  336. },800)
  337. },
  338. downTimeFun: function () {//游戏倒计时
  339. this.data.setInt = setInterval(()=>{
  340. this.data.downNum -= 1;
  341. if (this.data.downNum<10){
  342. this.data.downNum = '0' + this.data.downNum;
  343. }
  344. this.setData({
  345. downNum: this.data.downNum
  346. })
  347. if (this.data.downNum < 1) {
  348. this.getClaw();
  349. }
  350. },1000);
  351. },
  352. closeSetInt: function () {//关闭倒计时
  353. clearInterval(this.data.setInt);
  354. this.setData({
  355. downNum: 15,
  356. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440)
  357. })
  358. setTimeout(() => {
  359. this.setData({
  360. gameEnd:false
  361. })
  362. this.setData({
  363. downNum: 15,
  364. clawScale: 1
  365. })
  366. setTimeout(() => {
  367. this.setData({
  368. clawTop: -440,
  369. })
  370. }, 800)
  371. setTimeout(()=>{
  372. this.setData({
  373. clawLeft: 268
  374. })
  375. },1600)
  376. setTimeout(()=>{
  377. this.setData({
  378. gameEnd: true
  379. })
  380. },2400)
  381. }, 800);
  382. },
  383. prizeLook:function(){//活动奖品
  384. if(!this.data.gameState){
  385. wx.navigateTo({
  386. url: '../prizes/prizes'
  387. })
  388. }
  389. },
  390. getAddress: function () {//获取地址
  391. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  392. if (res.code == 200) {
  393. if (res.data) {
  394. this.setData({
  395. isAddress:true
  396. })
  397. }
  398. }
  399. }, this)
  400. },
  401. receive:function(){//立即领取
  402. wx.redirectTo({
  403. url: '../myCenter/myCenter',
  404. })
  405. },
  406. // userRegister: function () {//立即注册,探索更多星探好礼
  407. // wx.navigateTo({
  408. // url: '../address/address',
  409. // })
  410. // },
  411. closeWindow:function(){//关闭中奖
  412. this.setData({
  413. pizeTip:0,
  414. // ruleShow:true
  415. })
  416. },
  417. getGameAwardList: function () {//获取游戏中奖数据
  418. if(this.data.pageUnload){
  419. return;
  420. }
  421. app.wxRequest(app.globalData.urlRoot + "award/getGameAwardList", this.data.configure,res=>{
  422. if(res.code==200){
  423. if(res.data){
  424. var stringContent = "";//字符串内容
  425. for (let i = 0; i < res.data.length; i++) {//内容整合
  426. res.data[i].content = "恭喜" + (res.data[i].nickName ? res.data[i].nickName : '***') + "获得" + res.data[i].awardName+" ";
  427. stringContent += res.data[i].content;
  428. }
  429. this.data.gameAwardListArr += stringContent;
  430. stringContent = stringContent.substring(0, stringContent.length - 2);
  431. this.setData({
  432. gameAwardList: stringContent
  433. })
  434. query.select('.textFrame').boundingClientRect();
  435. query.select('.tipContent').boundingClientRect();
  436. var duration = 0;//动画时常
  437. query.exec((option) => {
  438. if(!option || !option[0] || !option[1] || !option[0].width || !option[1].width){
  439. setTimeout(()=>{
  440. this.getGameAwardList();
  441. },3000);
  442. return;
  443. }
  444. duration = option[1].width < option[0].width ? 10 : option[1].width / option[0].width * 10;
  445. this.aniFun(duration * 1000, -option[1].width);
  446. if (res.data.length >= this.data.configure.count) {
  447. setTimeout(() => {
  448. this.aniFun(0, '100%');
  449. this.data.configure.page += 1;
  450. this.getGameAwardList();
  451. }, duration * 1000)
  452. } else {
  453. // console.log("没有更多数据了");
  454. setTimeout(() => {
  455. this.aniFun(0, '100%');
  456. this.data.gameAwardListArr = this.data.gameAwardListArr.substring(0, this.data.gameAwardListArr.length - 2);
  457. this.setData({
  458. gameAwardList: this.data.gameAwardListArr
  459. })
  460. query.select('.textFrame').boundingClientRect();
  461. query.select('.tipContent').boundingClientRect();
  462. query.exec((option) => {
  463. duration = option[1].width < option[0].width ? 10 : option[1].width / option[0].width * 10;
  464. this.noMoreData(duration * 1000, -option[1].width);
  465. })
  466. },duration * 1000);
  467. }
  468. })
  469. }
  470. }
  471. },this)
  472. },
  473. noMoreData: function (duration,left){
  474. if(this.data.pageUnload){
  475. return;
  476. }
  477. this.aniFun(duration, left);
  478. setTimeout(() => {
  479. this.aniFun(0, '100%');
  480. setTimeout(() => {
  481. this.noMoreData(duration, left);
  482. },50);
  483. }, duration)
  484. },
  485. aniFun(duration,left){
  486. var animation = wx.createAnimation({
  487. duration: duration
  488. });
  489. animation.left(left).step();
  490. this.setData({
  491. ani: animation.export()
  492. })
  493. },
  494. getUserWxMsg: function (e) {//通过微信获取用户信息
  495. if (e.detail.errMsg == "getUserInfo:ok") {
  496. this.gameStart();
  497. this.setData({
  498. userData: e.detail.userInfo
  499. })
  500. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  501. }else{
  502. this.gameStart();
  503. }
  504. },
  505. cutPage:function(){//500元待领取
  506. if (!this.data.gameState) {
  507. wx.redirectTo({
  508. url: '/pages/star/star',
  509. })
  510. }
  511. },
  512. openClaw:function(){
  513. if (!this.data.gameState) {
  514. return;
  515. }
  516. this.data.btnGroup.claw = true;
  517. this.setData({
  518. btnGroup: this.data.btnGroup
  519. })
  520. setTimeout(()=>{
  521. this.data.btnGroup.claw = false;
  522. this.setData({
  523. btnGroup: this.data.btnGroup
  524. })
  525. this.getClaw();
  526. },200);
  527. },
  528. getCertificationInfo:function(){
  529. app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfo", {}, res => {
  530. if(res.code==200){
  531. this.setData({
  532. certificationInfo:true
  533. })
  534. app.globalData.certificationInfo = true;
  535. wx.setStorageSync("certificationInfo", true);
  536. }else{
  537. certificationInfoValue = res.code;
  538. }
  539. }, this);
  540. },
  541. enterStar:function(){//
  542. if (certificationInfoValue == -307) {
  543. wx.navigateTo({
  544. url: '/pages/mobileVerification/mobileVerification'
  545. })
  546. } else if (certificationInfoValue == -308) {
  547. wx.navigateTo({
  548. url: '/pages/scout/register/register'
  549. })
  550. }
  551. },
  552. enterIndex:function(){
  553. wx.reLaunch({
  554. url: '/pages/index/index'
  555. })
  556. },
  557. getBuyState: function () {//查询是否已下订
  558. app.wxRequest(app.globalData.urlRoot + "wxPay/getBuyState", {source:2}, res => {
  559. if (res.code == 200) {
  560. if (res.data) {
  561. this.setData({
  562. buyState: res.data.success
  563. })
  564. }
  565. }
  566. }, this);
  567. },
  568. addressControl: function () {//跳转到地址管理
  569. this.setData({
  570. addressShow: !this.data.addressShow
  571. })
  572. if (this.data.addressShow) {
  573. app.globalData.skipType = 'mycenter';
  574. }
  575. },
  576. chanceShowControl:function(){
  577. this.setData({
  578. isChanceShow:true
  579. })
  580. },
  581. operationControl:function(){
  582. this.setData({
  583. operationExampleShow: !this.data.operationExampleShow
  584. })
  585. this.setData({
  586. startDown: 3
  587. })
  588. this.setData({
  589. gameState: true
  590. })
  591. var setInt2 = setInterval(() => {
  592. if (this.data.startDown > -1) {
  593. this.data.startDown -= 1;
  594. this.setData({
  595. startDown: this.data.startDown
  596. })
  597. if (this.data.startDown == -1) {
  598. clearInterval(setInt2);
  599. if (this.data.gameSign) {
  600. this.downTimeFun();
  601. }
  602. }
  603. }
  604. }, 1000);
  605. }
  606. })