东风启辰小程序端
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.

597 line
15KB

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