CashOutUI.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import PlayerConst from "../data/PlayerConst";
  8. import Util from "../util/Util";
  9. import PoolMgr, { NODEPOOLPREFABTYPE } from "../mgr/PoolMgr";
  10. import CashOutItem, { CASHOUTITEMSTATE } from "./uiItem/CashOutItem";
  11. import GameConst from "../data/GameConst";
  12. import EffectMgr from "../mgr/EffectMgr";
  13. import HttpMgr from "../mgr/HttpMgr";
  14. import GameMgr, { UI_NAME } from "../mgr/GameMgr";
  15. import DataMgr from "../mgr/DataMgr";
  16. import { EVENT_TYPE } from "../../game/data/GameData";
  17. const { ccclass, property } = cc._decorator;
  18. @ccclass
  19. export default class CashOutUI extends cc.Component {
  20. @property(cc.Node)
  21. node_rectBg: cc.Node = null;
  22. @property(cc.Node)
  23. node_top: cc.Node = null;
  24. @property(cc.Node)
  25. node_content: cc.Node = null;
  26. @property(cc.Node)
  27. node_backBtn: cc.Node = null;
  28. @property(cc.Node)
  29. node_cashOutRecordBtn: cc.Node = null;
  30. @property(cc.Node)
  31. node_cashOutItemList: cc.Node = null;
  32. @property(cc.Label)
  33. label_cashNum: cc.Label = null;
  34. @property(cc.Node)
  35. node_wxIcon: cc.Node = null;
  36. @property(cc.Label)
  37. label_nickName: cc.Label = null;
  38. @property(cc.Node)
  39. node_cashOutBtn: cc.Node = null;
  40. @property(cc.Label)
  41. label_cashOutTip: cc.Label = null;
  42. @property(cc.Node)
  43. node_noCashOutBtn: cc.Node = null;
  44. @property(cc.Label)
  45. label_noCashOutTip: cc.Label = null;
  46. @property(cc.Node)
  47. node_taskCashOut: cc.Node = null;
  48. @property(cc.RichText)
  49. richText_taskCashOutBtn: cc.RichText = null;
  50. @property(cc.Node)
  51. node_goToTaskBtn: cc.Node = null;
  52. public curSelectCashOutItem: CashOutItem = null;
  53. public color_gray: cc.Color = new cc.Color(174, 174, 174);
  54. public color_green: cc.Color = new cc.Color(174, 174, 174);
  55. // LIFE-CYCLE CALLBACKS:
  56. // onLoad () {}
  57. start() {
  58. this.adapt();
  59. this.initView();
  60. this.initEvent();
  61. }
  62. // update (dt) {}
  63. onDisable() {
  64. let node_playerInfoUI = mk.ui.getCurOnPanel("PlayerInfoUI");
  65. if (node_playerInfoUI) {
  66. // AdMgr.Inst.showNativeAd(4, true);
  67. }
  68. mk.event.remove(EVENT_TYPE.UPDATE_CashNum, this.initCashNum, this);
  69. }
  70. onEnable() {
  71. GameMgr.Inst.sendEvent(UI_NAME.CashOutUI, "进入提现界面");
  72. this.initCashNum();
  73. this.initCashOutItem();
  74. this.initNickName();
  75. this.initHead();
  76. }
  77. adapt() {
  78. let offset = 1334 * 0.5 - this.node_top.y;
  79. let gap = (cc.winSize.height - 1334) * 0.5
  80. // LogUtil.log("offset", offset);
  81. // this.node_top.y = cc.winSize.height * 0.5 - offset;
  82. this.node_top.y += gap;
  83. this.node_content.y += gap;
  84. this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
  85. }
  86. initView() {
  87. this.initNickName();
  88. }
  89. initEvent() {
  90. this.node_backBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  91. this.node_cashOutRecordBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  92. this.node_cashOutBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  93. if (!GameConst.isAuth) {
  94. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  95. }
  96. mk.event.register(EVENT_TYPE.UPDATE_CashNum, this.initCashNum, this);
  97. }
  98. onClick(event: cc.Event.EventTouch) {
  99. switch (event.currentTarget) {
  100. case this.node_backBtn:
  101. this.onClickBackBtn();
  102. break;
  103. case this.node_cashOutRecordBtn:
  104. this.onClickCashOutRecordBtn();
  105. break;
  106. case this.node_cashOutBtn:
  107. this.onClickCashOutBtn();
  108. break;
  109. }
  110. }
  111. /**初始化 */
  112. initCashNum() {
  113. // let num = Math.round((PlayerConst.cashNum * 100)) / 100;
  114. let num = Util.numberFixed(PlayerConst.cashNum, 2);
  115. this.label_cashNum.string = `¥ ${num}`;
  116. }
  117. /**初始化昵称 */
  118. initNickName() {
  119. this.label_nickName.string = Util.cutStr(PlayerConst.nickName, 12);
  120. this.label_nickName.node.active = true;
  121. this.node_wxIcon.x = this.label_nickName.node.x - this.label_nickName.node.width - 30;
  122. }
  123. /**初始化头像 */
  124. async initHead() {
  125. // let spr_wxIcon = this.node_wxIcon.getComponent(cc.Sprite);
  126. // LoaderUtil.loadHeadImg(this.node_wxIcon.getComponent(cc.Sprite), 42);
  127. // mk.loader.
  128. }
  129. /**初始化提现 */
  130. initCashOutItem() {
  131. if (this.node_cashOutItemList.childrenCount <= 0) {
  132. for (var i = 0; i < 5; i++) {
  133. let node_cashOutItem = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CashOutItem);
  134. //LogUtil.log("node_cashOutItem", node_cashOutItem);
  135. let cashOutItem = node_cashOutItem.getComponent(CashOutItem);
  136. let cashOutItemState = this.getCashOutItemState(i);
  137. cashOutItem.init(i, cashOutItemState);
  138. this.node_cashOutItemList.addChild(node_cashOutItem);
  139. }
  140. }
  141. else {
  142. for (var i = 0; i < this.node_cashOutItemList.childrenCount; i++) {
  143. let node_cashOutItem = this.node_cashOutItemList.children[i];
  144. let cashOutItem = node_cashOutItem.getComponent(CashOutItem);
  145. let cashOutItemState = this.getCashOutItemState(i);
  146. cashOutItem.init(i, cashOutItemState);
  147. }
  148. }
  149. }
  150. /**获取提现状态
  151. * @param index 索引值
  152. */
  153. getCashOutItemState(index: number): CASHOUTITEMSTATE {
  154. let cashOutItemState = CASHOUTITEMSTATE.Normal;
  155. if (PlayerConst.clockInCashInfo) {
  156. let clockInCashInfo = PlayerConst.clockInCashInfo[index];
  157. if (clockInCashInfo) {
  158. if (clockInCashInfo.isWithdraw === 0) {
  159. cashOutItemState = CASHOUTITEMSTATE.Normal;
  160. }
  161. else if (clockInCashInfo.isWithdraw === 1) {
  162. cashOutItemState = CASHOUTITEMSTATE.CashOuted;
  163. }
  164. else {
  165. cashOutItemState = CASHOUTITEMSTATE.CashOuting
  166. }
  167. }
  168. }
  169. return cashOutItemState;
  170. }
  171. /**点击返回按钮 */
  172. onClickBackBtn() {
  173. GameMgr.Inst.sendEvent(UI_NAME.CashOutUI, "点击返回按钮");
  174. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  175. mk.audio.playEffect("ef_button_click");
  176. mk.ui.closePanel("CashOutUI");
  177. }
  178. /**点击提现记录按钮 */
  179. onClickCashOutRecordBtn() {
  180. GameMgr.Inst.sendEvent(UI_NAME.CashOutUI, "点击提现记录按钮");
  181. }
  182. onClickCashOutBtn() {
  183. GameMgr.Inst.sendEvent(UI_NAME.CashOutUI, "点击提现按钮");
  184. if (!GameConst.isAuth) {
  185. mk.ui.openPanel("game/prefab/uiPanel/GuideAuthUI")
  186. return;
  187. }
  188. if (!this.curSelectCashOutItem) {
  189. EffectMgr.Inst.addTip("请选择提现档次");
  190. return;
  191. }
  192. let day = this.curSelectCashOutItem.day;
  193. let cashNum = this.curSelectCashOutItem.cashOutNum;
  194. if (PlayerConst.clockInDay < day) {
  195. EffectMgr.Inst.addTip(`还需打卡${day - PlayerConst.clockInDay}天,可以提现哦`)
  196. }
  197. else {
  198. if (PlayerConst.cashNum < cashNum) {
  199. let leftNum = Math.round((cashNum - PlayerConst.cashNum) * 10) / 10;
  200. EffectMgr.Inst.addTip(`还需${leftNum}元零钱,可以提现哦`)
  201. }
  202. else {
  203. HttpMgr.Inst.cash(cashNum, 1).then(() => {
  204. HttpMgr.Inst.getClockInInfo();
  205. DataMgr.Inst.updateMoneyNum(-cashNum);
  206. EffectMgr.Inst.addTip("恭喜提现成功,等待到账");
  207. GameMgr.Inst.sendEvent(UI_NAME.CashOutUI, `${PlayerConst.clockInDay}打卡提现成功`);
  208. GameMgr.Inst.sendEventCp(UI_NAME.CashOutUI, `${PlayerConst.clockInDay}打卡提现成功`);
  209. //提现操作
  210. }).catch((err) => {
  211. // EffectMgr.Inst.addTip(`后台维护中,请稍后再试`)
  212. EffectMgr.Inst.addTip(err.errmsg);
  213. });
  214. }
  215. }
  216. }
  217. setCurSelectItemBtn(cashOutItem: CashOutItem) {
  218. if (this.curSelectCashOutItem) {
  219. this.curSelectCashOutItem.cancelSelect();
  220. }
  221. this.curSelectCashOutItem = cashOutItem;
  222. this.curSelectCashOutItem.select();
  223. switch (this.curSelectCashOutItem.cashOutItemState) {
  224. case CASHOUTITEMSTATE.Normal:
  225. this.node_cashOutBtn.active = true;
  226. this.node_noCashOutBtn.active = false;
  227. this.node_taskCashOut.active = false;
  228. break;
  229. case CASHOUTITEMSTATE.CashOuting:
  230. this.node_cashOutBtn.active = false;
  231. this.node_noCashOutBtn.active = true;
  232. this.node_taskCashOut.active = false;
  233. break;
  234. case CASHOUTITEMSTATE.CashOuted:
  235. this.node_cashOutBtn.active = false;
  236. this.node_noCashOutBtn.active = true;
  237. this.node_taskCashOut.active = false;
  238. break;
  239. }
  240. }
  241. //自定义事件---------------------------------------------------------------------
  242. /**微信授权返回 */
  243. onWxAuthBack() {
  244. console.log("CashOutUI 微信授权返回");
  245. this.initHead();
  246. this.initNickName();
  247. mk.console.log("PlayerConst.headImgUrl", PlayerConst.headImgUrl);
  248. mk.console.log("PlayerConst.nickName111", PlayerConst.nickName);
  249. mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  250. }
  251. }