ArtistOperationAlert.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. const DWTool = require("../utils/DWTool");
  2. const { ArtistOperation, GameNotificationKey } = require("../utils/GameEnum");
  3. const Api = require('../net/Api');
  4. const HomeApi = require("../net/HomeApi");
  5. const GameModule = require("../utils/GameModule");
  6. const AlertManaget = require("../utils/AlertManager");
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. titleText: cc.Label,
  11. headSprite: cc.Sprite,
  12. nickRichText: cc.RichText,
  13. levelLabel: cc.Label,
  14. jobTitleLabel: cc.Label,
  15. gainDetailLabel: cc.Label,
  16. gainCoinLabel: cc.Label,
  17. recallArtistTipLabel: cc.Label,
  18. recallArtistFailTipRichText: cc.RichText,
  19. reportArtistTipLabel: cc.Label,
  20. reportArtistFailTipRichText: cc.RichText,
  21. driveAwayFailTipRichText: cc.RichText,
  22. gellAllCoinBtn: cc.Button,
  23. confrimBtn: cc.Button,
  24. coinNode: cc.Node,
  25. content: cc.Node,
  26. coinPrefab: cc.Prefab,
  27. benefit: {
  28. get: function() {
  29. if (!this._benefit) {
  30. this._benefit = 0;
  31. }
  32. return this._benefit;
  33. },
  34. set: function (value) {
  35. this._benefit = value;
  36. this.gainCoinLabel.string = DWTool.coinParse(this._benefit);
  37. }
  38. }
  39. },
  40. init(buildingInfo, uid, isSelf, artistData) {
  41. this.isSelf = isSelf;
  42. this.artistData = artistData;
  43. this.buildingInfo = buildingInfo;
  44. this.uid = uid;
  45. this.getNetworkData();
  46. },
  47. getNetworkData() {
  48. HomeApi.friendGetBenefit(this.artistData.id || this.artistData.uid, (data) => {
  49. let time = (Date.parse(new Date()) - data.stationTime) / 1000;
  50. this.gainDetailLabel.string = `演出时长: ${DWTool.calculateTime(time)}`
  51. if (data.role === 2) {
  52. if (time < 900) { // 入驻15分钟才可以召回
  53. this.setStyleByOperation(ArtistOperation.RecalArtistlFail);
  54. } else {
  55. this.setStyleByOperation(ArtistOperation.RecallArtist);
  56. }
  57. // this.setStyleByOperation(ArtistOperation.RecallArtist);
  58. } else {
  59. if (this.isSelf) {
  60. if (time < 900) { // 入驻15分钟才可以驱赶
  61. this.setStyleByOperation(ArtistOperation.DriveAwayArtistFail);
  62. } else {
  63. this.setStyleByOperation(ArtistOperation.DriveAwayArtist);
  64. }
  65. // this.setStyleByOperation(ArtistOperation.DriveAwayArtist);
  66. } else {
  67. if (data.isReported) { // 是否举报过;0:否;1:是
  68. this.setStyleByOperation(ArtistOperation.ReportArtistFail);
  69. } else {
  70. this.setStyleByOperation(ArtistOperation.ReportArtistSuccess);
  71. }
  72. }
  73. }
  74. this.operationData = data;
  75. this.jobTitleLabel.string = data.jobName;
  76. this.levelLabel.string = data.jobLevel;
  77. this.nickRichText.string = `<color=#584a47>${data.nick}</c> <img src='${data.picId}'/>`;
  78. this.benefit = data.benefit;
  79. Api.createImageFromUrl(data.head, (spriteFrame) => {
  80. this.headSprite.spriteFrame = spriteFrame;
  81. }, null);
  82. }, (code, msg) => {
  83. console.log(msg);
  84. });
  85. },
  86. setStyleByOperation(operation) {
  87. if (this.operation === operation) {
  88. return;
  89. }
  90. switch (operation) {
  91. case ArtistOperation.RecallArtist:
  92. this.setTitleString("艺人召回");
  93. this.recallArtistTipLabel.node.active = true;
  94. this.recallArtistFailTipRichText.node.active = false;
  95. this.reportArtistTipLabel.node.active = false;
  96. this.reportArtistFailTipRichText.node.active = false;
  97. this.gellAllCoinBtn.node.active = false;
  98. this.confrimBtn.node.active = true;
  99. this.driveAwayFailTipRichText.node.active = false;
  100. break;
  101. case ArtistOperation.RecalArtistlFail:
  102. this.setTitleString("艺人召回");
  103. this.recallArtistTipLabel.node.active = false;
  104. this.recallArtistFailTipRichText.node.active = true;
  105. this.reportArtistTipLabel.node.active = false;
  106. this.reportArtistFailTipRichText.node.active = false;
  107. this.gellAllCoinBtn.node.active = false;
  108. this.confrimBtn.node.active = true;
  109. this.driveAwayFailTipRichText.node.active = false;
  110. break;
  111. case ArtistOperation.ReportArtistSuccess:
  112. this.setTitleString("举报艺人");
  113. this.recallArtistTipLabel.node.active = false;
  114. this.recallArtistFailTipRichText.node.active = false;
  115. this.reportArtistTipLabel.node.active = true;
  116. this.reportArtistFailTipRichText.node.active = false;
  117. this.gellAllCoinBtn.node.active = false;
  118. this.confrimBtn.node.active = true;
  119. this.driveAwayFailTipRichText.node.active = false;
  120. break;
  121. case ArtistOperation.ReportArtistFail:
  122. this.setTitleString("举报艺人");
  123. this.recallArtistTipLabel.node.active = false;
  124. this.recallArtistFailTipRichText.node.active = false;
  125. this.reportArtistTipLabel.node.active = false;
  126. this.reportArtistFailTipRichText.node.active = true;
  127. this.gellAllCoinBtn.node.active = false;
  128. this.confrimBtn.node.active = true;
  129. this.driveAwayFailTipRichText.node.active = false;
  130. break;
  131. case ArtistOperation.DriveAwayArtist:
  132. this.setTitleString("驱赶艺人");
  133. this.recallArtistTipLabel.node.active = false;
  134. this.recallArtistFailTipRichText.node.active = false;
  135. this.reportArtistTipLabel.node.active = false;
  136. this.reportArtistFailTipRichText.node.active = false;
  137. this.gellAllCoinBtn.node.active = true;
  138. this.confrimBtn.node.active = false;
  139. this.driveAwayFailTipRichText.node.active = false;
  140. break;
  141. case ArtistOperation.DriveAwayArtistFail:
  142. this.setTitleString("驱赶艺人");
  143. this.recallArtistTipLabel.node.active = false;
  144. this.recallArtistFailTipRichText.node.active = false;
  145. this.reportArtistTipLabel.node.active = false;
  146. this.reportArtistFailTipRichText.node.active = false;
  147. this.gellAllCoinBtn.node.active = false;
  148. this.confrimBtn.node.active = true;
  149. this.driveAwayFailTipRichText.node.active = true;
  150. break;
  151. default:
  152. break;
  153. }
  154. this.operation = operation;
  155. },
  156. // LIFE-CYCLE CALLBACKS:
  157. onLoad () {
  158. GameModule.homeGuide.on('Fire_state36', () => {
  159. this.handleConfrimBtn()
  160. })
  161. },
  162. start() {
  163. // this.content.y = -cc.view.getVisibleSize().height;
  164. // this.scheduleOnce(() => {
  165. // // 调整弹窗y轴位置,以适应引导系统的UI [-40 ~ 100]
  166. // let s = cc.sequence(cc.moveTo(0.2, 0, 100).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -20));
  167. // this.content.runAction(s);
  168. // }, 0.1);
  169. },
  170. showCollectAnim(pos, colNums) {
  171. let canvasNode = cc.find("Canvas");
  172. let grossCoin = GameModule.userInfo.grossCoin;
  173. let grossCoinPos = grossCoin.node.convertToWorldSpace(cc.v2(grossCoin.node.width/2, grossCoin.node.height/2));
  174. // let colNums = 5
  175. let vSize = cc.view.getVisibleSize();
  176. let target = cc.v2(grossCoinPos.x - vSize.width / 2, grossCoinPos.y - vSize.height / 2)
  177. let i = 0;
  178. let runSt = setInterval(() => {
  179. if(i == colNums) {
  180. clearInterval(runSt)
  181. } else {
  182. let ran = (Math.random() - 0.5) * 2 * 3;
  183. let newCoin = cc.instantiate(this.coinPrefab);
  184. let posX = pos.x - vSize.width / 2;
  185. let posY = pos.y - vSize.height / 2;
  186. canvasNode.addChild(newCoin)
  187. newCoin.x = posX + ran * 15;
  188. newCoin.y = posY + 30 + ran * 15;
  189. newCoin.active = true;
  190. newCoin = newCoin.getComponent("LevelHomeCoin")
  191. newCoin.initAnim()
  192. let cbDestroy = cc.callFunc(() => {
  193. newCoin.node.destroy();
  194. })
  195. let act = cc.sequence(cc.moveTo(1, target), cbDestroy)
  196. newCoin.node.runAction(act.easing(cc.easeIn(2.1)));
  197. i++
  198. }
  199. }, 100);
  200. },
  201. handleConfrimBtn() {
  202. if (this.benefit === 0) {
  203. this.dissmiss();
  204. } else {
  205. let animation = () => {
  206. let changeTimes = 10;
  207. let changeUnit = this.benefit === 0 ? 0 : Math.floor(this.benefit / changeTimes);
  208. // let pos = this.coinNode.convertToWorldSpace(cc.v2(this.coinNode.width/2, this.coinNode.height/2))
  209. // this.showCollectAnim(pos, changeTimes);
  210. for (let i = 0; i < changeTimes; i++) {
  211. setTimeout(() => {
  212. let result = this.benefit - changeUnit;
  213. if (i === changeTimes-1) {
  214. result = 0;
  215. setTimeout(() => { // 延时关闭当前界面
  216. this.dissmiss();
  217. }, 200);
  218. }
  219. this.benefit = result;
  220. }, 100 * i);
  221. }
  222. }
  223. if (this.operation === ArtistOperation.RecallArtist ||
  224. this.operation === ArtistOperation.DriveAwayArtist) {
  225. HomeApi.friendExpelRecall(this.artistData.id || this.artistData.uid, (responseData) => { // 召回驱赶艺人成功
  226. animation();
  227. GameModule.userInfo.grossIncome += this.operationData.benefit;
  228. GameEvent.fire(GameNotificationKey.RefreshLevelHomeArtistList, this.uid, this.buildingInfo.buildingId);
  229. GameEvent.fire(GameNotificationKey.RefreshResidentArtistList);
  230. let opt = (this.operation === ArtistOperation.RecallArtist) ? 6 : 7;
  231. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, opt);
  232. }, (code, msg) => {
  233. console.log(msg);
  234. this.dissmiss();
  235. });
  236. } else {
  237. if (this.operation === ArtistOperation.ReportArtistSuccess) { // 举报艺人成功
  238. HomeApi.friendReportArtist(this.artistData.id || this.artistData.uid, (responseData) => {
  239. this.dissmiss();
  240. AlertManaget.showArtistReportSuccess(Math.floor(this.operationData.benefit * 0.1));
  241. GameModule.userInfo.grossIncome += Math.floor(this.operationData.benefit * 0.1);
  242. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, 8);
  243. }, (code, msg) => {
  244. console.log(msg);
  245. this.dissmiss();
  246. });
  247. } else {
  248. this.dissmiss();
  249. }
  250. }
  251. }
  252. },
  253. dissmiss() {
  254. this.node.destroy();
  255. // let finish = cc.callFunc(() => {
  256. // }, this);
  257. // let sequence = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish)
  258. // this.content.runAction(sequence);
  259. },
  260. close() {
  261. this.dissmiss();
  262. },
  263. setTitleString(title) {
  264. this.titleText.string = title;
  265. },
  266. getNickString(nick) {
  267. this.nickRichText.string = `<color=#584a47>${nick}</c> <img src='50001'/>`;
  268. },
  269. });