东风启辰小程序端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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