|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- // pages/luckyStar/luckyStar.js
- const app = getApp();
- var query = null;
- var certificationInfoValue = 0;
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- buyState:false,
- ruleShow: true,//是否显示游戏玩法
- ruleCloseShow: true,//是否显示游戏玩法关闭按钮
- clawTop:-440,//爪子的top值
- clawLeft: 268,//爪子的left值
- clawScale: 1,//爪子的scale值
- downNum:30,//倒计时时间
- setInt:null,//倒计时元素
- pizeTip:0,//抓奖提示框
- setGroup:{
- left:null,
- right: null,
- top: null,
- bottom: null,
- },
- btnGroup:{
- left: false,
- right: false,
- top: false,
- bottom: false,
- claw:false
- },
- gameSign: null, //游戏结束时需要
- gameState:false,//游戏状态
- endGameData:null,//中奖数据
- isAddress:false,//是否有地址
- configure:{
- page:1,
- count:10
- },
- gameAwardList:"",
- gameAwardListArr:"",
- userData:null,
- scrollNum:0,
- setInt:null,
- startDown:-1,//游戏开始倒计时
- clawType:false,//是否正在抓取
- gameEnd:true,
- ani:null,
- certificationInfo:false,//是否车主认证了
- addressShow:false
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- query = wx.createSelectorQuery();
- app.globalData.nowPage = 3;
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- },
- loadFun: function () {
- if (app.globalData.userInfoData) {
- this.setData({
- userData: app.globalData.userInfoData
- })
- }
- if (!app.globalData.certificationInfo){
- this.getCertificationInfo();
- }else{
- this.setData({
- certificationInfo: true
- })
- }
- this.getAddress();
- this.getGameAwardList();
- this.getBuyState();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return app.sharePack();
- },
- closeRule:function(){//关闭游戏玩法
- this.setData({
- ruleShow:false
- })
- },
- openGameRule: function () {//打开游戏玩法
- if(!this.data.gameState){
- this.setData({
- ruleShow: true
- })
- }
- },
- gameStart: function () {//开始游戏按钮
- // this.setData({
- // ruleShow: false,
- // ruleCloseShow: true
- // })
- this.beginGame();
- },
- beginGame: function () {//开始游戏
- app.wxRequest(app.globalData.urlRoot + "dollGame/beginGame", {}, res => {
- if(res.code==200){
- this.setData({
- startDown: 3
- })
- var setInt2 = setInterval(() => {
- if (this.data.startDown > -1) {
- this.data.startDown -= 1;
- this.setData({
- startDown: this.data.startDown
- })
- if (this.data.startDown==-1){
- clearInterval(setInt2);
- this.data.gameSign = res.data.sign;
- this.endGame();
- if (this.data.gameSign) {
- this.downTimeFun();
- }
- }
- }
- }, 1000);
- }else{
- wx.showToast({
- title: res.msg,
- icon:"none"
- })
- }
- },this)
- },
- endGame:function(){//结束游戏
- app.wxRequest(app.globalData.urlRoot + "dollGame/endGame", { sign:this.data.gameSign}, res => {
- if(res.code=200){
- this.setData({
- endGameData: res.data
- })
- }else{
- console.log(res);
- }
- }, this,"POST")
- },
- startClaw:function(e){//开始控制爪子方向
- if(!this.data.gameState){
- return;
- }
- let direction = e.currentTarget.dataset.direction;
- if (direction == "L") {//向左
- this.data.btnGroup.left = true;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- if (this.data.clawLeft <= 110) {
- return;
- }
- this.data.setGroup.left = setInterval(() => {
- this.setData({
- clawLeft: this.data.clawLeft-=2
- })
- if (this.data.clawLeft <= 110) {
- clearInterval(this.data.setGroup.left);
- }
- },20);
- } else if (direction == "R") {//向右
- this.data.btnGroup.right = true;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- if (this.data.clawLeft >= 415) {
- return;
- }
- this.data.setGroup.right = setInterval(() => {
- this.setData({
- clawLeft: this.data.clawLeft += 2
- })
- if (this.data.clawLeft >= 415) {
- clearInterval(this.data.setGroup.right);
- }
- }, 20);
- } else if (direction == "T") {//向后
- this.data.btnGroup.top = true;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- if (this.data.clawScale <= 0.8) {
- return;
- }
- this.data.setGroup.top = setInterval(() => {
- this.setData({
- clawScale: this.data.clawScale -= 0.01
- })
- if (this.data.clawScale <= 0.8) {
- clearInterval(this.data.setGroup.top);
- }
- }, 20);
- } else if (direction == "B") {//向前
- this.data.btnGroup.bottom = true;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- if (this.data.clawScale >= 1.2) {
- return;
- }
- this.data.setGroup.bottom = setInterval(() => {
- this.setData({
- clawScale: this.data.clawScale += 0.01
- })
- if (this.data.clawScale >= 1.2) {
- clearInterval(this.data.setGroup.bottom);
- }
- }, 20);
- }
- },
- endClaw: function (e) {//结束爪子动作
- if (!this.data.gameState) {
- return;
- }
- let direction = e.currentTarget.dataset.direction;
- if (direction == "L") {//向左
- this.data.btnGroup.left = false;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- clearInterval(this.data.setGroup.left);
- } else if (direction == "R") {//向右
- this.data.btnGroup.right = false;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- clearInterval(this.data.setGroup.right);
- } else if (direction == "T") {//向后
- this.data.btnGroup.top = false;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- clearInterval(this.data.setGroup.top);
- } else if (direction == "B") {//向前
- this.data.btnGroup.bottom = false;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- clearInterval(this.data.setGroup.bottom);
- }
- },
- getClaw:function(){//抓取
- this.setData({
- clawType:true
- })
- this.setData({
- clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440 )
- })
- this.closeSetInt();
- setTimeout(() => {
- this.setData({
- clawType: false,
- gameState: false
- })
- if (this.data.endGameData) {
- this.setData({
- pizeTip: 1
- })
- } else {
- this.setData({
- pizeTip: 2
- })
- }
- },800)
- },
- downTimeFun: function () {//游戏倒计时
- this.setData({
- gameState:true
- })
- this.data.setInt = setInterval(()=>{
- this.data.downNum -= 1;
- if (this.data.downNum<10){
- this.data.downNum = '0' + this.data.downNum;
- }
- this.setData({
- downNum: this.data.downNum
- })
- if (this.data.downNum < 1) {
- this.getClaw();
- }
- },1000);
- },
- closeSetInt: function () {//关闭倒计时
- clearInterval(this.data.setInt);
- this.setData({
- downNum: 30,
- clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440)
- })
- setTimeout(() => {
- this.setData({
- gameEnd:false
- })
- this.setData({
- downNum: 30,
- clawScale: 1
- })
- setTimeout(() => {
- this.setData({
- clawTop: -440,
- })
- }, 800)
- setTimeout(()=>{
- this.setData({
- clawLeft: 268
- })
- },1600)
- setTimeout(()=>{
- this.setData({
- gameEnd: true
- })
- },2400)
- }, 800);
- },
- prizeLook:function(){//活动奖品
- if(!this.data.gameState){
- wx.navigateTo({
- url: '../prizes/prizes'
- })
- }
- },
- getAddress: function () {//获取地址
- app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
- if (res.code == 200) {
- if (res.data) {
- this.setData({
- isAddress:true
- })
- }
- }
- }, this)
- },
- receive:function(){//立即领取
- wx.redirectTo({
- url: '../myCenter/myCenter',
- })
- },
- // userRegister: function () {//立即注册,探索更多星探好礼
- // wx.navigateTo({
- // url: '../address/address',
- // })
- // },
- closeWindow:function(){//关闭中奖
- this.setData({
- pizeTip:0,
- // ruleShow:true
- })
- },
- getGameAwardList: function () {//获取游戏中奖数据
- app.wxRequest(app.globalData.urlRoot + "award/getGameAwardList", this.data.configure,res=>{
- if(res.code==200){
- if(res.data){
- var stringContent = "";//字符串内容
- for (let i = 0; i < res.data.length; i++) {//内容整合
- res.data[i].content = "恭喜" + (res.data[i].nickName ? res.data[i].nickName : '***') + "获得" + res.data[i].awardName+" ";
- stringContent += res.data[i].content;
- }
- this.data.gameAwardListArr += stringContent;
- stringContent = stringContent.substring(0, stringContent.length - 2);
- this.setData({
- gameAwardList: stringContent
- })
- query.select('.textFrame').boundingClientRect();
- query.select('.tipContent').boundingClientRect();
- var duration = 0;//动画时常
- query.exec((option) => {
- duration = option[1].width < option[0].width ? 10 : option[1].width / option[0].width * 10;
- this.aniFun(duration * 1000, -option[1].width);
- if (res.data.length >= this.data.configure.count) {
- console.log("还有更多数据");
- setTimeout(() => {
- this.aniFun(0, '100%');
- this.data.configure.page += 1;
- this.getGameAwardList();
- }, duration * 1000)
- } else {
- console.log("没有更多数据了");
- setTimeout(() => {
- this.aniFun(0, '100%');
- this.data.gameAwardListArr = this.data.gameAwardListArr.substring(0, this.data.gameAwardListArr.length - 2);
- this.setData({
- gameAwardList: this.data.gameAwardListArr
- })
- query.select('.textFrame').boundingClientRect();
- query.select('.tipContent').boundingClientRect();
- query.exec((option) => {
- duration = option[1].width < option[0].width ? 10 : option[1].width / option[0].width * 10;
- this.noMoreData(duration * 1000, -option[1].width);
- })
- },duration * 1000);
- }
- })
- }
- }
- },this)
- },
- noMoreData: function (duration,left){
- console.log(1);
- this.aniFun(duration, left);
- setTimeout(() => {
- this.aniFun(0, '100%');
- setTimeout(() => {
- this.noMoreData(duration, left);
- },50);
- }, duration)
- },
- aniFun(duration,left){
- var animation = wx.createAnimation({
- duration: duration
- });
- animation.left(left).step();
- this.setData({
- ani: animation.export()
- })
- },
- getUserWxMsg: function (e) {//通过微信获取用户信息
- if (e.detail.errMsg == "getUserInfo:ok") {
- this.gameStart();
- this.setData({
- userData: e.detail.userInfo
- })
- app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
- }else{
- this.gameStart();
- }
- },
- cutPage:function(){//500元待领取
- if (!this.data.gameState) {
- wx.redirectTo({
- url: '/pages/star/star',
- })
- }
- },
- openClaw:function(){
- if (!this.data.gameState) {
- return;
- }
- this.data.btnGroup.claw = true;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- setTimeout(()=>{
- this.data.btnGroup.claw = false;
- this.setData({
- btnGroup: this.data.btnGroup
- })
- this.getClaw();
- },200);
- },
- getCertificationInfo:function(){
- app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfo", {}, res => {
- if(res.code==200){
- this.setData({
- certificationInfo:true
- })
- app.globalData.certificationInfo = true;
- wx.setStorageSync("certificationInfo", true);
- }else{
- certificationInfoValue = res.code;
- }
- }, this);
- },
- enterStar:function(){//
- if (certificationInfoValue == -307) {
- wx.navigateTo({
- url: '/pages/mobileVerification/mobileVerification'
- })
- } else if (certificationInfoValue == -308) {
- wx.navigateTo({
- url: '/pages/scout/register/register'
- })
- }
- },
- getBuyState: function () {//查询是否已下订
- app.wxRequest(app.globalData.urlRoot + "wxPay/getBuyState", {}, res => {
- if (res.code == 200) {
- if (res.data) {
- this.setData({
- buyState: res.data.success
- })
- }
- }
- }, this);
- },
- addressControl: function () {//跳转到地址管理
- this.setData({
- addressShow: !this.data.addressShow
- })
- }
- })
|