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

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