export default {
	install(Vue){
		Vue.prototype.getOpenid = function(page) {
        var host='http://47.101.145.23/tianzong';
        //var host='http://localhost:8080/tianzong';
		    if (localStorage.getItem("openid") != 'undefined' && localStorage.getItem("openid") != null)
		      return;
		    var code = this.getUrlParam("code");
		    if (code == 'undefined' || code == null || code == "") {
		      //alert("参数异常，请返回首页重试");
		      this.urlredirect(page);
		      return;
		    }
		    this.$http.post(host + "/weixin/getWxUserInfo", {
		        code: code,
			userId:localStorage.getItem("userId")
		      }, {
		        emulateJSON: true
		      })
		      .then(res => {
		        //发送成功
			console.log(res);

		        if (res.body.code == '0') {
		          localStorage.setItem("openid", res.body.openId);
		          localStorage.setItem("headimgurl", res.body.headimgurl);
		          //this.$store.commit("getId",res.body.data)
		        } else {
		          //console.log(res);
		          this.urlredirect(page);
		        }

		        //if()
		      }, res => {
		        //发送失败
		      })

		  }

		Vue.prototype.urlredirect=function(page) {
		  var host='http://47.101.145.23/wuliu/ljy/';
		  window.location.href =
		    "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3d3b98cc26425f40&redirect_uri=" + host + page + "&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect";
		}
		Vue.prototype.getUrlParam = function(name) {
			var vars = [],
				hash;
			var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
			for (var i = 0; i < hashes.length; i++) {
				hash = hashes[i].split('=');
				vars.push(hash[0]);
				vars[hash[0]] = hash[1];
			}
			return decodeURIComponent(vars[name]);
		}

    Vue.prototype.getUser=function(){
    	this.$http.post(this.$store.state.host+"/personal/getSysUserInfoByUserId.do",{userId:this.userId},{emulateJSON:true})
    		.then(res=>{
    				//发送成功
    				if(res.body.msg=='success'){
    					this.user=res.body.sysUserInfo;
              console.log("getUser:" + res.body.sysUserInfo)
    				}
    	},res=>{
    				 //发送失败
    	})
    }
		//快递公司列表
		Vue.prototype.getLogisticsList=function(){
			this.$http.post(this.$store.state.host+"/sendMail/getLogisticsList.do",{},{emulateJSON:true})
				.then(res=>{
					//发送成功
					if(res.body.msg=='success'){
						this.columns = res.body.list
						for(var i=0;i<this.columns.length;i++){
							this.columns[i].text = this.columns[i].expressCompany
						}
					}
			},res=>{
					 //发送失败
			})
		}
    //成本中心列表
    Vue.prototype.getCostCenterList=function(){
    	this.$http.post(this.$store.state.host+"/sendMail/getCostCenterList.do",{mailRoomId:this.mailRoomId},{emulateJSON:true})
    		.then(res=>{
    			//发送成功
    			if(res.body.msg=='success'){
    				this.costCenterList = res.body.list
    				for(var i=0;i<this.columns.length;i++){
    					this.columns[i].text = this.columns[i].expressCompany
    				}
    			}
    	},res=>{
    			 //发送失败
    	})
    }

		//登录判断
		Vue.prototype.isLogin=function(){
			this.$http.post(this.$store.state.host+"/appSysUser/isLogin.do",{
				},{emulateJSON:true})
				.then(res=>{
					console.log(res.body)
					//发送成功
					if(res.body.msg=='success'){
            console.log("isLogin=Y")
					}else{
            //本地 注释  服务器 放开
						//localStorage.clear();
					}
			},res=>{
					 //发送失败
			})
		}
	}


}
