StoreBigItem.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const DWTool = require("../utils/DWTool");
  2. const AlertManager = require('../utils/AlertManager');
  3. const WeChat = require('../net/WeChat');
  4. const GameModule = require("../utils/GameModule");
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. itemBgSprite: cc.Sprite,
  9. iconSprite: cc.Sprite,
  10. titleSprite: cc.Sprite,
  11. subTitleRichText: cc.RichText,
  12. useTitleLabel: cc.Label,
  13. useButton: cc.Button,
  14. useSprite: cc.Sprite,
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. onLoad () {},
  18. start () {
  19. },
  20. /// tabIndex是第几个tab index 在数组中的index
  21. init(data, fontSize, tabIndex, index) {
  22. this._isAlbum = false;
  23. this._tabIndex = tabIndex;
  24. if (data.type === 4) {
  25. index = data.shopId - 16;
  26. }
  27. this._index = index;
  28. this._shopData = data;
  29. this.subTitleRichText.string = `<color=#2E2E2E>${data.desc}</c>`
  30. this.subTitleRichText.fontSize = fontSize;
  31. this.useTitleLabel.string = `¥ ${data.price}`;
  32. let path = './textures/store/800' + data.type;
  33. if (data.type === 4) {
  34. /// 加载背景 shopid 16 17 18 19
  35. DWTool.loadResSpriteFrame(path + index + 1).then((spriteFrame) => {
  36. this.itemBgSprite.spriteFrame = spriteFrame;
  37. }).catch((msg) => {
  38. console.log(msg);
  39. });
  40. ////加载黄色背景
  41. } else {
  42. let bgPath = './textures/store/800401';
  43. DWTool.loadResSpriteFrame(bgPath).then((spriteFrame) => {
  44. this.itemBgSprite.spriteFrame = spriteFrame;
  45. }).catch((msg) => {
  46. console.log(msg);
  47. });
  48. }
  49. if (data.type === 1) {
  50. this.titleSprite.node.scaleX = 1;
  51. this.titleSprite.node.scaleY = 1;
  52. }
  53. DWTool.loadResSpriteFrame(path + index + 2).then((spriteFrame) => {
  54. this.iconSprite.spriteFrame = spriteFrame;
  55. }).catch((msg) => {
  56. console.log(msg);
  57. });
  58. DWTool.loadResSpriteFrame(path + index + 3).then((spriteFrame) => {
  59. this.titleSprite.spriteFrame = spriteFrame;
  60. }).catch((msg) => {
  61. console.log(msg);
  62. });
  63. },
  64. /// 初始化商品的第二个
  65. initAlbum(itemDatas) {
  66. this._isAlbum = true;
  67. this._itemDatas = itemDatas;
  68. this.useTitleLabel.fontSize = 20;
  69. this.useTitleLabel.string = '订阅\n查看详细内容';
  70. this.subTitleRichText.string = `<color=#2E2E2E>${itemDatas[0].desc}</c>`;
  71. let path = './textures/store/800000';
  72. let bgPath = './textures/store/800401';
  73. let titlePath = './textures/store/store_subcript';
  74. DWTool.loadResSpriteFrame(path).then((spriteFrame) => {
  75. this.iconSprite.spriteFrame = spriteFrame;
  76. }).catch((msg) => {
  77. console.log(msg);
  78. });
  79. DWTool.loadResSpriteFrame(bgPath).then((spriteFrame) => {
  80. this.itemBgSprite.spriteFrame = spriteFrame;
  81. }).catch((msg) => {
  82. console.log(msg);
  83. });
  84. DWTool.loadResSpriteFrame(titlePath).then((spriteFrame) => {
  85. this.titleSprite.spriteFrame = spriteFrame;
  86. }).catch((msg) => {
  87. console.log(msg);
  88. });
  89. },
  90. useButtonAction() {
  91. GameModule.audioMng.playClickButton();
  92. /// 推荐合辑
  93. if (this._isAlbum) {
  94. AlertManager.showStoreAlbumAlert(this._itemDatas);
  95. /// 如果是礼包
  96. } else if (this._shopData.type == 4) {
  97. AlertManager.showStoreGiftAlert(this._index, this._shopData);
  98. } else {
  99. WeChat.jumpCustomerServices();
  100. }
  101. },
  102. // update (dt) {},
  103. });