|
@@ -1,9 +1,10 @@
|
|
|
|
|
|
|
|
-import { _decorator, Component, EditBox, game, instantiate, Label, Node, Prefab } from 'cc';
|
|
|
|
|
|
|
+import { _decorator, Button, Component, EditBox, game, instantiate, Label, Node, Sprite, Tween, tween, Vec3} from 'cc';
|
|
|
import { UtilsPanel } from '../../scene/script/UtilsPanel';
|
|
import { UtilsPanel } from '../../scene/script/UtilsPanel';
|
|
|
import { Generate } from '../../scene/script/components/Generate';
|
|
import { Generate } from '../../scene/script/components/Generate';
|
|
|
import { Config, nav_info } from '../../scene/script/NavInfo';
|
|
import { Config, nav_info } from '../../scene/script/NavInfo';
|
|
|
import { WebRequest } from '../../scene/script/WebRequest';
|
|
import { WebRequest } from '../../scene/script/WebRequest';
|
|
|
|
|
+import { funcBg } from '../../scene/script/components/FuncBg';
|
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
export type RateInfo = {
|
|
export type RateInfo = {
|
|
@@ -15,11 +16,20 @@ export type RateInfo = {
|
|
|
//money * rate * (1 + Ratio) = gold;
|
|
//money * rate * (1 + Ratio) = gold;
|
|
|
export type ShopData = {
|
|
export type ShopData = {
|
|
|
ProductConfig: RateInfo[]
|
|
ProductConfig: RateInfo[]
|
|
|
|
|
+ ExchangeRate: ExchangeRate[]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+//国家信息
|
|
|
|
|
+export type ExchangeRate = {
|
|
|
|
|
+ Currency: string // 币种
|
|
|
|
|
+ CountryName: string // 国家名称
|
|
|
|
|
+ CountryCode: string // 国家编码
|
|
|
|
|
+ Rate: number //汇率
|
|
|
|
|
+ Sort: number //显示顺序
|
|
|
|
|
+}
|
|
|
@ccclass('Pay')
|
|
@ccclass('Pay')
|
|
|
export class Pay extends Component {
|
|
export class Pay extends Component {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// public static clacGold(money: number){
|
|
// public static clacGold(money: number){
|
|
|
// let config = Pay.data_shop;
|
|
// let config = Pay.data_shop;
|
|
|
// if(!config || money < config.MinMoney)return 0;
|
|
// if(!config || money < config.MinMoney)return 0;
|
|
@@ -30,61 +40,84 @@ export class Pay extends Component {
|
|
|
// }
|
|
// }
|
|
|
// return Math.floor(money * (ratio_info.Ratio + 1) * config.Rate);
|
|
// return Math.floor(money * (ratio_info.Ratio + 1) * config.Rate);
|
|
|
// }
|
|
// }
|
|
|
- public static buy(prod_id:string, price:number){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public static buy(prod_id: string, price: number, currency: string = "SAU") {
|
|
|
let user_id = Pay.user_id;
|
|
let user_id = Pay.user_id;
|
|
|
- if(user_id.length == 0){
|
|
|
|
|
|
|
+ if (user_id.length == 0) {
|
|
|
nav_info.scene.showTip("يرجى إدخال ال ID حقك");
|
|
nav_info.scene.showTip("يرجى إدخال ال ID حقك");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
let url = nav_info.is_test ? Config.url_pay_test : Config.url_pay;
|
|
let url = nav_info.is_test ? Config.url_pay_test : Config.url_pay;
|
|
|
- let final_url = `${url}?UserID=${user_id}&Price=${price}&ProductID=${prod_id}&PartnerID=110&Currency=SAR&Country=SA&T=${new Date().getTime()}`;
|
|
|
|
|
|
|
+ let final_url = `${url}?UserID=${user_id}&Price=${price}&ProductID=${prod_id}&PartnerID=110&Currency=${currency}&Country=SA&T=${new Date().getTime()}`;
|
|
|
window.open(final_url);
|
|
window.open(final_url);
|
|
|
}
|
|
}
|
|
|
- public static user_id = "";
|
|
|
|
|
- public static data_shop:ShopData = null;
|
|
|
|
|
|
|
|
|
|
|
|
+ public static user_id = "";
|
|
|
|
|
+ public static data_shop: ShopData = null;
|
|
|
private node_descid: Node = null;
|
|
private node_descid: Node = null;
|
|
|
- private node_buy: Node = null;
|
|
|
|
|
- private gene_items: Generate = null;
|
|
|
|
|
|
|
+ private node_buy: Node = null;
|
|
|
|
|
+ private gene_items: Generate = null;
|
|
|
private node_light: Node = null;
|
|
private node_light: Node = null;
|
|
|
- private lb_money: Label = null;
|
|
|
|
|
- private edit_id: EditBox = null;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ private lb_money: Label = null;
|
|
|
|
|
+ private edit_id: EditBox = null;
|
|
|
private select_data: RateInfo = null;
|
|
private select_data: RateInfo = null;
|
|
|
|
|
+ public currentCountry: ExchangeRate = null;
|
|
|
|
|
+ public typeIndex: number = 0;
|
|
|
|
|
+ private node_typeList: Node = null;
|
|
|
|
|
+ private sp_arrows: Sprite = null;
|
|
|
|
|
+ private node_type: Node = null;
|
|
|
|
|
+ private lb_type: Label = null;
|
|
|
|
|
+ private sp_type: Sprite = null;
|
|
|
|
|
+ private node_arrows: Node = null;
|
|
|
|
|
|
|
|
- protected start(){
|
|
|
|
|
- UtilsPanel.getAllNeedCom(this, this.node, true);
|
|
|
|
|
|
|
+ protected start() {
|
|
|
|
|
+ UtilsPanel.getAllNeedCom(this, this.node, true);
|
|
|
UtilsPanel.addBtnEvent(this.node_buy, this.onBuy, this);
|
|
UtilsPanel.addBtnEvent(this.node_buy, this.onBuy, this);
|
|
|
|
|
+ UtilsPanel.addBtnEvent(this.node_arrows, this.onArrowsClick, this).transition = Button.Transition.NONE;
|
|
|
|
|
+
|
|
|
// @ts-ignore
|
|
// @ts-ignore
|
|
|
game.on("select_item", this.onSelect, this);
|
|
game.on("select_item", this.onSelect, this);
|
|
|
let url = nav_info.is_test ? Config.url_product_test : Config.url_product;
|
|
let url = nav_info.is_test ? Config.url_product_test : Config.url_product;
|
|
|
// this.test();return;
|
|
// this.test();return;
|
|
|
- new WebRequest().getData(url, "", (succ:boolean,content:string)=>{
|
|
|
|
|
- if(succ){
|
|
|
|
|
- let info:ShopData = Pay.data_shop = JSON.parse(content);
|
|
|
|
|
|
|
+ new WebRequest().getData(url, "", (succ: boolean, content: string) => {
|
|
|
|
|
+ if (succ) {
|
|
|
|
|
+ let info: ShopData = Pay.data_shop = JSON.parse(content);
|
|
|
// console.log("fwef:",info);
|
|
// console.log("fwef:",info);
|
|
|
this.gene_items.initData(info.ProductConfig);
|
|
this.gene_items.initData(info.ProductConfig);
|
|
|
this.node_light.setSiblingIndex(-1);
|
|
this.node_light.setSiblingIndex(-1);
|
|
|
|
|
+ this.createTypeList();
|
|
|
}
|
|
}
|
|
|
}, false);
|
|
}, false);
|
|
|
- }
|
|
|
|
|
- private onEditChange(){
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private onEditChange() {
|
|
|
this.node_descid.active = this.edit_id.string.length == 0;
|
|
this.node_descid.active = this.edit_id.string.length == 0;
|
|
|
Pay.user_id = this.edit_id.string;
|
|
Pay.user_id = this.edit_id.string;
|
|
|
}
|
|
}
|
|
|
- private onSelect(info: RateInfo, node:Node){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private onSelect(info: RateInfo, node: Node) {
|
|
|
this.select_data = info;
|
|
this.select_data = info;
|
|
|
- this.lb_money.string = "" + info.PayPrice
|
|
|
|
|
|
|
+ this.upSelectPrice();
|
|
|
this.node_light.active = true;
|
|
this.node_light.active = true;
|
|
|
this.node_light.setPosition(node.position);
|
|
this.node_light.setPosition(node.position);
|
|
|
}
|
|
}
|
|
|
- private onBuy(){
|
|
|
|
|
- if(this.select_data == null){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private upSelectPrice() {
|
|
|
|
|
+ if (!this.select_data) return;
|
|
|
|
|
+ //取字符串保留2位小数(不足补0)
|
|
|
|
|
+ this.lb_money.string = `${(this.select_data.PayPrice * this.currentCountry.Rate).toFixed(2)} ${this.currentCountry.CountryCode}`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private onBuy() {
|
|
|
|
|
+ if (this.select_data == null) {
|
|
|
nav_info.scene.showTip("يرجى اختيار الباقة التي ترغب بشرائها");
|
|
nav_info.scene.showTip("يرجى اختيار الباقة التي ترغب بشرائها");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- Pay.buy(this.select_data.ProductID, this.select_data.PayPrice);
|
|
|
|
|
|
|
+ //计算汇率 取number类型整数
|
|
|
|
|
+ let price = parseFloat((this.select_data.PayPrice * this.currentCountry.Rate).toFixed(2));
|
|
|
|
|
+ Pay.buy(this.select_data.ProductID, price, this.currentCountry.CountryCode);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// private test(){
|
|
// private test(){
|
|
|
// let info = Pay.data_shop = {"MinMoney": 450, "Rate": 10000, "DefaultPrice": [1000,3000,6000,8000,10000],
|
|
// let info = Pay.data_shop = {"MinMoney": 450, "Rate": 10000, "DefaultPrice": [1000,3000,6000,8000,10000],
|
|
|
// "RatioConfig": [
|
|
// "RatioConfig": [
|
|
@@ -97,5 +130,73 @@ export class Pay extends Component {
|
|
|
// ]}
|
|
// ]}
|
|
|
// this.gene_items.initData(new Array(info.DefaultPrice.length + 1));
|
|
// this.gene_items.initData(new Array(info.DefaultPrice.length + 1));
|
|
|
// }
|
|
// }
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //刷新国家列表
|
|
|
|
|
+ private createTypeList() {
|
|
|
|
|
+ if (this.node_typeList.children.length > 0) return;
|
|
|
|
|
+ Pay.data_shop.ExchangeRate.forEach((item, index) => {
|
|
|
|
|
+ let temp = instantiate(this.node_type);
|
|
|
|
|
+ temp.name = index.toString();
|
|
|
|
|
+ temp.getComponent(Sprite).spriteFrame = null;
|
|
|
|
|
+ temp.children[0].active = this.typeIndex === index;
|
|
|
|
|
+ UtilsPanel.setItemIcon(nav_info.bundle, `texture/flag_${item.Currency}/spriteFrame`, temp.children[1].getComponent(Sprite));
|
|
|
|
|
+ temp.children[2].getComponent(Label).string = item.CountryName;
|
|
|
|
|
+ this.node_typeList.addChild(temp);
|
|
|
|
|
+ UtilsPanel.clearBtnEvent(temp, false);
|
|
|
|
|
+ UtilsPanel.addBtnEvent2(temp, 'onSelectType', this, index).transition = Button.Transition.NONE;
|
|
|
|
|
+ });
|
|
|
|
|
+ this.upTypeList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //刷新选中的类型
|
|
|
|
|
+ private upTypeList() {
|
|
|
|
|
+ this.node_typeList.active = false;
|
|
|
|
|
+ this.sp_arrows.node.toScaleY(-1);
|
|
|
|
|
+ this.currentCountry = Pay.data_shop.ExchangeRate[this.typeIndex];
|
|
|
|
|
+ this.lb_type.string = this.currentCountry.CountryName;
|
|
|
|
|
+ UtilsPanel.setItemIcon(nav_info.bundle, `texture/flag_${this.currentCountry.Currency}/spriteFrame`, this.sp_type);
|
|
|
|
|
+ //刷新金币
|
|
|
|
|
+ this.upSelectPrice();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //选择 typeList
|
|
|
|
|
+ private onSelectType(event: Event, customEventData: string) {
|
|
|
|
|
+ let index = parseInt(customEventData);
|
|
|
|
|
+ if (this.typeIndex == index) return;
|
|
|
|
|
+ this.typeIndex = index;
|
|
|
|
|
+ this.upTypeList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //显示隐藏 typeList
|
|
|
|
|
+ private onArrowsClick() {
|
|
|
|
|
+ let isOpen = !this.node_typeList.active;
|
|
|
|
|
+ Tween.stopAllByTarget(this.node_typeList);
|
|
|
|
|
+ if (isOpen) {
|
|
|
|
|
+ this.node_typeList.toScaleY(0);
|
|
|
|
|
+ this.node_typeList.active = true;
|
|
|
|
|
+ tween(this.node_typeList)
|
|
|
|
|
+ .to(0.2, { scale: new Vec3(1, 1, 1) }, {
|
|
|
|
|
+ onComplete: () => {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .start();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tween(this.node_typeList)
|
|
|
|
|
+ .to(0.2, { scale: new Vec3(1, 0.1, 1) }, {
|
|
|
|
|
+ onComplete: () => {
|
|
|
|
|
+ this.node_typeList.active = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .start();
|
|
|
|
|
+ }
|
|
|
|
|
+ this.sp_arrows.node.toScaleY(isOpen ? 1 : -1);
|
|
|
|
|
+ if (isOpen) {
|
|
|
|
|
+ funcBg.add(this.node_typeList, this.onArrowsClick.bind(this), 0, 0);
|
|
|
|
|
+ this.node_typeList.children.forEach((item, index) => {
|
|
|
|
|
+ item.children[0].active = this.typeIndex == index;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|