// import Image = Laya.Image;
// import FontClip = Laya.FontClip;
// import Button = Laya.Button;
// import Box = Laya.Box;
// import Text = Laya.Text;

// import SKinView, { SkinGetForType, ShopScene } from "../View/SkinView"
// import SkinView from "../View/SkinView";
// import { AccountManager } from "../Net/AccountManager";
// import { WXSDK } from "../Net/WXSDK";
// import GuangGao from "../Net/GuangGao";
// import { ServerManager, JtSniper } from "../Net/ServerManager";
// import { EventManager, EventState } from "./EventManager";

// export default class  ShopItem extends Laya.Script{
//     private static ins:ShopItem;
//     public static get Instance():ShopItem{
//         if(ShopItem.ins){
//             return ShopItem.ins
//         }
//         else{
//             return new ShopItem();
//         }
//     }
//     constructor(){
//         super();
//         ShopItem.ins = this;
//     }
    
//     private selfobj: Laya.Box;
//     private _select: Image;
//     private _skin: Image;
//     private coinnum: Text;
//     private geted: Box;
//     private using: Box;
//     private videoget: Box;
//     private coinget:Box;
//     private getbtn:Button;
//     private videonum: Text;
//     private click_btn: Button;
//     private uiArr = [];
//     private skinGetForType: SkinGetForType;

//     private _data: any;
//     onAwake() {
//         this.selfobj = this.owner as Box;
//         this._select = this.selfobj.getChildByName("choose") as Image;
//         this._skin = this.selfobj.getChildByName("icon") as Image;
//         this.getbtn = this.selfobj.getChildByName("getbtn") as Button;
//         this.coinget = this.getbtn.getChildByName("coinget") as Box;
//         this.videoget = this.getbtn.getChildByName("videoget") as Box;
//         this.using = this.getbtn.getChildByName("using") as Box;
//         this.geted = this.getbtn.getChildByName("geted") as Box;
//         this.coinnum = this.coinget.getChildByName("coinnum") as Text;
//         this.videonum = this.videoget.getChildByName("videonum") as Text;
//         this.click_btn = this.selfobj.getChildByName("btn") as Button;

//         this.click_btn.clickHandler = new Laya.Handler(this,this._ClickHander);
//         this.getbtn.clickHandler = new Laya.Handler(this,this._Click1Handler);
//         EventManager.EventOn(EventState.ShowModel,this,this.ShowSelect);

//         this.uiArr.push(this.using);
//         this.uiArr.push(this.geted);
//         this.uiArr.push(this.coinget);
//         this.uiArr.push(this.videoget);
//     }

//     private comeType:number;
//     private instance:any;
//     RefreshItem(any?,comeType?) {
//         this.comeType=comeType;
//         if(any)this.instance=any;
//         else this.instance=SkinView.Instance;
//         this._data = (this.selfobj.dataSource);
//         var _id = this._data.id;
//         var usingId = Number(AccountManager.Instance.curplayerData.GainAccount("equip_themes")[1]);
//         console.log("usingid---",usingId);
//         var hasmotor = AccountManager.Instance.curplayerData.HasGun(_id);
//         var require_type = this._data.require_type;
//         this._skin.skin = "subpackage/res/skin/" + this._data.icon + ".png";
//         if (usingId == _id) {
//             this.skinGetForType = SkinGetForType.Using;
//             this.ShowUi();
//             return;
//         }
//         if (hasmotor) {
//             this.skinGetForType = SkinGetForType.Geted;
//             this.ShowUi();
//             return;
//         }
//         if (require_type == 2) {
//             this.skinGetForType = SkinGetForType.Coin;
//             this.coinnum.text = this._data.require_num.toString();
//             this.ShowUi();
//             return;
//         }
//         if (require_type == 3) {
//             this.skinGetForType = SkinGetForType.Video;
//             this.videonum.text = AccountManager.Instance.curplayerData.GetProgress(_id) + "/" + this._data.require_num;
//             this.ShowUi();
//             return;
//         }
//     }
//     ShowUi() {
//         var type = this.skinGetForType;
//         this._select.visible = type == SkinGetForType.Using;
//         if(this._select.visible){
//             SKinView.Instance.demagetext.text = "+" + this._data.atkUp;
//             SKinView.Instance.bullettext.text = "+" + this._data.ammoUp;
//         }
//          console.log("this._select.visible",this._select.visible);
//          for (let index = 0; index < this.uiArr.length; index++) {
//             if (index == type) {
//                 this.uiArr[index].visible = true;
//             } else {
//                 this.uiArr[index].visible = false;
//             }
//         }
//     }
//     _ClickHander() {
//         if (this._data.id == this.instance.showId) return;
//         this.ShowModel();
//     }


//     _Click1Handler() {
//         switch (this.skinGetForType) {
//             case SkinGetForType.Coin:
//                 var money = Number(AccountManager.Instance.curplayerData.GainAccount("money"));
//                 if (money < Number(this._data.require_num)) { 
//                     WXSDK.ShowTxt("金币不足--")
//                 }
//                 else {
//                     this.Buy();
//                 }
//                 break;
//             case SkinGetForType.Video:
//             console.log("视频获取--")
//                 this.VideoGet();
//                 break;
//             case SkinGetForType.Geted:
//             console.log("已经拥有--")
//                 this.Use();
//                 break;
//         }
//         if (this._data.id == this.instance.showId) return;
//         this.ShowModel();
//     }
//     ShowModel() {
//         if (!this.instance) return;
//         if (this._data.id == this.instance.showId) return;
//         this.instance.showId = this._data.id;
//         EventManager.EventTrigger(EventState.ShowModel);
//         ShopScene.Instance.CreateGun(this._data.id)

//         SKinView.Instance.demagetext.text = "+" + this._data.atkUp;
//         SKinView.Instance.bullettext.text = "+" + this._data.ammoUp;
//     }
//     ShowSelect() {
//         if (!this._data) return;
//         this._select.visible = this.instance.showId == this._data.id;
//     }
//     //视频获取
//     VideoGet(){
//         let stage = Number(AccountManager.Instance.curplayerData.GainAccount("stage")) + 1;
//         window['zzsdkui'].aliEvent('watchVideo', {'page': "skin"})
//         window['zzsdkui'].aliEvent('watchVideo', {'level': stage.toString()})
//         GuangGao.ShowVideo(isLoaded => {
//             if (isLoaded) {
//                 WXSDK.ShowTxt("获得奖励");
//                 var getkey = JtSniper.ShareGetSkin;
//                 var agrs = [{ "id": this._data.id.toString() }, { "channel": "video" }, { "t": AccountManager.Instance.ServerTime.toString() }];
//                 ServerManager.Instance.SendHttp(getkey, agrs, Laya.Handler.create(this, this.VideoGetSuccess), Laya.Handler.create(this, this.VideoGetFail));
//             }
//         })
//     }
//     //视频获取成功
//     VideoGetSuccess(_data){
//         if (!this.instance) return;
//         this.instance.RefreshItem();
//         console.log("LookVideo->suc:" + JSON.stringify(_data));
//     }
//     //视频获取失败
//     VideoGetFail(_data){
//         console.log("LookVideo->suc:" + JSON.stringify(_data));
//     }
//     //使用摩托车
//     Use() {
//         var agrs = [{ "id": this._data.id }];
//         ServerManager.Instance.SendHttp(JtSniper.WearEquip, agrs,Laya.Handler.create(this,this.UseSuccess),Laya.Handler.create(this,this.UseFail));
//     }
//     //使用成功
//     UseSuccess(data){
//       if(SkinView.Instance)
//       SkinView.Instance.RefreshItem();
//         WXSDK.ShowTxt("装备成功!");
//         console.log("装备suc:" + JSON.stringify(data));
//     }
//     //使用失败
//     UseFail(data){
//         console.log("装备err:" + JSON.stringify(data));
//     }
//     //购买
//     Buy() {
//         var agrs = [{"id":this._data.id.toString()}];
//         console.log(this._data.id);
//         ServerManager.Instance.SendHttp(JtSniper.BuyEquip, agrs,Laya.Handler.create(this,this.BuySuccess),Laya.Handler.create(this,this.BuyFail));
//     }
//     //购买成功
//     BuySuccess(data){
//         if (!this.instance) return;
//         this.instance.RefreshItem();
//         console.log("购买suc:" + JSON.stringify(data));
//     }
//     //购买失败
//     BuyFail(data){
//         console.log("购买fail:" + JSON.stringify(data));
//     }
//     //销毁
//     onDestroy() {
//         this.click_btn.clickHandler = null;
//         EventManager.EventOff(EventState.ShowModel,this,this.ShowSelect);
//         // DispatcherControl.DispatcherOff(DispatcherState.ShowModel,this,this.ShowSelect);
//     }
// }
