东风启辰小程序端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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. clearInterval(this.data.setGroup.top);
  308. clearInterval(this.data.setGroup.left);
  309. clearInterval(this.data.setGroup.right);
  310. clearInterval(this.data.setGroup.bottom);
  311. this.setData({
  312. clawType:true
  313. })
  314. this.setData({
  315. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440 )
  316. })
  317. this.closeSetInt();
  318. setTimeout(() => {
  319. this.setData({
  320. clawType: false,
  321. gameState: false
  322. })
  323. if (this.data.endGameData) {
  324. this.setData({
  325. pizeTip: 1
  326. })
  327. } else {
  328. this.setData({
  329. pizeTip: 2
  330. })
  331. }
  332. },800)
  333. },
  334. downTimeFun: function () {//游戏倒计时
  335. this.data.setInt = setInterval(()=>{
  336. this.data.downNum -= 1;
  337. if (this.data.downNum<10){
  338. this.data.downNum = '0' + this.data.downNum;
  339. }
  340. this.setData({
  341. downNum: this.data.downNum
  342. })
  343. if (this.data.downNum < 1) {
  344. this.getClaw();
  345. }
  346. },1000);
  347. },
  348. closeSetInt: function () {//关闭倒计时
  349. clearInterval(this.data.setInt);
  350. this.setData({
  351. downNum: 15,
  352. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440)
  353. })
  354. setTimeout(() => {
  355. this.setData({
  356. gameEnd:false
  357. })
  358. this.setData({
  359. downNum: 15,
  360. clawScale: 1
  361. })
  362. setTimeout(() => {
  363. this.setData({
  364. clawTop: -440,
  365. })
  366. }, 800)
  367. setTimeout(()=>{
  368. this.setData({
  369. clawLeft: 268
  370. })
  371. },1600)
  372. setTimeout(()=>{
  373. this.setData({
  374. gameEnd: true
  375. })
  376. },2400)
  377. }, 800);
  378. },
  379. prizeLook:function(){//活动奖品
  380. if(!this.data.gameState){
  381. wx.navigateTo({
  382. url: '../prizes/prizes'
  383. })
  384. }
  385. },
  386. getAddress: function () {//获取地址
  387. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  388. if (res.code == 200) {
  389. if (res.data) {
  390. this.setData({
  391. isAddress:true
  392. })
  393. }
  394. }
  395. }, this)
  396. },
  397. receive:function(){//立即领取
  398. wx.redirectTo({
  399. url: '../myCenter/myCenter',
  400. })
  401. },
  402. // userRegister: function () {//立即注册,探索更多星探好礼
  403. // wx.navigateTo({
  404. // url: '../address/address',
  405. // })
  406. // },
  407. closeWindow:function(){//关闭中奖
  408. this.setData({
  409. pizeTip:0,
  410. // ruleShow:true
  411. })
  412. },
  413. getGameAwardList: function () {//获取游戏中奖数据
  414. app.wxRequest(app.globalData.urlRoot + "award/getGameAwardList", this.data.configure,res=>{
  415. if(res.code==200){
  416. if(res.data){
  417. var stringContent = "";//字符串内容
  418. for (let i = 0; i < res.data.length; i++) {//内容整合
  419. res.data[i].content = "恭喜" + (res.data[i].nickName ? res.data[i].nickName : '***') + "获得" + res.data[i].awardName+" ";
  420. stringContent += res.data[i].content;
  421. }
  422. this.data.gameAwardListArr += stringContent;
  423. stringContent = stringContent.substring(0, stringContent.length - 2);
  424. this.setData({
  425. gameAwardList: stringContent
  426. })
  427. query.select('.textFrame').boundingClientRect();
  428. query.select('.tipContent').boundingClientRect();
  429. var duration = 0;//动画时常
  430. query.exec((option) => {
  431. duration = option[1].width < option[0].width ? 10 : option[1].width / option[0].width * 10;
  432. this.aniFun(duration * 1000, -option[1].width);
  433. if (res.data.length >= this.data.configure.count) {
  434. console.log("还有更多数据");
  435. setTimeout(() => {
  436. this.aniFun(0, '100%');
  437. this.data.configure.page += 1;
  438. this.getGameAwardList();
  439. }, duration * 1000)
  440. } else {
  441. console.log("没有更多数据了");
  442. setTimeout(() => {
  443. this.aniFun(0, '100%');
  444. this.data.gameAwardListArr = this.data.gameAwardListArr.substring(0, this.data.gameAwardListArr.length - 2);
  445. this.setData({
  446. gameAwardList: this.data.gameAwardListArr
  447. })
  448. query.select('.textFrame').boundingClientRect();
  449. query.select('.tipContent').boundingClientRect();
  450. query.exec((option) => {
  451. duration = option[1].width < option[0].width ? 10 : option[1].width / option[0].width * 10;
  452. this.noMoreData(duration * 1000, -option[1].width);
  453. })
  454. },duration * 1000);
  455. }
  456. })
  457. }
  458. }
  459. },this)
  460. },
  461. noMoreData: function (duration,left){
  462. console.log(1);
  463. this.aniFun(duration, left);
  464. setTimeout(() => {
  465. this.aniFun(0, '100%');
  466. setTimeout(() => {
  467. this.noMoreData(duration, left);
  468. },50);
  469. }, duration)
  470. },
  471. aniFun(duration,left){
  472. var animation = wx.createAnimation({
  473. duration: duration
  474. });
  475. animation.left(left).step();
  476. this.setData({
  477. ani: animation.export()
  478. })
  479. },
  480. getUserWxMsg: function (e) {//通过微信获取用户信息
  481. if (e.detail.errMsg == "getUserInfo:ok") {
  482. this.gameStart();
  483. this.setData({
  484. userData: e.detail.userInfo
  485. })
  486. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  487. }else{
  488. this.gameStart();
  489. }
  490. },
  491. cutPage:function(){//500元待领取
  492. if (!this.data.gameState) {
  493. wx.redirectTo({
  494. url: '/pages/star/star',
  495. })
  496. }
  497. },
  498. openClaw:function(){
  499. if (!this.data.gameState) {
  500. return;
  501. }
  502. this.data.btnGroup.claw = true;
  503. this.setData({
  504. btnGroup: this.data.btnGroup
  505. })
  506. setTimeout(()=>{
  507. this.data.btnGroup.claw = false;
  508. this.setData({
  509. btnGroup: this.data.btnGroup
  510. })
  511. this.getClaw();
  512. },200);
  513. },
  514. getCertificationInfo:function(){
  515. app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfo", {}, res => {
  516. if(res.code==200){
  517. this.setData({
  518. certificationInfo:true
  519. })
  520. app.globalData.certificationInfo = true;
  521. wx.setStorageSync("certificationInfo", true);
  522. }else{
  523. certificationInfoValue = res.code;
  524. }
  525. }, this);
  526. },
  527. enterStar:function(){//
  528. if (certificationInfoValue == -307) {
  529. wx.navigateTo({
  530. url: '/pages/mobileVerification/mobileVerification'
  531. })
  532. } else if (certificationInfoValue == -308) {
  533. wx.navigateTo({
  534. url: '/pages/scout/register/register'
  535. })
  536. }
  537. },
  538. enterIndex:function(){
  539. wx.reLaunch({
  540. url: '/pages/index/index'
  541. })
  542. },
  543. getBuyState: function () {//查询是否已下订
  544. app.wxRequest(app.globalData.urlRoot + "wxPay/getBuyState", {}, res => {
  545. if (res.code == 200) {
  546. if (res.data) {
  547. this.setData({
  548. buyState: res.data.success
  549. })
  550. }
  551. }
  552. }, this);
  553. },
  554. addressControl: function () {//跳转到地址管理
  555. this.setData({
  556. addressShow: !this.data.addressShow
  557. })
  558. if (this.data.addressShow) {
  559. app.globalData.skipType = 'mycenter';
  560. }
  561. },
  562. chanceShowControl:function(){
  563. this.setData({
  564. isChanceShow:true
  565. })
  566. },
  567. operationControl:function(){
  568. this.setData({
  569. operationExampleShow: !this.data.operationExampleShow
  570. })
  571. this.setData({
  572. startDown: 3
  573. })
  574. this.setData({
  575. gameState: true
  576. })
  577. var setInt2 = setInterval(() => {
  578. if (this.data.startDown > -1) {
  579. this.data.startDown -= 1;
  580. this.setData({
  581. startDown: this.data.startDown
  582. })
  583. if (this.data.startDown == -1) {
  584. clearInterval(setInt2);
  585. this.endGame();
  586. if (this.data.gameSign) {
  587. this.downTimeFun();
  588. }
  589. }
  590. }
  591. }, 1000);
  592. }
  593. })