Pay.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Component, EditBox, game, instantiate, Label, Node, Prefab } from 'cc';
  2. import { UtilsPanel } from '../../scene/script/UtilsPanel';
  3. import { Generate } from '../../scene/script/components/Generate';
  4. import { Config, nav_info } from '../../scene/script/NavInfo';
  5. import { WebRequest } from '../../scene/script/WebRequest';
  6. const { ccclass, property } = _decorator;
  7. type ItemType = {
  8. ItemId: number
  9. Count: number
  10. }
  11. export type ShopData = {
  12. AninationType: number
  13. Bonus: number
  14. Extra: Array<ItemType>
  15. IsBotton: number
  16. IsHot: number
  17. PayType: number
  18. Price: number
  19. ProductDesc: string
  20. ProductId: string
  21. ProductName: string
  22. ShopType: number
  23. ShowPrice: number
  24. Sort: number
  25. Status: number
  26. UserType: number
  27. }
  28. @ccclass('Pay')
  29. export class Pay extends Component {
  30. private node_descid: Node = null;
  31. private node_buy: Node = null;
  32. private gene_items: Generate = null;
  33. private lb_money: Label = null;
  34. private edit_id: EditBox = null;
  35. private data: ShopData[] = null;
  36. private select_data:ShopData = null;
  37. protected onLoad(){
  38. UtilsPanel.getAllNeedCom(this, this.node, false);
  39. UtilsPanel.addBtnEvent(this.node_buy, this.onBuy, this);
  40. // @ts-ignore
  41. game.on("select_item", this.onSelect, this);
  42. let url = nav_info.is_test ? Config.url_product_test : Config.url_product;
  43. new WebRequest().getData(url, "", (succ:boolean,content:string)=>{
  44. if(succ){
  45. this.data = JSON.parse(JSON.parse(content).Data);
  46. }
  47. this.gene_items.initData(this.data);
  48. // console.log("fwef:",this.data);
  49. }, false);
  50. }
  51. private onEditChange(){
  52. this.node_descid.active = this.edit_id.string.length == 0;
  53. }
  54. private onSelect(index:number){
  55. this.select_data = this.data[index];
  56. this.lb_money.string = this.select_data.Price + "";
  57. }
  58. private onBuy(){
  59. let user_id = this.edit_id.string;
  60. if(user_id.length == 0){
  61. nav_info.scene.showTip("please input user id");
  62. return;
  63. }
  64. if(!this.select_data){
  65. nav_info.scene.showTip("please select product");
  66. return;
  67. }
  68. let data = this.select_data;
  69. let url = nav_info.is_test ? Config.url_pay_test : Config.url_pay;
  70. let final_url = `${url}?UserID=${user_id}&Price=${data.Price}&ProductID=${data.ProductId}&PartnerID=110&Currency=SAR&Country=SA&T=${new Date().getTime()}`;
  71. window.open(final_url);
  72. }
  73. }