// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
// TODO 路由
// let Http=require("../comment/Http")
let Http=require("NGame")
cc.Class({
    extends:Http,

    properties: {
    },
    /**
     * 验证token 是否失效
     */
    getoken(userid,callback){

        this.Http("/web/login/getoken",{userid:userid}, (req) => {
            let result=req.data
            if (result.bool==true){
                this.sets("token",result.token)//设置用户token
                let data=JSON.stringify(result)
                this.sets("user",data)// 设置用户数据
            } else {
                this.sets("token",result.token)//设置用户token
                let data=JSON.stringify(result)
                this.sets("user",data)// 设置用户数据
            }
        })
    },
    /**
     * 登录
     */
    login(callback){
        let userid=this.getsParam("shop_token")?this.getsParam("shop_token"):1
        // let token=this.gets("token")
        // if (!token){
            // this.Http("/web/login/index",{userid:userid}, (req) => {
            this.Http("/web/login/logins",{shop_token:userid}, (req) => {
                console.log("登录数据",req)
                if (req.code==1){
                    this.sets("token",req.data.token)//设置用户token
                    let data=JSON.stringify(req.data)
                    this.sets("user",data)// 设置用户数据
                }
                callback(req)
            })
        // }else {
        //     this.getoken(userid)
        //     callback("已经登录")
        // }
    },


});
