东风启辰小程序端
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 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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 app.sharePack();
  118. },
  119. closeRule:function(){//关闭游戏玩法
  120. this.setData({
  121. ruleShow:false
  122. })
  123. },
  124. openGameRule: function () {//打开游戏玩法
  125. if(!this.data.gameState){
  126. this.setData({
  127. ruleShow: true
  128. })
  129. }
  130. },
  131. gameStart: function () {//开始游戏按钮
  132. // this.setData({
  133. // ruleShow: false,
  134. // ruleCloseShow: true
  135. // })
  136. this.beginGame();
  137. },
  138. beginGame: function () {//开始游戏
  139. app.wxRequest(app.globalData.urlRoot + "dollGame/beginGame", {}, res => {
  140. if(res.code==200){
  141. this.setData({
  142. startDown: 3
  143. })
  144. this.setData({
  145. gameState: true
  146. })
  147. var setInt2 = setInterval(() => {
  148. if (this.data.startDown > -1) {
  149. this.data.startDown -= 1;
  150. this.setData({
  151. startDown: this.data.startDown
  152. })
  153. if (this.data.startDown==-1){
  154. clearInterval(setInt2);
  155. this.data.gameSign = res.data.sign;
  156. this.endGame();
  157. if (this.data.gameSign) {
  158. this.downTimeFun();
  159. }
  160. }
  161. }
  162. }, 1000);
  163. }else{
  164. this.setData({
  165. isChanceShow:false
  166. })
  167. }
  168. },this)
  169. },
  170. endGame:function(){//结束游戏
  171. app.wxRequest(app.globalData.urlRoot + "dollGame/endGame", { sign:this.data.gameSign}, res => {
  172. if(res.code=200){
  173. this.setData({
  174. endGameData: res.data
  175. })
  176. }else{
  177. console.log(res);
  178. }
  179. }, this,"POST")
  180. },
  181. startClaw:function(e){//开始控制爪子方向
  182. if(!this.data.gameState){
  183. return;
  184. }
  185. let direction = e.currentTarget.dataset.direction;
  186. if (direction == "L") {//向左
  187. this.data.btnGroup.left = true;
  188. this.setData({
  189. btnGroup: this.data.btnGroup
  190. })
  191. if (this.data.clawLeft <= 110) {
  192. return;
  193. }
  194. this.data.setGroup.left = setInterval(() => {
  195. this.setData({
  196. clawLeft: this.data.clawLeft-=2
  197. })
  198. if (this.data.clawLeft <= 110) {
  199. clearInterval(this.data.setGroup.left);
  200. }
  201. },20);
  202. } else if (direction == "R") {//向右
  203. this.data.btnGroup.right = true;
  204. this.setData({
  205. btnGroup: this.data.btnGroup
  206. })
  207. if (this.data.clawLeft >= 415) {
  208. return;
  209. }
  210. this.data.setGroup.right = setInterval(() => {
  211. this.setData({
  212. clawLeft: this.data.clawLeft += 2
  213. })
  214. if (this.data.clawLeft >= 415) {
  215. clearInterval(this.data.setGroup.right);
  216. }
  217. }, 20);
  218. } else if (direction == "T") {//向后
  219. this.data.btnGroup.top = true;
  220. this.setData({
  221. btnGroup: this.data.btnGroup
  222. })
  223. if (this.data.clawScale <= 0.8) {
  224. return;
  225. }
  226. this.data.setGroup.top = setInterval(() => {
  227. this.setData({
  228. clawScale: this.data.clawScale -= 0.01
  229. })
  230. if (this.data.clawScale <= 0.8) {
  231. clearInterval(this.data.setGroup.top);
  232. }
  233. }, 20);
  234. } else if (direction == "B") {//向前
  235. this.data.btnGroup.bottom = true;
  236. this.setData({
  237. btnGroup: this.data.btnGroup
  238. })
  239. if (this.data.clawScale >= 1.2) {
  240. return;
  241. }
  242. this.data.setGroup.bottom = setInterval(() => {
  243. this.setData({
  244. clawScale: this.data.clawScale += 0.01
  245. })
  246. if (this.data.clawScale >= 1.2) {
  247. clearInterval(this.data.setGroup.bottom);
  248. }
  249. }, 20);
  250. }
  251. },
  252. endClaw: function (e) {//结束爪子动作
  253. if (!this.data.gameState) {
  254. return;
  255. }
  256. let direction = e.currentTarget.dataset.direction;
  257. if (direction == "L") {//向左
  258. this.data.btnGroup.left = false;
  259. this.setData({
  260. btnGroup: this.data.btnGroup
  261. })
  262. clearInterval(this.data.setGroup.left);
  263. } else if (direction == "R") {//向右
  264. this.data.btnGroup.right = false;
  265. this.setData({
  266. btnGroup: this.data.btnGroup
  267. })
  268. clearInterval(this.data.setGroup.right);
  269. } else if (direction == "T") {//向后
  270. this.data.btnGroup.top = false;
  271. this.setData({
  272. btnGroup: this.data.btnGroup
  273. })
  274. clearInterval(this.data.setGroup.top);
  275. } else if (direction == "B") {//向前
  276. this.data.btnGroup.bottom = false;
  277. this.setData({
  278. btnGroup: this.data.btnGroup
  279. })
  280. clearInterval(this.data.setGroup.bottom);
  281. }
  282. },
  283. getClaw: function () {//抓取
  284. clearInterval(this.data.setGroup.top);
  285. clearInterval(this.data.setGroup.left);
  286. clearInterval(this.data.setGroup.right);
  287. clearInterval(this.data.setGroup.bottom);
  288. this.setData({
  289. clawType:true
  290. })
  291. this.setData({
  292. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440 )
  293. })
  294. this.closeSetInt();
  295. setTimeout(() => {
  296. this.setData({
  297. clawType: false,
  298. gameState: false
  299. })
  300. if (this.data.endGameData) {
  301. this.setData({
  302. pizeTip: 1
  303. })
  304. } else {
  305. this.setData({
  306. pizeTip: 2
  307. })
  308. }
  309. },800)
  310. },
  311. downTimeFun: function () {//游戏倒计时
  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. chanceShowControl:function(){
  532. this.setData({
  533. isChanceShow:true
  534. })
  535. }
  536. })