123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import HTTPS, { NetGet, NetPost } from "./HTTPS";
- import Tips from "./Tips";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class Task extends cc.Component {
- @property(cc.Node)
- Content: cc.Node = null;
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- this.Content.active = false
- let Close = this.node.getChildByName("Close")
- vv.deleteBtnEvent(Close, this)
- vv.addBtnEvent(Close, () => {
- this.node.active = false
- }, this)
- }
- protected onEnable(): void {
- this.getTask()
- }
- getTask() {
- HTTPS.Instance.get(NetGet.Task).then(res => {
- if (res.code != 200) {
- Tips.Instance.show(res.msg)
- return
- }
- let item: cc.Node = null
- for (const key in res.data) {
- if (Object.prototype.hasOwnProperty.call(res.data, key)) {
- const element = res.data[key];
- switch (key) {
- case 'ad_watch':
- item = this.Content.getChildByName(key)
- item.getChildByName("title").getComponent(cc.Label).string = element.title
- item.getChildByName("reward").getComponent(cc.Label).string = `${element.reward_min}-${element.reward_max}元`
- //对接广告
- vv.deleteBtnEvent(item, this)
- vv.addBtnEvent(item, () => {
- // this.setTask(key)
- Tips.Instance.show('等待对接广告')
- }, this)
- break;
- case 'sign_in':
- item = this.Content.getChildByName(key)
- item.getChildByName("title").getComponent(cc.Label).string = element.title
- item.getChildByName("reward").getComponent(cc.Label).string = `${element.reward}元`
- //每日签到人物
- vv.deleteBtnEvent(item, this)
- vv.addBtnEvent(item, () => {
- this.setTask(key)
- }, this)
- break;
- default:
- break;
- }
- }
- }
- this.Content.active = true
- })
- }
- submitTask() {
- Tips.Instance.show('等待对接广告')
- }
- setTask(_task_type) {
- HTTPS.Instance.post(NetPost.complete, {
- task_type: _task_type,
- }).then(res => {
- if (res.code != 200) {
- Tips.Instance.show(res.msg)
- return
- }
- Tips.Instance.show(res.data.message)
- })
- }
- // update (dt) {}
- }
|