东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

luckyStar.js 16KB

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