123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- const Api = require('../net/Api');
- cc.Class({
- extends: cc.Component,
- properties: {
- questItem: {
- default: null,
- type: cc.Node,
- },
- questWrap: {
- tooltip: '每日任务容器',
- default: null,
- type: cc.Node
- },
- actGifts: {
- tooltip: '活跃度奖励节点',
- default: [],
- type: [cc.Node]
- },
- actGiftSprite: {
- tooltip: '活跃度奖励素材',
- default: [],
- type: [cc.SpriteFrame]
- },
- actProgress: {
- tooltip: '每日活跃度进度',
- default: null,
- type: cc.ProgressBar
- },
- userDegreeLabel: {
- tooltip: '用户当前活跃度',
- default: null,
- type: cc.Label
- },
- _userDegree: 0,
- userDegree: {
- get () {
- return this._userDegree
- },
- set (data) {
- this._userDegree = data
-
- this.actProgress.progress = data / 100
- this.userDegreeLabel.string = data
- }
- }
- },
- onLoad () {
- this.userDegree = 0
- this.dailyDegreeList = []
- },
- init (quest) {
- this.quest = quest
- this.questItem.active = false
- Api.httpGet({
- url: "/daily/getUserDailyInfo",
- data: {},
- success: ({dailyDegreeList, dailyTaskList, userDegree}) => {
- this.dailyDegreeList = dailyDegreeList.sort((a, b) => {
- return a.degree - b.degree
- })
- this.dailyTaskList = dailyTaskList
- this.userDegree = parseInt(userDegree)
-
- this._setDegreeList()
- this._setTaskList()
- }
- })
- },
-
- _setTaskList () {
- this.dailyTaskList.forEach((item, index) => {
- let questItem = cc.instantiate(this.questItem)
- this.questWrap.addChild(questItem)
- questItem.active = true
- questItem.getComponent('QuestDailyItem').init(this, item, index)
- })
- },
-
- _setDegreeList () {
- this.dailyDegreeList.forEach((item, index) => {
- let giftFrame = this.actGiftSprite[item.state]
- this.actGifts[index].getComponent('cc.Sprite').spriteFrame = giftFrame
- })
- },
- updateStatus (task) {
- let _degree = this.userDegree + parseInt(task.degree)
- this.userDegree = _degree > 100 ? 100 : _degree
- this.dailyDegreeList.forEach((item, index) => {
- if(this.userDegree >= item.degree && item.state != 2) {
- item.state = 0
- }
- let giftFrame = this.actGiftSprite[item.state]
- this.actGifts[index].getComponent('cc.Sprite').spriteFrame = giftFrame
- })
- },
-
- handleGiftBtn (event, index) {
- let act = this.dailyDegreeList[index]
-
-
- if(act.state == 0) {
- Api.httpPost({
- url: "/daily/getDailyDegreeReward",
- data: {
- degree: act.degree
- },
- success: (res) => {
-
- this.quest.updateUserInfo(act.coin, act.diamond, act.ticket)
-
- act.state = 2
-
- event.target.getComponent('cc.Sprite').spriteFrame = this.actGiftSprite[2]
-
-
- setTimeout(() => {
- this.quest.showActGift({
- ticket: act.ticket,
- diamond: act.diamond,
- coin: act.coin
- })
- }, 200);
- },
- fail: () => {
-
-
- }
- })
- }
- },
- start () {
- }
- });
|