<script>
/**
 * vuex管理登陆状态，具体可以参考官方登陆模板示例
 */
import Vue from 'vue'
import { mapActions, mapMutations } from 'vuex'
export default {
    onLaunch: function() {
        console.log('清空本地缓存')
        uni.clearStorageSync()
        this.initSystemInfo()
        this.wechatlogin()
        // 判断优惠券弹窗是否显示
        // this.checkShowCouponPopup()
    },
    methods: {
        ...mapActions('app', ['setWindowHeight', 'setVariableFun']),
        ...mapActions('user', ['wechatlogin']),
        ...mapMutations('coupon', ['setCouponPopupStatus']),
        ...mapMutations('app', ['setWindowHeight']),
        // 验证是否需要显示优惠券入口弹窗
        checkShowCouponPopup() {
            const couponPopupType = uni.getStorageSync('couponPopupType')
            const nowDay = new Date().getDay()
            // 新用户 当天不弹窗
            if (couponPopupType === nowDay) {
                this.setCouponPopupStatus(false)
            }
        },
        initSystemInfo() {
            let self = this
            uni.getSystemInfo({
                success: function(e) {
                    let modelmes = e.model
                    self.setWindowHeight(e.windowHeight)
                    console.log(modelmes)
                    // iphone x以上的版本都要控制下巴高度
                    console.log(/iphone [1|x]\s?/i.test(modelmes))
                    if (/iphone [1|x]\s?/i.test(modelmes)) {
                        self.setVariableFun(true)
                    } else {
                        self.setVariableFun(false)
                    }
                    // #ifndef MP
                    Vue.prototype.StatusBar = e.statusBarHeight
                    if (e.platform == 'android') {
                        Vue.prototype.CustomBar = e.statusBarHeight + 50
                        Vue.prototype.platformClass = true
                    } else {
                        Vue.prototype.CustomBar = e.statusBarHeight + 45
                        Vue.prototype.platformClass = false
                    }
                    // #endif

                    // #ifdef MP-WEIXIN || MP-QQ
                    if (e.platform == 'android') {
                        Vue.prototype.platformClass = 'left'
                    } else {
                        Vue.prototype.platformClass = 'center'
                    }
                    Vue.prototype.StatusBar = e.statusBarHeight
                    Vue.prototype.fontSizeSetting = e.fontSizeSetting
                    Vue.prototype.screenWidth = e.screenWidth
                    let capsule = wx.getMenuButtonBoundingClientRect()
                    Vue.prototype.capsule = capsule
                    if (capsule) {
                        Vue.prototype.Custom = capsule
                        Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
                    } else {
                        Vue.prototype.CustomBar = e.statusBarHeight + 50
                    }
                    // #endif
                    // #ifdef MP-ALIPAY
                    Vue.prototype.StatusBar = e.statusBarHeight
                    Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight
                    // #endif
                }
            })
        }
    }
}
</script>

<style lang="scss">
/*每个页面公共css */
@import '@/common/css/common.scss';
@import '@/common/css/iconfont.scss';
@import '@/common/css/style/thorui.css';
@import '@/common/css/style/icon.css';

view,
scroll-view,
swiper,
swiper-item,
cover-view,
cover-image,
icon,
text,
rich-text,
progress,
button,
checkbox,
form,
input,
label,
radio,
slider,
switch,
textarea,
navigator,
audio,
camera,
image,
video {
    // box-sizing: border-box;
}
// page {
//   width: 100%;
//   height: 100%;
//   background: #fff;
//   filter: grayscale(100%);
//   filter: gray;
//   filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
//   --toast-default-width: 114px;
// }
page {
    height: 100%;
    background-color: #ffffff;
}
/* 骨架屏替代方案 */
.Skeleton {
    background: #f3f3f3;
    padding: 20upx 0;
    border-radius: 8upx;
}

.clamp {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.common-hover {
    background: #f5f5f5;
}
/* input 样式 */
.input-placeholder {
    color: #999999;
}

.placeholder {
    color: #999999;
}
</style>
