Task.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import HTTPS, { NetGet, NetPost } from "./HTTPS";
  8. import Tips from "./Tips";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class Task extends cc.Component {
  12. @property(cc.Node)
  13. Content: cc.Node = null;
  14. // LIFE-CYCLE CALLBACKS:
  15. onLoad() {
  16. this.Content.active = false
  17. let Close = this.node.getChildByName("Close")
  18. vv.deleteBtnEvent(Close, this)
  19. vv.addBtnEvent(Close, () => {
  20. this.node.active = false
  21. }, this)
  22. }
  23. protected onEnable(): void {
  24. this.getTask()
  25. }
  26. getTask() {
  27. HTTPS.Instance.get(NetGet.Task).then(res => {
  28. if (res.code != 200) {
  29. Tips.Instance.show(res.msg)
  30. return
  31. }
  32. let item: cc.Node = null
  33. for (const key in res.data) {
  34. if (Object.prototype.hasOwnProperty.call(res.data, key)) {
  35. const element = res.data[key];
  36. switch (key) {
  37. case 'ad_watch':
  38. item = this.Content.getChildByName(key)
  39. item.getChildByName("title").getComponent(cc.Label).string = element.title
  40. item.getChildByName("reward").getComponent(cc.Label).string = `${element.reward_min}-${element.reward_max}元`
  41. //对接广告
  42. vv.deleteBtnEvent(item, this)
  43. vv.addBtnEvent(item, () => {
  44. // this.setTask(key)
  45. Tips.Instance.show('等待对接广告')
  46. }, this)
  47. break;
  48. case 'sign_in':
  49. item = this.Content.getChildByName(key)
  50. item.getChildByName("title").getComponent(cc.Label).string = element.title
  51. item.getChildByName("reward").getComponent(cc.Label).string = `${element.reward}元`
  52. //每日签到人物
  53. vv.deleteBtnEvent(item, this)
  54. vv.addBtnEvent(item, () => {
  55. this.setTask(key)
  56. }, this)
  57. break;
  58. default:
  59. break;
  60. }
  61. }
  62. }
  63. this.Content.active = true
  64. })
  65. }
  66. submitTask() {
  67. Tips.Instance.show('等待对接广告')
  68. }
  69. setTask(_task_type) {
  70. HTTPS.Instance.post(NetPost.complete, {
  71. task_type: _task_type,
  72. }).then(res => {
  73. if (res.code != 200) {
  74. Tips.Instance.show(res.msg)
  75. return
  76. }
  77. Tips.Instance.show(res.data.message)
  78. })
  79. }
  80. // update (dt) {}
  81. }