import { _decorator, Component, ProgressBar, Label } from 'cc'; import { Http } from '../../core/net/Http'; import { BitmapFont } from '../../core/ui/BitmapFont'; import { WindowManager } from '../../core/ui/window/WindowManager'; import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode'; import { g } from '../../Data/g'; import { platform } from '../../Data/platform'; import { ChildItem } from './ChildItem'; const { ccclass, property } = _decorator; @ccclass('InviteWindow') export class InviteWindow extends Component { @property({ type: Http, tooltip: "http组件" }) http: Http; @property({ type: BitmapFont, tooltip: "金额文本" }) moneyLabel: BitmapFont; @property({ type: [ChildItem], tooltip: "泡泡集合" }) paopaos: Array = []; @property({ type: ProgressBar, tooltip: "我的金额进度条" }) moneyProgress: ProgressBar; @property({ type: Label, tooltip: "约等于文本" }) aboutLabel: Label; private memberData: any; private parentData: { nickName: string, avatar: string, uid: string } = { nickName: "", avatar: "", uid: "" }; private nowReceive = -1; private revenueData = []; // private testData = { "code": 0, "data": { "memberDatas": { "g1Members": [{ "userID": 100034, "avatar": "", "nickname": "测试32", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100043, "avatar": "", "nickname": "测试31", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100044, "avatar": "", "nickname": "测试32", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100201, "avatar": "", "nickname": "测试100201", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100211, "avatar": "", "nickname": "测试100211", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }], "g2Members": [{ "userID": 100046, "avatar": "", "nickname": "测试34", "revenueAmount": 0, "gameWithdrawAmount": 0 }, { "userID": 100202, "avatar": "", "nickname": "测试100202", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100212, "avatar": "", "nickname": "测试100212", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }], "g3Members": [{ "userID": 100203, "avatar": "", "nickname": "测试100203", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100213, "avatar": "", "nickname": "测试100213", "revenueAmount": 0, "gameWithdrawAmount": 0 }], "g4Members": [{ "userID": 100204, "avatar": "", "nickname": "测试100204", "revenueAmount": 0, "gameWithdrawAmount": 0 }, { "userID": 100214, "avatar": "", "nickname": "测试100214", "revenueAmount": 0, "gameWithdrawAmount": 0 }], "g5Members": [{ "userID": 100205, "avatar": "", "nickname": "测试100205", "revenueAmount": 0, "gameWithdrawAmount": 0 }], "parentUin": "", "parentAvatar": "", "parentNickname": "" } } } async start() { let result = await this.http.send("/api/fission/GetFission", {}); if (result.code == 0) { this.memberData = result.data.memberDatas;//this.testData.data.memberDatas;// this.parentData = { nickName: result.data.memberDatas.parentNickname, avatar: result.data.memberDatas.parentAvatar, uid: result.data.memberDatas.parentUin }; for (let i = 1; i < 6; i++) { let gData = this.memberData[`g${i}Members`]; for (let j = 0; j < gData.length; j++) { if (gData[j].revenueAmount > 0) { this.revenueData.push(gData[j]); } } } this.onChildTweenOver(); } } update() { if (this.nowReceive != g.userData.contribution) { this.nowReceive = g.userData.contribution; this.moneyLabel.string = !!g.userData.contribution ? g.userData.contribution + "" : "0"; this.moneyProgress.progress = (g.userData.contribution / 10000 / 10) <= 1 ? (g.userData.contribution / 10000 / 10) : 1; this.aboutLabel.string = `约${(g.userData.contribution / 10000).toFixed(2)}元`; } } public onChildTweenOver(): void { for (let i = 0; i < this.paopaos.length; i++) { if (!this.paopaos[i].node.active && this.revenueData.length > 0) { this.paopaos[i].setData(this.revenueData.shift()); } } } public async oneKeyGet() { let canOneKey = false; for (let i = 0; i < this.paopaos.length; i++) { if (this.paopaos[i].node.active) { canOneKey = true; break; } } if (canOneKey) { let result = await this.http.send("/api/fission/ReceiveFission", { receiveUserID: 0 }); if (result.code == 0) { platform.reportThinking("invite", JSON.stringify({ current_amount: g.userData.contribution, after_amount: g.userData.contribution + result.data.addTotalContribution })); g.userData.contribution += result.data.addTotalContribution; this.revenueData = []; for (let i = 0; i < this.paopaos.length; i++) { if (this.paopaos[i].node.active) { await this.paopaos[i].getComponent(ChildItem).doTween(); } } } } else { WindowManager.showTips("暂时没有贡献可领取"); } } public async withDraw() { if (g.userData.contribution >= 0.3 * 10000) { let result = await this.http.send("/api/user/withdraw", { type: 1 }); if (result.code === 0 && !result.message) { WindowManager.showTips("提现成功"); g.userData.contribution = 0; } else if (result.message) { WindowManager.showTips(result.message); } else { WindowManager.showTips("网络异常,请稍候再试"); } } else { WindowManager.showTips("提现金额不足0.3元"); } } public moreFriend(): void { WindowManager.open("Prefabs/InviteWindow/ChildrenListWindow", WindowOpenMode.NotCloseAndAdd, this.memberData); } public myTeacher(): void { if (this.parentData.uid != "") { WindowManager.open("Prefabs/InviteWindow/InviteTeacherWIndow", WindowOpenMode.NotCloseAndAdd, this.parentData); } else { WindowManager.showTips("您没有上级"); } } public async share() { let result = await this.http.send("/api/app/share", {}); if (result.code == 0) { platform.reportThinking("invite", JSON.stringify({ upper_class: this.parentData.uid })); platform.wxShare(result.data.url, result.data.title, result.data.descroption); } else { WindowManager.showTips("分享信息获取失败,请稍后再试"); } } }