| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import { _decorator, Component, EditBox, game, instantiate, Label, Node, Prefab } from 'cc';
- import { UtilsPanel } from '../../scene/script/UtilsPanel';
- import { Generate } from '../../scene/script/components/Generate';
- import { Config, nav_info } from '../../scene/script/NavInfo';
- import { WebRequest } from '../../scene/script/WebRequest';
- const { ccclass, property } = _decorator;
- export type RateInfo = {
- ProductID: string
- Gold: number,
- PayPrice: number
- ShowRate: number
- }
- //money * rate * (1 + Ratio) = gold;
- export type ShopData = {
- ProductConfig: RateInfo[]
- }
- @ccclass('Pay')
- export class Pay extends Component {
-
- // public static clacGold(money: number){
- // let config = Pay.data_shop;
- // if(!config || money < config.MinMoney)return 0;
- // let ratio_info = config.RatioConfig.find(function(info){return money >= info.Min && money <= info.Max});
- // if(!ratio_info){
- // let ratios = config.RatioConfig;
- // ratio_info = ratios[ratios.length - 1];
- // }
- // return Math.floor(money * (ratio_info.Ratio + 1) * config.Rate);
- // }
- public static buy(prod_id:string, price:number){
- let user_id = Pay.user_id;
- if(user_id.length == 0){
- nav_info.scene.showTip("يرجى إدخال ال ID حقك");
- return;
- }
- 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()}`;
- window.open(final_url);
- }
- public static user_id = "";
- public static data_shop:ShopData = null;
- private node_descid: Node = null;
- private node_buy: Node = null;
- private gene_items: Generate = null;
- private node_light: Node = null;
- private lb_money: Label = null;
- private edit_id: EditBox = null;
-
- private select_data: RateInfo = null;
- protected start(){
- UtilsPanel.getAllNeedCom(this, this.node, true);
- UtilsPanel.addBtnEvent(this.node_buy, this.onBuy, this);
- // @ts-ignore
- game.on("select_item", this.onSelect, this);
- let url = nav_info.is_test ? Config.url_product_test : Config.url_product;
- // this.test();return;
- new WebRequest().getData(url, "", (succ:boolean,content:string)=>{
- if(succ){
- let info:ShopData = Pay.data_shop = JSON.parse(content);
- // console.log("fwef:",info);
- this.gene_items.initData(info.ProductConfig);
- this.node_light.setSiblingIndex(-1);
- }
- }, false);
- }
- private onEditChange(){
- this.node_descid.active = this.edit_id.string.length == 0;
- Pay.user_id = this.edit_id.string;
- }
- private onSelect(info: RateInfo, node:Node){
- this.select_data = info;
- this.lb_money.string = "" + info.PayPrice
- this.node_light.active = true;
- this.node_light.setPosition(node.position);
- }
- private onBuy(){
- if(this.select_data == null){
- nav_info.scene.showTip("يرجى اختيار الباقة التي ترغب بشرائها");
- return;
- }
- Pay.buy(this.select_data.ProductID, this.select_data.PayPrice);
- }
- // private test(){
- // let info = Pay.data_shop = {"MinMoney": 450, "Rate": 10000, "DefaultPrice": [1000,3000,6000,8000,10000],
- // "RatioConfig": [
- // {"Min":400,"Max": 1000, "Ratio": 0.7},
- // {"Min":1001,"Max": 3000, "Ratio": 0.8},
- // {"Min":3001,"Max": 6000, "Ratio": 1},
- // {"Min":6001,"Max": 8000, "Ratio": 1.2},
- // {"Min":8001,"Max": 10000, "Ratio": 1.4},
- // {"Min":10001,"Max": 10000000, "Ratio": 2}
- // ]}
- // this.gene_items.initData(new Array(info.DefaultPrice.length + 1));
- // }
-
- }
|