东风启辰小程序端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

545 行
14KB

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