123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- const Api = require('../net/Api');
- cc.Class({
- extends: cc.Component,
- properties: {
- questNode: cc.Node,
- questFrames: {
- tooltip: '任务图标',
- default: [],
- type: [cc.SpriteFrame],
- },
- questBtns: [cc.Node],
- giftNode: {
- tooltip: '奖励图标节点',
- default: null,
- type: cc.Node
- },
- giftCounts: {
- tooltip: '奖励数量',
- default: null,
- type: cc.Label
- },
- giftFrames: {
- tooltip: '奖励图片素材',
- default: [],
- type: [cc.SpriteFrame]
- },
- questTitle: {
- tooltip: '任务标题',
- default: null,
- type: cc.Label
- },
- questDetail: {
- tooltip: '任务内容',
- default: null,
- type: cc.Label
- },
- questAct: {
- tooltip: '活跃度奖励',
- default: null,
- type: cc.Label
- }
- },
- onLoad () {
- this.giftMap = ['diamond', 'coin', 'ticket']
- },
- start () {
- },
-
- init (parent, task, questIndex) {
- this.parent = parent
- this.quest = parent.quest
- this.task = task
- this.questIndex = questIndex
- this.questBtns[task.state].active = true
-
- this.questNode.getComponent('cc.Sprite').spriteFrame = this.questFrames[this.questIndex]
-
- this.questTitle.string = task.title
-
- this.questDetail.string = task.desc
-
- this.questAct.string = `活跃度 + ${task.degree}`
-
- this._setGift()
- },
-
- _setGift () {
- let _count = 0
- let _type = ''
- let _sprite = null
- this.giftMap.forEach((value, index) => {
- if(this.task[value] > 0) {
- _count = this.task[value]
- _type = value
- _sprite = this.giftFrames[index]
- }
- })
-
- this.giftNode.getComponent('cc.Sprite').spriteFrame = _sprite
- this.giftCounts.string = `x ${_count}`
- },
-
- handleGiftBtn () {
- Api.httpPost({
- url: "/daily/getDailyTaskReward",
- data: {
- id: this.task.id
- },
- success: (res) => {
-
- this.quest.updateUserInfo(this.task.coin, this.task.diamond, this.task.ticket)
-
-
- this.parent.updateStatus(this.task)
- this.questBtns[this.task.state].active = false;
- this.questBtns[2].active = true;
-
- this.quest.showActGift({
- ticket: this.task.ticket,
- diamond: this.task.diamond,
- coin: this.task.coin
- })
- },
- fail: () => {
-
- }
- })
- }
- });
|