<script>
var user = require('./utils/user.js');
const util = require('./utils/util.js');
const api = require('./config/api.js');
var app = getApp();
export default {
    data() {
        return {};
    },
    onLaunch: function () {
        const updateManager = uni.getUpdateManager();
        uni.getUpdateManager().onUpdateReady(function () {
            updateManager.applyUpdate();
            // wx.showModal({
            //   title: '更新提示',
            //   content: '新版本已经准备好，是否重启应用？',
            //   success: function (res) {
            //     if (res.confirm) {

            //       updateManager.applyUpdate();
            //     }
            //   }
            // });
        });

        /*网络状态
  wx.onNetworkStatusChange(function (res) {
    if (res.networkType === 'none') {
      wx.showToast({
        title: '网络已断开',
        icon: 'none'
      })
    } else if (res.networkType === "2g" || res.networkType === "3g")
      wx.showToast({
        title: '您的网络状态不佳，' + res.networkType + '，建议使用wifi',
        icon: 'none'
      });
   })*/

       
		// util.request(api.appTheme, {
			
		//     }).then(res=> {
		//     if (res.errno === 0) {
				
		// 	}
		// 	});
		
		          //项目启动获取缓存中的皮肤
					const value = uni.getStorageSync('theme');
					console.log(value);
					if (value == 'jz') {
						this.$store.dispatch('handleActionAgree', 'jz');
						
					} else if (value == 'yj') {
						this.$store.dispatch('handleActionAgree', 'yj');
						
					} else {
						// this.$store.dispatch('handleActionAgree', 'yj');
						// this.$store.dispatch('handleActionCol', '#ff0000');
						// uni.setNavigationBarColor({
						// 	frontColor: '#000000',
						// 	backgroundColor:'#ff0000'
						// });
					}
					const appInstance = getApp();
					console.log(appInstance);
      this.getUserOpenId();
    },
    onLoad() {
        var updateManager = uni.getUpdateManager();
        updateManager.onUpdateReady((res) => {
            uni.showModal({
                title: '更新提示',
                content: '新版本已经准备好，是否重启小程序？',
                success: (res) => {
                    if (res.confirm) {
                        // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                        updateManager.applyUpdate();
                    }
                }
            });
        });
        updateManager.onUpdateFailed((err) => {
            // 新的版本下载失败
            console.log('版本下载失败原因', err);
            uni.showToast({
                title: '新版本下载失败，请稍后再试',
                icon: 'none'
            });
        });
		
    },
	methods:{
	  async getUserOpenId() {
	    let that = this;
	    let res = await user.userOpenId();
	    console.log(res);
	       let openId=res.data;
		   getApp().globalData.openId=res.data;
		      let uuid= uni.getStorageSync('uuid');
		     if(openId==''||openId==null||openId==undefined){
			   // 生成uuid
			   if(!uuid){
				    uuid=util.creadUuid();
				    uni.setStorageSync('uuid',uuid);
			   }
			  
			   
		   }
		    getApp().globalData.uuid=uuid;
	  
	    // uni.setStorageSync('openId', res.data);
	  
	},
	},
    onShow: function (options) {
        /*是否授权登录*/
        user.checkLogin()
            .then((res) => {
                this.globalData.hasLogin = true;
                if (this.globalData.checkLoginReadyCallback) {
                    this.globalData.checkLoginReadyCallback();
                }
            })
            .catch(() => {
                this.globalData.hasLogin = false;
            });

        //购物车数据显示
        //user.cartcount();
    },
    globalData: {
		uuid:'',
		openId:'',
        hasLogin: false,

        //是否授权登录
        isMember: false,

        //是否是会员
        userInfo: {},

        r_userid: 0,

        //推荐人id
        iscert: false,

        //是否注册过
        mapKey: 'AEZBZ-7JYL6-N4WSL-EFMOK-SAHSO-GLFA4',

        currentLocationName: '位置获取中',
        city: '',
        rId: '',

        //引荐人ID
        shareImage: '',

        recommend: {
            //引荐人信息
            userName: '',
            avatarUrl: '',
            bCode: '',
            phone: '',
            unionId: '',
            openId: '',
            sessionKey: ''
        },

        infoGoods: {
            picUrl: '',
            name: '',
            brief: '',
            type: '0',
            id: ''
        },

        //信息收集,
        infoAddress: {
            addressId: '',
            addressDetail: ''
        },

        memberUserInfo: {
            nickName: '',
            avatarUrl: '/static/images/new/icon-user.png'
        },

        checkLoginReadyCallback: function () {
            //是否登录
            this.hasLogin = true;
        }
    }
};

//购物车隐藏
// {
//   "pagePath": "pages/tabBar/cart/cart",
//   "iconPath": "static/images/cart.png",
//   "selectedIconPath": "static/images/cart@selected.png",
//   "text": "购物车"
// },
</script>
<style>
/**app.ttss**/

.container {
    box-sizing: border-box;
    background-color: #f5f5f5;
    font-family: PingFangSC-Light, helvetica, 'Heiti SC';
}

view,
image,
text,
navigator {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
}
page {
    color: #2a2a2a; /*主要颜色*/
    font-size: 28rpx;
    background: #f5f5f5;
}
text,
view {
    font-family: PingFangSC-Light, helvetica, 'Heiti SC';
    /* font-weight: 500; */
}
.sub-color {
    color: #85868a;
}
.jz-color {
    color: #09afff; /*鲸致色号00AFFF*/
}
.van-tab > view.van-ellipsis {
    color: #888;
}
.van-tab--active.van-tab > view.van-ellipsis {
    color: #09afff;
}

van-dialog .van-button {
    color: #09afff !important;
}
.van-dialog__message-text {
    color: #666;
}
.van-button--info {
    background: #09afff !important;
    border: none !important;
}
.bottom-fixed-btn-wrapper {
    position: fixed;
    bottom: 146rpx;
    left: 0;
    right: 28rpx;
    left: 28rpx;
}
.bottom-fixed-btn-wrapper .van-button {
    height: 74rpx;
    border: none;
}

.common-btn-wrapper {
    margin: 0 28rpx 0;
}
.common-btn-wrapper .van-button {
    height: 74rpx;
    margin: 0 0 48rpx 0;
}
/* 云嘉样式 */
/* .yj.container .new-item-right{
	background: #f18342;
}
.yj.container .add-address{
	background: #f18342;
} */
</style>
