219 lines
7.0 KiB
TypeScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
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 "";
}
}