ExchangeAmethystView.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import ViewObject from "../../../main/ViewObject";
  2. import { HttpStateType, ReveData } from "../../../util/CHttp";
  3. import ShopView from "./ShopView";
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class ExchangeAmethystView extends ViewObject {
  7. @property(cc.Label)
  8. lbdrawcount: cc.Label = null;
  9. @property(cc.Label)
  10. lbneed: cc.Label = null;
  11. @property(cc.Label)
  12. lbhave: cc.Label = null;
  13. @property(cc.Label)
  14. diamond_1: cc.Label = null;
  15. @property(cc.Label)
  16. diamond_2: cc.Label = null;
  17. count: number = 0;
  18. callBack: Function = null;
  19. init(pandoraDrawCount: number, needAmethyst: number, callBack: Function) {
  20. this.callBack = callBack;
  21. let amethystCount = this.main.player.getGoodCount(1009);
  22. this.count = needAmethyst - amethystCount;
  23. this.lbdrawcount.string = `抽奖${pandoraDrawCount}次`;
  24. this.lbneed.string = `${needAmethyst}`;
  25. this.lbhave.string = `${amethystCount}`;
  26. this.diamond_1.string = `(可消耗${this.count * 10}钻石购买)`;
  27. this.diamond_2.string = `${this.count * 10}`;
  28. }
  29. buy() {
  30. let msg = {
  31. count: this.count
  32. };
  33. this.main.gameHttp.sendJson('pandora/v1/buyZsj', msg, (state, reve: ReveData) => {
  34. this.main.stopLoad();
  35. if (state == HttpStateType.SUCCESS) {
  36. if (reve.retCode == 0) {
  37. console.log("==reve=exchangeamethyst===", reve)
  38. // this.main.showReward(reve);
  39. this.callBack && this.callBack();
  40. this.exitDistroy();
  41. } else {
  42. this.main.showTips(reve.message);
  43. }
  44. } else {
  45. this.main.showTips('网络异常');
  46. }
  47. });
  48. }
  49. onClick() {
  50. this.buy();
  51. }
  52. }