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

518 lines
13KB

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