sign_receive_reward.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { _decorator, Component, Label, Node, Sprite } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { sign_reward_data } from '../../data';
  4. import { tools } from '../../tools';
  5. import { http } from '../../http';
  6. import { config } from '../../config';
  7. import { GameManager } from '../../GameManager';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('sign_receive_reward')
  10. export class sign_receive_reward extends base_ui {
  11. @property(Node) public_bg:Node = null
  12. @property(Node) img_icon:Node = null
  13. @property(Node) lab_name:Node = null
  14. @property(Node) lab_count:Node = null
  15. @property(Node) btn_receive:Node = null
  16. @property(Node) btn_double:Node = null
  17. private m_data:sign_reward_data = null
  18. private m_cb = null
  19. start() {
  20. this.onButtonListen(this.public_bg, ()=>{
  21. this.node.active = false
  22. })
  23. this.onButtonListen(this.btn_receive, ()=>{
  24. this.requestUserSign(false)
  25. })
  26. this.onButtonListen(this.btn_double, ()=>{
  27. GameManager.showVideoAd(config.ADS_TYPE.GAME_SIGN_DOUBLE, (res)=>{
  28. this.requestUserSign(true)
  29. })
  30. })
  31. }
  32. initView(data:sign_reward_data, cb) {
  33. this.m_data = data
  34. this.m_cb = cb
  35. tools.loadRemoteImg(data.icon, (d)=>{
  36. this.img_icon.getComponent(Sprite).spriteFrame = d.sf
  37. })
  38. this.lab_name.getComponent(Label).string = data.name
  39. this.lab_count.getComponent(Label).string = `x${data.quantity}`
  40. }
  41. private requestUserSign(is_double:boolean) {
  42. let stype = 1
  43. if(is_double) {
  44. stype = 2
  45. }
  46. let opt = {'index':this.m_data.index, 'stype': stype}
  47. http.post(config.API.user_sign, opt, (err,d)=>{
  48. if(!err){
  49. let nd = JSON.parse(d)
  50. if(nd.code === config.status.SUCCESS){
  51. // console.log("user_sign", nd.content)
  52. this.m_cb()
  53. }
  54. }
  55. })
  56. }
  57. }