import MoneySaveItem from "./MoneySaveItem"; const { ccclass, property } = cc._decorator; @ccclass export default class SafeDepositBox extends cc.Component { @property(cc.Node) content: cc.Node = null @property(cc.Label) totalMoneyLabel: cc.Label = null @property(cc.Label) readyTixianLabel: cc.Label = null @property(cc.Button) readyTixianBtn: cc.Button = null @property(cc.Node) weitixianNode: cc.Node = null @property(cc.Node) tixianzhongNode: cc.Node = null @property(cc.Label) tixianzhongMoneyLabel: cc.Label = null @property(cc.Node) confirmTixianNode: cc.Node = null @property(cc.Node) saveNode: cc.Node = null @property(cc.Node) tixianTask: cc.Node = null @property(cc.RichText) loginProgress: cc.RichText = null @property(cc.RichText) playVideoProgress: cc.RichText = null @property(cc.Label) tipLogin: cc.Label = null @property(cc.Label) tipPlayVideo: cc.Label = null @property(cc.Node) safeBox: cc.Node = null @property(cc.Node) tipNode: cc.Node = null @property(cc.Node) completeNode: cc.Node = null @property(cc.Node) inCompleteNode: cc.Node = null @property(cc.Node) completeBtn: cc.Node = null @property(cc.Node) logDaysNode: cc.Node = null @property(cc.Node) videoTimesNode: cc.Node = null @property(cc.Node) saveSuccessNode: cc.Node = null @property(cc.Label) confirmMoneyLabel: cc.Label = null @property([cc.SpriteFrame]) boxSfLsit: cc.SpriteFrame[] = [] @property(cc.Sprite) boxSprite: cc.Sprite = null @property(cc.Node) ruleNode: cc.Node = null @property(cc.Node) boxNode: cc.Node = null @property(sp.Skeleton) openDraw: sp.Skeleton = null @property([cc.Node]) taskStartNodeList: cc.Node[] = [] @property(cc.Node) noPacketTip: cc.Node = null // 提现部分 @property(cc.Label) labMoeny: cc.Label = null @property(cc.Node) cashPro: cc.Node = null @property(cc.Node) loadPart: cc.Node = null @property(cc.Animation) spot1: cc.Animation = null @property(cc.Label) rulelabel: cc.Label = null @property([cc.SpriteFrame]) spriteFrameList: cc.SpriteFrame[] = [] @property(cc.Node) labRedCode: cc.Node = null @property(cc.Label) labDes: cc.Label = null addNum = 0 addTotal = 0 itemP = null _n = 0 _dis = 5 animNode: cc.Node = null private startTixian: number = 0 private test = false nodePos = [cc.v3(54, -63), cc.v3(313, 57), cc.v3(572, -67), cc.v3(862, -67)] private packet = [{ "amount": 3.3, "isSaveBank": 0, "partnerTradeNo": "a", "cashType": 1 }, { "amount": 500, "isSaveBank": 0, "partnerTradeNo": "a", "cashType": 1 }, { "amount": 330, "isSaveBank": 0, "partnerTradeNo": "a", "cashType": 1 }] async start() { if (!this.test) { let response = await mk.http.sendData('richbank/getCashRecord', {}); mk.console.logSingle('getCashRecord ', response); if (response && response.errcode == 0) { this.updateScrollView(response.data); } if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) { let response = await mk.http.sendData('richbank/getRichBankInfo', {}); mk.console.logSingle('getRichBankInfo ', response); if (response && response.errcode == 0) { if (response.data.richBankDailyVideoTimes >= 0) { gData.safeDepositBoxData.richBankDailyVideoTimes = response.data.richBankDailyVideoTimes; } if (response.data.richbankLoginDays >= 0) { gData.safeDepositBoxData.richbankLoginDays = response.data.richbankLoginDays; if (gData.safeDepositBoxData.richbankLoginDays == 0) { gData.safeDepositBoxData.richbankLoginDays = 1; } } gData.safeDepositBoxData.richBankDailyTotelVideoTimes = response.data.richBankDailyTotelVideoTimes; this.setTaskProgress(); } } } this.initView() if (this.test) { this.updateScrollView(this.packet) } } initView(showStep = false) { let money: number = gData.safeDepositBoxData.richBankCashAmount if (money == null || undefined) { money = 0 } this.startTixian = gData.safeDepositBoxData.currentRichBankCashTaskIndex if (this.startTixian > 0) { this.weitixianNode.active = false this.tixianzhongNode.active = true let config = gData.safeDepositBoxData.getBankTaskIndex() this.tixianzhongMoneyLabel.string = (config.money * 0.01).toFixed(2) + "元" this.readyTixianLabel.node.active = false this.tixianzhongNode.getChildByName("tixianLabel").active = true this.tixianTask.active = true this.labRedCode.active = false this.saveNode.active = true this.setTaskProgress() this.boxSprite.spriteFrame = this.boxSfLsit[1] if (showStep) { this.showInfoByStep() } this.noPacketTip.getChildByName("taskLabel").active = gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0 this.noPacketTip.getChildByName("noTaskLabel").active = !(gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) } else { this.tixianzhongNode.active = false this.weitixianNode.active = true this.readyTixianLabel.node.active = true this.totalMoneyLabel.string = (money * 0.01).toFixed(2) + "元" this.content.active = true this.tixianTask.active = false // this.labRedCode.active = true this.labRedCode.active = false; this.saveNode.active = true this.completeBtn.active = false this.checkCurrentCanStartTask(money) this.boxSprite.spriteFrame = this.boxSfLsit[0] } } async updateScrollView(data) { mk.console.logSingle("updateScrollView", data) this.content.destroyAllChildren() if (data == null || data == undefined) { this.showNoPacket() return } if (!(data.length > 0)) { this.showNoPacket() return } this.noPacketTip.active = false this.noPacketTip.stopAllActions() this.noPacketTip.position = cc.v3(324, -10) let count = 0 let startTixian = gData.safeDepositBoxData.currentRichBankCashTaskIndex; let showFinger: boolean = startTixian > 0 this.itemP = await mk.loader.load('module/safeDepositBox/prefabs/MoneySaveItem', cc.Prefab); for (let entry of data) { // if (entry.isSaveBank != 0) { // continue // } count++ if (count > 5) { break } let info = entry if (info == null || info == undefined) { break } let item: cc.Node = cc.instantiate(this.itemP) let s = item.getComponent(MoneySaveItem) item.parent = this.content s.init(info, showFinger, this.clickItemEvent.bind(this), count) } } //将提现金额放入保险箱 async clickItemEvent(data, node) { mk.audio.playEffect('button'); if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) { mk.tip.pop("提现后可存入") return } this.animNode = node if (this.test) { gData.safeDepositBoxData.richBankCashAmount = gData.safeDepositBoxData.richBankCashAmount + data.amount; this.saveMoneySuccess(gData.safeDepositBoxData.richBankCashAmount); } else { let response = await mk.http.sendData('richbank/updateCashRecord', { "partnerTradeNo": data.partnerTradeNo }) if (response && response.errcode == 0) { gData.safeDepositBoxData.richBankCashAmount = response.data.RichBankCashAmount; this.saveMoneySuccess(gData.safeDepositBoxData.richBankCashAmount); } } } saveMoneySuccess(money) { mk.data.sendDataEvent("Bank", "银行-点击存入") this.showAnim(this.animNode) this.totalMoneyLabel.string = ((money * 0.01).toFixed(2)) + "元" this.checkCurrentCanStartTask(money) gData.safeDepositBoxData.updateQipao(); } //存入宝箱中的数据和动画处理 async showAnim(itemNode: cc.Node) { itemNode.stopAllActions() let startWorldPos = itemNode.parent.convertToWorldSpaceAR(itemNode.position) let startPos = this.node.convertToNodeSpaceAR(startWorldPos) let worldEndPos = this.safeBox.parent.convertToWorldSpaceAR(this.safeBox.position) itemNode.parent = this.node itemNode.position = startPos let movePos = this.node.convertToNodeSpaceAR(worldEndPos) itemNode.runAction(cc.sequence(cc.spawn(cc.moveTo(1, cc.v2(movePos)), cc.scaleTo(1, 0.4), cc.fadeTo(1, 180)), cc.callFunc(async () => { mk.audio.playEffect('saveSuccess'); this.openDraw.node.active = true this.openDraw.setAnimation(0, 'animation', false) this.saveSuccessNode.runAction(cc.sequence(cc.scaleTo(0.2, 1), cc.delayTime(0.5), cc.scaleTo(0.1, 0))) if (cc.isValid(itemNode)) { itemNode.destroy() } if (this.test) { this.updateScrollView(this.packet) } else { let response = await mk.http.sendData('richbank/getCashRecord', {}); if (response && response.errcode == 0) { this.updateScrollView(response.data); } } }))) } //点提现按钮 readyTixian() { mk.audio.playEffect('button'); let minConfig = null; if (gData.safeDepositBoxData.currentRichBankCashTaskIndex == 0) { minConfig = gData.safeDepositBoxData.getBankTaskIndex(true); } else { minConfig = gData.safeDepositBoxData.getBankTaskIndex(); } let richBankCashAmount = gData.safeDepositBoxData.richBankCashAmount if (minConfig == null || minConfig == undefined) { return } let minMoney: number = minConfig.money let showMoney = Math.floor(minMoney / 100) > 0 ? (minMoney / 100) + "" : (minMoney / 100).toFixed(2) if (richBankCashAmount < minMoney) { mk.tip.pop("存款达到" + showMoney + "元可提现哦") return } let totaldays = minConfig.loginTimes // let totalVideoTimes = minConfig.videotimes this.tipLogin.string = "1、连续登陆" + totaldays + "天" this.tipPlayVideo.string = "2、每天观看指定数量的视频" this.confirmMoneyLabel.string = Math.floor(minConfig.money / 100) > 0 ? (minConfig.money / 100) + "元" : (minConfig.money / 100).toFixed(2) + "元" let y = this.boxNode.y let x = this.boxNode.x let delayTime = Math.random() this.scheduleOnce(() => { this.boxNode.runAction(cc.repeatForever(cc.sequence(cc.moveTo(1.5, cc.v2(x, y - 5)), cc.moveTo(1.2, cc.v2(x, this.node.y + 5))))) }, delayTime) this.confirmTixianNode.active = true this.saveNode.active = true this.content.active = false this.readyTixianLabel.node.active = false } //点开始任务 async confirmStartTixian() { mk.audio.playEffect('button'); let config = gData.safeDepositBoxData.getBankTaskIndex(true); if (!config) { mk.console.logSingle("SafeDepositBox", "can not confirmStartTixian") return } this.confirmTixianNode.active = false this.boxNode.stopAllActions() this.boxNode.x = 161 this.boxNode.y = 0 this.content.active = true if (this.test) { this.updateBankTask(1); } else { let response = await mk.http.sendData('richbank/openCashTask', { "index": config.index }); mk.console.logSingle('openCashTask ', response); if (response && response.errcode == 0) { gData.safeDepositBoxData.richBankDailyTotelVideoTimes = response.data.richBankDailyTotelVideoTimes; this.updateBankTask(config.index); } } } updateBankTask(index) { gData.safeDepositBoxData.currentRichBankCashTaskIndex = index; gData.safeDepositBoxData.addRichBankFinishIndex = gData.safeDepositBoxData.currentRichBankCashTaskIndex; gData.safeDepositBoxData.richbankLoginDays = 1 gData.safeDepositBoxData.richBankDailyVideoTimes = 0 mk.storage.setStorage("bankTaskStartTime", Date.now()) this.initView(true) mk.data.sendDataEvent("Bank", "开始任务") gData.safeDepositBoxData.freshQipao = true; } startTixianTask() { this.startTixian = 1 this.totalMoneyLabel.string = (gData.safeDepositBoxData.richBankCashAmount) + "元 提现中..." this.confirmTixianNode.active = false this.saveNode.active = true this.tixianTask.active = true this.labRedCode.active = false this.content.active = true this.readyTixianLabel.node.active = false } showCompleteNode() { mk.storage.setStorage("showBankTaskSuccess", Date.now() + "") this.tipNode.active = true this.tipNode.getChildByName("tipNode").active = true this.tipNode.getChildByName("tipNode").scale = 0; this.completeNode.active = true this.inCompleteNode.active = false cc.tween(this.tipNode.getChildByName("tipNode")).to(0.3, { scale: 1 }, { easing: "backOut" }).start(); } showRestartTaskNode() { mk.storage.setStorage("showBankTaskRestart", Date.now() + "") this.tipNode.active = true this.tipNode.getChildByName("tipNode").active = true this.tipNode.getChildByName("tipNode").scale = 0; this.completeNode.active = false this.inCompleteNode.active = true cc.tween(this.tipNode.getChildByName("tipNode")).to(0.3, { scale: 1 }, { easing: "backOut" }).start(); mk.data.sendDataEvent("Bank", "银行-任务进度重置") } hideCompleteTipNode() { this.tipNode.active = false this.tipNode.getChildByName("tipNode").active = false } hideConfirmTixianNode() { mk.audio.playEffect('button'); this.confirmTixianNode.active = false this.saveNode.active = true this.content.active = true this.readyTixianLabel.node.active = true this.boxNode.stopAllActions() this.boxNode.x = 161 this.boxNode.y = 0 } //设置提现按钮状态 checkCurrentCanStartTask(money) { console.log("checkCurrentCanStartTask money:" + money) let minConfig = null; if (gData.safeDepositBoxData.currentRichBankCashTaskIndex == 0) { minConfig = gData.safeDepositBoxData.getBankTaskIndex(true); } else { minConfig = gData.safeDepositBoxData.getBankTaskIndex(); } console.log("checkCurrentCanStartTask minConfig.index:" + minConfig.index) this.readyTixianLabel.string = "" if (minConfig == null || minConfig == undefined) { this.readyTixianBtn.node.getComponent(cc.Sprite).spriteFrame = this.spriteFrameList[0] return } let outLine = this.readyTixianBtn.node.getChildByName("btnLabel").getComponent(cc.LabelOutline) let minMoney: number = minConfig.money let showMoney = Math.floor(minMoney / 100) > 0 ? (minMoney / 100) + "" : (minMoney / 100).toFixed(2) if (money >= minMoney) { console.log("checkCurrentCanStartTask minConfig.index: money >= minMoney") this.readyTixianBtn.node.getComponent(cc.Sprite).spriteFrame = this.spriteFrameList[0] this.readyTixianBtn.interactable = true outLine.color = cc.color(181, 140, 59) showMoney = Math.floor(minConfig.money / 100) > 0 ? (minConfig.money / 100) + "" : (minConfig.money / 100).toFixed(2) mk.guide.open(5); } else { console.log("checkCurrentCanStartTask minConfig.index: money < minMoney") this.readyTixianBtn.node.getComponent(cc.Sprite).spriteFrame = this.spriteFrameList[1] outLine.color = cc.Color.GRAY } this.readyTixianBtn.node.getChildByName("btnLabel").getComponent(cc.Label).string = "提现" + showMoney + "元" } async clickLingqu() { mk.audio.playEffect('button'); let config = gData.safeDepositBoxData.getBankTaskIndex() this.labMoeny.string = "¥" + (config.money * 0.01).toFixed(2) if (this.test) { this.updateBankCash(null) } else { this.loadPart.active = true this.spot1.play('load', 0); let response = await mk.http.sendData('richbank/richbankcash', { "index": config.index, 'appVersion': gData.appData.appVersion }); if (response) { if (response.errcode == 0) { this.updateBankCash(response.data); } else { this.loadPart.active = false; if (response.data.count) { gData.tipPanelData.openCashFailTip(response.data.count); } else { mk.tip.pop('提现排队中,多看视频优先提现'); } } } } } updateBankCash(data) { mk.console.logSingle("updateBankCash", data) let cashMoney = 0 let len = gData.safeDepositBoxData.richBankConfig.length for (var i = 0; i < len; i++) { if (gData.safeDepositBoxData.richBankConfig[i].index == gData.safeDepositBoxData.currentRichBankCashTaskIndex) { cashMoney = Number((gData.safeDepositBoxData.richBankConfig[i].money * 0.01).toFixed(2)) break } } gData.safeDepositBoxData.currentRichBankCashTaskIndex = 0 gData.safeDepositBoxData.richbankLoginDays = 1 gData.safeDepositBoxData.richBankDailyVideoTimes = 0 //计算提现后,银行内剩余的 let currentConfig = gData.safeDepositBoxData.getBankTaskIndex() gData.safeDepositBoxData.richBankCashAmount = gData.safeDepositBoxData.richBankCashAmount - currentConfig.money if (gData.safeDepositBoxData.richBankCashAmount < 0) { gData.safeDepositBoxData.richBankCashAmount = 0 } mk.data.sendDataEvent("Bank", "银行-任务全部完成") this.tixianSuccess(true); gData.safeDepositBoxData.updateQipao(); //累计成功提现次数 mk.data.setTAEventUser(1, 'cash_time', 1); //累计提现金额 mk.data.setTAEventUser(1, 'cash_total', cashMoney); // if (data.CashMode == 2) { // gData.redCodeData.openRedCode(cashMoney, data.withdrawalCode); // mk.data.sendDataEvent('Bank', '公众号提现-富翁银行') // } } tixianSuccess(showPro) { this.loadPart.active = false if (showPro) { this.cashPro.active = true gData.adData.checkShowFullInter(1); } this.initView() } tixianFail() { this.loadPart.active = false mk.ui.hideUI(this.cashPro); } hideTixianNode() { mk.audio.playEffect('button'); mk.ui.hideUI(this.cashPro); } closeTixianNode() { mk.audio.playEffect('button'); mk.ui.hideUI(this.cashPro); } setTaskProgress() { let richBankDailyVideoTimes = gData.safeDepositBoxData.richBankDailyVideoTimes let richbankLoginDays = gData.safeDepositBoxData.richbankLoginDays let currentConfig = gData.safeDepositBoxData.getBankTaskIndex() if (currentConfig == null || currentConfig == undefined) { return } let totaldays = currentConfig.loginTimes let progress = "(" + richbankLoginDays + "/" + totaldays + ")" this.labDes.string = `连续完成${totaldays}日的每日任务即可提现\n任意一日未完成将重置提现进度`; this.loginProgress.string = "1.登陆游戏" if (richbankLoginDays < totaldays) { this.logDaysNode.getChildByName("labelNode").active = true this.logDaysNode.getChildByName("gou").active = false } else { this.logDaysNode.getChildByName("labelNode").active = false this.logDaysNode.getChildByName("gou").active = true } let totalVideoTimes = gData.safeDepositBoxData.richBankDailyTotelVideoTimes; let timeProgress = "(" + richBankDailyVideoTimes + "/" + totalVideoTimes + ")" this.playVideoProgress.string = "2.今日观看视频" + totalVideoTimes + "次" + timeProgress + "" if (richBankDailyVideoTimes < totalVideoTimes) {//没有完成视频次数 this.videoTimesNode.getChildByName("label").active = true this.videoTimesNode.getChildByName("label").getComponent(cc.Label).string = "进行中" this.videoTimesNode.getChildByName("label").color = cc.Color.GRAY this.videoTimesNode.getChildByName("gou").active = false } else { if (richbankLoginDays >= totaldays) { this.videoTimesNode.getChildByName("label").active = false this.videoTimesNode.getChildByName("gou").active = true } else { this.videoTimesNode.getChildByName("label").active = true this.videoTimesNode.getChildByName("label").getComponent(cc.Label).string = "今日已完成" this.videoTimesNode.getChildByName("label").color = cc.color(27, 188, 50) this.videoTimesNode.getChildByName("gou").active = false } } if (richbankLoginDays >= totaldays && richBankDailyVideoTimes >= totalVideoTimes) { this.completeBtn.active = true this.tixianzhongNode.getChildByName("tixianLabel").active = false this.tixianzhongNode.getChildByName("labPro").active = false } else { this.completeBtn.active = false this.tixianzhongNode.getChildByName("tixianLabel").active = true this.tixianzhongNode.getChildByName("labPro").active = true } this.tixianzhongNode.getChildByName("labPro").getComponent(cc.Label).string = progress this.tixianzhongNode.getChildByName("spPro").getComponent(cc.Sprite).fillRange = richbankLoginDays / totaldays //提示完成任务 if (richBankDailyVideoTimes >= totalVideoTimes) { // totalVid let lastDateStr = mk.storage.getStorage("showBankTaskSuccess") if (lastDateStr != null && lastDateStr != undefined) { let lastDate = new Number(lastDateStr).valueOf() if (!this.checkSameDay(lastDate)) { this.scheduleOnce(() => { this.showCompleteNode() }, 0.3) } } else { this.scheduleOnce(() => { this.showCompleteNode() }, 0.3) } } //提示任务中断 if (richbankLoginDays <= 1) { //任务中断的情况 let showBankTaskRestart = mk.storage.getStorage("showBankTaskRestart") let same = this.checkSameDay(new Number(showBankTaskRestart).valueOf()) let bankTaskStartTime = mk.storage.getStorage("bankTaskStartTime") let startTimeSame = this.checkSameDay(new Number(bankTaskStartTime).valueOf()) if (!same && !startTimeSame) { this.scheduleOnce(() => { this.showRestartTaskNode() }, 0.3) } } } clickRule() { mk.audio.playEffect('button'); // if (this.lock) { // return // } this.ruleNode.active = true let config = gData.safeDepositBoxData.getBankTaskIndex() let money = config.money let showMoney = Math.floor(money / 100) > 0 ? (money / 100) + "" : (money / 100).toFixed(2) this.rulelabel.string = "2、存入金额达到" + showMoney + "元可开启提现" } clickCloseRule() { mk.audio.playEffect('button'); this.ruleNode.active = false } /** * 当前时间和目标时间是否是同一天 * @param targetTime 记录的时间戳 */ checkSameDay(targetTime: number): boolean { let currentDay = new Date().getDate() let lastData = new Date(targetTime).getDate() if (currentDay == lastData) { return true } return false } showInfoByStep() { let count = 0 for (let entry of this.taskStartNodeList) { // entry.opacity= 0 entry.scale = 0 } let array = new Array() for (let i = 0; i < this.taskStartNodeList.length; i++) { array.push(this.taskStartNodeList[this.taskStartNodeList.length - i - 1]) } this.schedule(() => { if (cc.isValid(array[count])) { if (array[count].name == "contentnode" || array[count].name == "emptyNode") { array[count].scale = 1 array[count].opacity = 0 array[count].runAction(cc.fadeIn(1)) } else { array[count].runAction(cc.sequence(cc.scaleTo(0.15, 1.2), cc.scaleTo(0.1, 1))) } } count++ }, 0.2, array.length) } clickBoxShowTip() { mk.audio.playEffect('button'); let config = gData.safeDepositBoxData.getBankTaskIndex() let money = config.money let showMoney = Math.floor(money / 100) > 0 ? (money / 100) + "" : (money / 100).toFixed(2) let str = "存款达到" + showMoney + "元可提现哦" if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) { str = "完成任务可提现,加油哦!" } mk.tip.pop(str) } showNoPacket() { this.noPacketTip.getChildByName("taskLabel").active = gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0 this.noPacketTip.getChildByName("noTaskLabel").active = !(gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) this.noPacketTip.active = true let moveNode = this.noPacketTip let x = moveNode.x let y = moveNode.y moveNode.runAction(cc.repeatForever(cc.sequence(cc.moveTo(1.5, cc.v2(x, y - 5)), cc.moveTo(1.5, cc.v2(x - 5, y - 5)), cc.moveTo(1.2, cc.v2(x, y + 5))))) } }