import GameModel from "./core/GameModel"; import MsgAlert from "./game/msg/MsgAlert"; import FGAlert from "./gear_2.3.4/fgui/FGAlert"; import FGUtil from "./gear_2.3.4/fgui/FGUtil"; import SKDataUtil from "./gear_2.3.4/util/SKDataUtil"; import SKUIUtil from "./gear_2.3.4/util/SKUIUtil"; const { ccclass, property } = cc._decorator; export default class DrawMoney extends cc.Component { /** * 日常活動單例實例 */ public static Instance: DrawMoney = null; /** * 日常活動面板 */ MainPanel: fgui.GComponent = null; /** * 可用餘額 */ canDrawNum: number = 0; /** * 提現列表 */ dataList: any = []; /** * 展示列表 */ showList: any = []; /** * 只顯示自己的記錄 */ showSelf: boolean = false; /** * 是否可以申請提現 */ canDrawFlag: boolean = true; onLoad() { if (DrawMoney.Instance === null) { DrawMoney.Instance = this; } else { this.destroy(); return; } } openDrawPanel() { if (!SKUIUtil.isFGUIValid(this.MainPanel)) { this.MainPanel = FGUtil.create("main_ui", "draw_panel"); FGUtil.root().addChild(this.MainPanel); this.MainPanel.makeFullScreen(); } this.canDrawFlag = true; FGUtil.getComponent(this.MainPanel, "mask").onClick(this.closePanel, this) FGUtil.getButton(this.MainPanel, "alert/close").onClick(this.closePanel, this) FGUtil.getButton(this.MainPanel, "alert/n16").onClick(this.drawMoney, this); FGUtil.getButton(this.MainPanel, "alert/n30").onClick(this.showSelfOnly, this); FGUtil.getControl(this.MainPanel, "alert/n30/selected").selectedIndex = this.showSelf ? 1 : 0 var list = FGUtil.getList(this.MainPanel, "alert/n4"); list.itemRenderer = this.initListItem.bind(this); list.setVirtual(); this.refreshList() GameModel.send("c2s_information", { roleid: GameModel.player.roleid }) } /** * 接收記錄 * @param data * @returns */ reciveList(data) { if (!SKUIUtil.isFGUIValid(this.MainPanel)) return; this.dataList = SKDataUtil.jsonBy(data.withdraw); this.canDrawNum = data.balance ? data.balance : 0; FGUtil.getTextField(this.MainPanel, "alert/n19").text = `${this.canDrawNum.toFixed(1)}`; this.refreshList(); } /** * 只看自己 */ showSelfOnly() { if (!SKUIUtil.isFGUIValid(this.MainPanel)) return; if (this.showSelf) { FGUtil.getControl(this.MainPanel, "alert/n30/selected").selectedIndex = 0 this.showSelf = false } else { FGUtil.getControl(this.MainPanel, "alert/n30/selected").selectedIndex = 1 this.showSelf = true } this.refreshList(); } initListItem(idx, obj: fairygui.GObject) { let item = obj.asCom; var info = this.showList[idx]; FGUtil.getTextField(item, "id").text = `${info.serial}`; FGUtil.getTextField(item, "name").text = `${GameModel.player.name}`; FGUtil.getRichTextField(item, "num").text = `提現[color=#FF6666]${info.money}[/color]元`; FGUtil.getTextField(item, "time").text = `${info.req_time}`; // FGUtil.getTextField(item, "time").text = SKDataUtil.formatDate("YYYY-mm-dd HH:MM:SS", info.time) FGUtil.getTextField(item, "state").text = info.state == 1 ? "[color=#4B0082]審核不通過[/color]" : info.state == 2 ? "[color=#00FF66]款項已支付√[/color]" : "[color=#000FF6]等待審核中..[/color]"; } refreshList() { if (!SKUIUtil.isFGUIValid(this.MainPanel)) return; var list = FGUtil.getList(this.MainPanel, "alert/n4"); if (!this.showSelf) { this.showList = this.dataList; FGUtil.getTextField(this.MainPanel, "alert/drawListTip").text = "還沒有人提現哦" } else { this.showList = []; for (let i in this.dataList) { if (this.dataList[i].roleid == GameModel.player.roleid) this.showList.push(this.dataList[i]) } FGUtil.getTextField(this.MainPanel, "alert/drawListTip").text = "還沒有提現記錄哦" } list.numItems = this.showList.length; if (this.showList.length == 0) FGUtil.getControl(this.MainPanel, "alert/noList").selectedIndex = 1 else FGUtil.getControl(this.MainPanel, "alert/noList").selectedIndex = 0 } closePanel() { FGUtil.dispose(this.MainPanel); this.MainPanel = null; } drawMoney() { if (!SKUIUtil.isFGUIValid(this.MainPanel)) return; if (!this.canDrawFlag) { MsgAlert.addMsg(`申請太快啦`); return; } var acid = FGUtil.getTextInput(this.MainPanel, "alert/n9").text; let idValid = this.checkSymbol(acid, 3, 30, "不能包含特殊字符"); if (idValid.length > 0) { MsgAlert.addMsg(`賬號${idValid} `); return; } var acname = FGUtil.getTextInput(this.MainPanel, "alert/n10").text; let nameValid = this.checkSymbol(acname, 1, 10, "不能包含特殊字符"); if (nameValid.length > 0) { MsgAlert.addMsg(`名字${nameValid} `); return; } var drawNum = FGUtil.getTextInput(this.MainPanel, "alert/n11").text; var num = 0; if (SKDataUtil.isNumberString(drawNum)) { num = parseInt(drawNum); if (SKDataUtil.isNumber(num)) { if (num >= 100) { num = Math.floor(num); } else { MsgAlert.addMsg(`提現金額最低為100`); return; } } else { MsgAlert.addMsg(`請輸入正確的提現金額`); return; } } else { MsgAlert.addMsg(`請輸入正確的提現金額`); return; } if (num > this.canDrawNum) { MsgAlert.addMsg(`當前可提現餘額不足`); return; } this.canDrawFlag = false; FGAlert.show(`確定提現[color=#FF6666]${num}[/color]元到支付寶賬戶[color=#000080]${acid}[/color]麼?`, () => { FGAlert.hide(); }, () => { FGAlert.hide(); GameModel.send("c2s_withdraw", { money: num, alipay: acid, name: acname }) }) this.scheduleOnce(() => { this.canDrawFlag = true }, 1) } checkSymbol(value: string, min: number, max: number, tip: string): string { if (value.length < min) { return `長度不能少於${min}個`; } if (value.length > max) { return `最多只能${max}個`; } let regexp = new RegExp("[\r\n\t]"); let check = regexp.test(value); if (check) { return `不能有回車或製表符!`; } regexp = new RegExp("[`~!#$^&*()=|{}':;',\\[\\]<>/?~!#¥……&*()——|{}【】‘;:”“'。,、?]"); check = regexp.test(value); if (check) { return tip; } return ""; } }