import { _decorator, Color, Component, Label, Node, Sprite, SpriteFrame } from 'cc'; import { base_ui } from '../../fw/base_ui'; import { http } from '../../http'; import { config } from '../../config'; import { sign_reward } from './sign_reward'; import { sign_total_reward } from './sign_total_reward'; import { sign_reward_data, sign_total_reward_data } from '../../data'; import { sign_receive_reward } from './sign_receive_reward'; import { GameManager } from '../../GameManager'; const { ccclass, property } = _decorator; @ccclass('sign_view') export class sign_view extends base_ui { @property(Node) public_bg:Node = null @property(Node) reward_node:Node = null @property(Node) total_reward_node:Node = null @property(Node) btn_sign:Node = null @property(Node) lab_sign:Node = null @property(SpriteFrame) sf_btn_sign_qd:SpriteFrame = null // 签到 @property(SpriteFrame) sf_btn_sign_yqd:SpriteFrame = null // 已签到 @property(Node) receive_reward:Node = null private m_today_data:sign_reward_data = null start() { this.onButtonListen(this.public_bg, ()=>{ this.close() }) this.onButtonListen(this.btn_sign, ()=>{ this.requestUserSign() }) this.btn_sign.active = false GameManager.requestDelay(()=>{ this.requestSignListData() }) } private requestSignListData() { http.post(config.API.sign_list,null,(err,d)=>{ if(!err){ let nd = JSON.parse(d) if(nd.code === config.status.SUCCESS){ // console.log("sign_list", nd.content) let total_sign_number = nd.content.total_sign_number this.reward_node.getComponent(sign_reward).initView(nd.content.sign_reward_list,this.onRewardCallBack.bind(this),this.onClickRewardItem.bind(this)) this.total_reward_node.getComponent(sign_total_reward).initView(total_sign_number, nd.content.sign_total_reward_list,this.onClickTotalRewardItem.bind(this)) } } },'GET') } private onRewardCallBack(today_data:sign_reward_data) { this.m_today_data = today_data if(today_data.receive_status==0) { this.btn_sign.getComponent(Sprite).spriteFrame = this.sf_btn_sign_qd this.lab_sign.getComponent(Label).color = new Color().fromHEX("#A3511B") this.lab_sign.getComponent(Label).string = '签 到' } else { this.btn_sign.getComponent(Sprite).spriteFrame = this.sf_btn_sign_yqd this.lab_sign.getComponent(Label).color = new Color().fromHEX("#464646") this.lab_sign.getComponent(Label).string = '今日已签到' } this.btn_sign.active = true } private onClickRewardItem(data:sign_reward_data,is_buqian:boolean) { let call_back = (()=>{ this.showReceiveReward(data) }) if(is_buqian) { GameManager.showVideoAd(config.ADS_TYPE.GAME_SIGN_BUQIAN, (res)=>{ call_back() }) } else { call_back() } } private onClickTotalRewardItem(data:sign_total_reward_data) { this.receive_reward.active = true this.receive_reward.getComponent(sign_receive_reward).initReceiveSuccess(data) this.requestSignListData() } private requestUserSign() { if(this.m_today_data.receive_status==1) { return } this.showReceiveReward(this.m_today_data) } private showReceiveReward(data:sign_reward_data) { this.receive_reward.active = true this.receive_reward.getComponent(sign_receive_reward).initView(data, (v:sign_receive_reward)=>{ this.requestSignListData() }) } }