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

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