| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /** 引导到微信 */
- import JsbSystem from "../../../mk/system/JsbSystem";
- import { DataEventId } from "../../data/GameData";
- import { GuideState } from "../../data/module/GuideToWxData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class GuideToWx extends cc.Component {
- @property(cc.Sprite)
- sp_money: cc.Sprite = null;
- @property(cc.Sprite)
- sp_getMoney: cc.Sprite = null;
- @property(cc.Sprite)
- sp_fill: cc.Sprite = null;
- @property(cc.Node)
- node_target: cc.Node = null;
- @property(cc.Node)
- hand: cc.Node = null;
- @property(cc.VideoPlayer)
- videoPlayer: cc.VideoPlayer = null;
- @property(cc.Node)
- nodeStateArr: cc.Node[] = [];
- /** 进度条进度 */
- private fillPer = 0;
- /** 根据金额获取index */
- private moneyIndex = 0;
- private checkCloseGuide = false;
- private lastTimeSpan = -1;
- async start() {
- this.node_target.opacity = 0;
- this.hand.active = false;
- this.moneyIndex = this.getIndexByMoney();
- let path = 'module/guideToWx/texture/money_' + this.moneyIndex;
- this.sp_money.spriteFrame = await mk.loader.load(path, cc.SpriteFrame);
- let response = await mk.http.sendData('getAddServiceState', {});
- mk.console.logSingle('GuideToWx getAddServiceState ', response);
- if (response.errcode != 0) {
- return
- }
- console.log("state >> ", response.data.state)
- switch (response.data.state) {
- case 0:
- let state = mk.storage.getStorage('GuideState');
- if (!state) {
- state = '0';
- }
- gData.guideToWxData.guideState = parseInt(state);
- break;
- case 1:
- gData.guideToWxData.guideState = GuideState.canGetMoney;
- let stateN = mk.storage.getStorage('canGetMoney');
- if (!stateN) {
- mk.storage.setStorage('canGetMoney', 1);
- mk.data.sendDataEvent(DataEventId.guideToWx, "二维码");
- }
- break;
- case 2:
- gData.guideToWxData.guideState = GuideState.gotMoney;
- break;
- }
- await mk.time.WaitForSeconds(0.3);
- this.setState();
- this.videoPlayer.node.on("completed", this.onCompleted, this);
- if (!mk.guide.isGuiding()) {
- this.playVideo();
- }
- else {
- this.checkCloseGuide = true;
- }
- }
- playVideo() {
- this.videoPlayer.node.active = true;
- mk.audio.setPauseMusic();
- this.videoPlayer.play();
- }
- update() {
- if (this.checkCloseGuide) {
- if (!mk.guide.isGuiding()) {
- this.checkCloseGuide = false;
- this.playVideo();
- }
- }
- if (this.lastTimeSpan != -1) {
- let pass = Date.now() - this.lastTimeSpan;
- mk.console.logSingle('GuideToWx pass ', pass);
- if (pass >= 10000) {
- gData.guideToWxData.guideState = 3;
- mk.storage.setStorage('GuideState', gData.guideToWxData.guideState);
- this.setState();
- }
- this.lastTimeSpan = -1;
- }
- }
- async setState() {
- this.nodeStateArr.forEach(element => {
- element.active = true;
- });
- this.node_target.opacity = 0;
- this.node_target.active = true;
- let nodeState: cc.Node = null;
- let path = '';
- switch (gData.guideToWxData.guideState) {
- case GuideState.none:
- this.fillPer = 0;
- path = 'module/guideToWx/texture/addService';
- nodeState = this.nodeStateArr[0];
- break;
- case GuideState.sendApply:
- this.fillPer = 0.33;
- path = 'module/guideToWx/texture/addService';
- nodeState = this.nodeStateArr[1];
- break;
- case GuideState.waitForPass:
- this.fillPer = 0.66;
- path = 'module/guideToWx/texture/addService';
- nodeState = this.nodeStateArr[2];
- break;
- case GuideState.canGetMoney:
- this.fillPer = 1;
- path = 'module/guideToWx/texture/get_' + this.moneyIndex;
- nodeState = this.nodeStateArr[3];
- break;
- case GuideState.gotMoney:
- this.fillPer = 1;
- path = 'module/guideToWx/texture/getSuccess';
- this.node_target.active = false;
- this.nodeStateArr[3].active = true;
- break;
- }
- this.sp_getMoney.spriteFrame = await mk.loader.load(path, cc.SpriteFrame);
- cc.tween(this.sp_fill)
- .to(0.5, { fillRange: this.fillPer })
- .start();
- if (nodeState) {
- this.node_target.x = nodeState.x;
- cc.tween(nodeState).delay(0.5)
- .to(0.25, { scale: 1.2 })
- .to(0.25, { scale: 1 })
- .call(() => {
- nodeState.active = false;
- this.hand.active = true;
- })
- .start();
- }
- cc.tween(this.node_target)
- .delay(1.5)
- .to(0.5, { opacity: 255 })
- .start();
- }
- getIndexByMoney() {
- let index = 0;
- switch (parseFloat(gData.guideToWxData.money)) {
- case 0.3:
- index = 0;
- break;
- case 0.5:
- index = 1;
- break;
- case 0.8:
- index = 2;
- break;
- case 1:
- index = 3;
- break;
- }
- return index;
- }
- async clickService() {
- mk.audio.playEffect('button');
- if (gData.guideToWxData.guideState == GuideState.none || gData.guideToWxData.guideState == GuideState.sendApply
- || gData.guideToWxData.guideState == GuideState.waitForPass) {
- this.lastTimeSpan = Date.now();
- mk.console.logSingle('GuideToWx lastTimeSpan ', this.lastTimeSpan);
- JsbSystem.WXLaunchMiniProgram(gData.guideToWxData.ghId, gData.guideToWxData.ghIdPath);
- let value = mk.storage.getStorage('addServer')
- if (!value) {
- mk.storage.setStorage('addServer', 1);
- mk.data.sendDataEvent(DataEventId.guideToWx, `添加客服`);
- mk.data.sendXYEvent('addService', '添加客服');
- }
- }
- else if (gData.guideToWxData.guideState == GuideState.canGetMoney) {
- let response = await mk.http.sendData('customerServiceCash', {});
- mk.console.logSingle('GuideToWx customerServiceCash ', response);
- if (response.errcode != 0) {
- if (response.data.count) {
- gData.tipPanelData.openCashFailTip(response.data.count);
- }
- else {
- mk.tip.pop('提现排队中,多看视频优先提现');
- }
- return;
- }
- mk.data.sendDataEvent(DataEventId.guideToWx, `领取${gData.guideToWxData.money}元`);
- gData.receiptNotice.receip_rmb = parseFloat(gData.guideToWxData.money);
- mk.ui.openPanel('module/receiptNotice/receiptNotice');
- gData.guideToWxData.guideState = GuideState.gotMoney;
- this.setState();
- }
- else if (gData.guideToWxData.guideState == GuideState.gotMoney) {
- mk.tip.pop('您已经领取成功!', 1);
- }
- }
- clickClose() {
- mk.audio.playEffect('button');
- mk.ui.closePanel(this.node.name);
- }
- onDisable() {
- mk.audio.setResumeMusic();
- this.videoPlayer.node.off("completed", this.onCompleted, this);
- }
- onCompleted() {
- this.videoPlayer.play();
- }
- }
|