StoreBigItem.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 (tabIndex === 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' + tabIndex;
  33. if (tabIndex === 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. if (tabIndex === 1) {
  42. this.titleSprite.node.scaleX = 1;
  43. this.titleSprite.node.scaleY = 1;
  44. }
  45. DWTool.loadResSpriteFrame(path + index + 2).then((spriteFrame) => {
  46. this.iconSprite.spriteFrame = spriteFrame;
  47. }).catch((msg) => {
  48. console.log(msg);
  49. });
  50. DWTool.loadResSpriteFrame(path + index + 3).then((spriteFrame) => {
  51. this.titleSprite.spriteFrame = spriteFrame;
  52. }).catch((msg) => {
  53. console.log(msg);
  54. });
  55. },
  56. /// 初始化商品的第二个
  57. initAlbum(itemDatas) {
  58. this._isAlbum = true;
  59. this._itemDatas = itemDatas;
  60. this.subTitleRichText.string = `<color=#2E2E2E>${itemDatas[0].desc}</c>`;
  61. },
  62. useButtonAction() {
  63. GameModule.audioMng.playClickButton();
  64. /// 推荐合辑
  65. if (this._isAlbum) {
  66. AlertManager.showStoreAlbumAlert(this._itemDatas);
  67. /// 如果是礼包
  68. } else if (this._tabIndex == 4) {
  69. AlertManager.showStoreGiftAlert(this._index, this._shopData);
  70. } else {
  71. WeChat.jumpCustomerServices();
  72. }
  73. },
  74. // update (dt) {},
  75. });