ArtistOperationAlert.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. titleRichText: cc.RichText,
  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. },
  159. start() {
  160. this.content.y = -cc.view.getVisibleSize().height;
  161. this.scheduleOnce(() => {
  162. let s = cc.sequence(cc.moveTo(0.2, 0, -40).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -20));
  163. this.content.runAction(s);
  164. }, 0.1);
  165. },
  166. showCollectAnim(pos, colNums) {
  167. let canvasNode = cc.find("Canvas");
  168. let grossCoin = GameModule.userInfo.grossCoin;
  169. let grossCoinPos = grossCoin.node.convertToWorldSpace(cc.v2(grossCoin.node.width/2, grossCoin.node.height/2));
  170. // let colNums = 5
  171. let vSize = cc.view.getVisibleSize();
  172. let target = cc.v2(grossCoinPos.x - vSize.width / 2, grossCoinPos.y - vSize.height / 2)
  173. let i = 0;
  174. let runSt = setInterval(() => {
  175. if(i == colNums) {
  176. clearInterval(runSt)
  177. } else {
  178. let ran = (Math.random() - 0.5) * 2 * 3;
  179. let newCoin = cc.instantiate(this.coinPrefab);
  180. let posX = pos.x - vSize.width / 2;
  181. let posY = pos.y - vSize.height / 2;
  182. canvasNode.addChild(newCoin)
  183. newCoin.x = posX + ran * 15;
  184. newCoin.y = posY + 30 + ran * 15;
  185. newCoin.active = true;
  186. newCoin = newCoin.getComponent("LevelHomeCoin")
  187. newCoin.initAnim()
  188. let cbDestroy = cc.callFunc(() => {
  189. newCoin.node.destroy();
  190. })
  191. let act = cc.sequence(cc.moveTo(1, target), cbDestroy)
  192. newCoin.node.runAction(act.easing(cc.easeIn(2.1)));
  193. i++
  194. }
  195. }, 100);
  196. },
  197. handleConfrimBtn() {
  198. if (this.benefit === 0) {
  199. this.dissmiss();
  200. } else {
  201. let animation = () => {
  202. let changeTimes = 10;
  203. let changeUnit = this.benefit === 0 ? 0 : Math.floor(this.benefit / changeTimes);
  204. // let pos = this.coinNode.convertToWorldSpace(cc.v2(this.coinNode.width/2, this.coinNode.height/2))
  205. // this.showCollectAnim(pos, changeTimes);
  206. for (let i = 0; i < changeTimes; i++) {
  207. setTimeout(() => {
  208. let result = this.benefit - changeUnit;
  209. if (i === changeTimes-1) {
  210. result = 0;
  211. setTimeout(() => { // 延时关闭当前界面
  212. this.dissmiss();
  213. }, 200);
  214. }
  215. this.benefit = result;
  216. }, 100 * i);
  217. }
  218. }
  219. if (this.operation === ArtistOperation.RecallArtist ||
  220. this.operation === ArtistOperation.DriveAwayArtist) {
  221. HomeApi.friendExpelRecall(this.artistData.id || this.artistData.uid, (responseData) => { // 召回驱赶艺人成功
  222. animation();
  223. GameModule.userInfo.grossIncome += this.operationData.benefit;
  224. GameEvent.fire(GameNotificationKey.RefreshLevelHomeArtistList, this.uid, this.buildingInfo.buildingId);
  225. GameEvent.fire(GameNotificationKey.RefreshResidentArtistList);
  226. let opt = (this.operation === ArtistOperation.RecallArtist) ? 6 : 7;
  227. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, opt);
  228. }, (code, msg) => {
  229. console.log(msg);
  230. this.dissmiss();
  231. });
  232. } else {
  233. if (this.operation === ArtistOperation.ReportArtistSuccess) { // 举报艺人成功
  234. HomeApi.friendReportArtist(this.artistData.id || this.artistData.uid, (responseData) => {
  235. this.dissmiss();
  236. AlertManaget.showArtistReportSuccess(Math.floor(this.operationData.benefit * 0.1));
  237. GameModule.userInfo.grossIncome += Math.floor(this.operationData.benefit * 0.1);
  238. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, 8);
  239. }, (code, msg) => {
  240. console.log(msg);
  241. this.dissmiss();
  242. });
  243. } else {
  244. this.dissmiss();
  245. }
  246. }
  247. }
  248. },
  249. dissmiss() {
  250. let finish = cc.callFunc(() => {
  251. this.node.destroy();
  252. }, this);
  253. let sequence = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish)
  254. this.content.runAction(sequence);
  255. },
  256. close() {
  257. this.dissmiss();
  258. },
  259. setTitleString(title) {
  260. this.titleRichText.string = `<outline color=#e8e9e9 width=2><b><color=#584A47>${title}</c></b></outline>`;
  261. },
  262. getNickString(nick) {
  263. this.nickRichText.string = `<color=#584a47>${nick}</c> <img src='50001'/>`;
  264. },
  265. });