import Vue from 'vue'
import App from './App'
import config from './common/js/config'
import router from './common/js/router'
import store from './common/store/index'
import fn from './common/js/index'
import log from './common/js/log'
import api from './common/api/index'
import * as filters from './common/js/filters'

App.mpType = 'app'
Vue.config.productionTip = false
Vue.prototype.config = config
Vue.prototype.router = router
Vue.prototype.$store = store
Vue.prototype.fn = fn
Vue.prototype.log = log
Vue.prototype.api = api

// 全局混入
Vue.mixin({
    // 数据
    data() {
        return {}
    },

    // 页面加载
    onLoad() {
        // #ifdef MP
        uni.hideShareMenu()
        // #endif
        // 隐藏tabbar 手写
        // uni.hideTabBar({});
    },

    // 页面隐藏
    onHide() {
        const self = this

        // 恢复预览类型
        self.$store.commit('common/update', {
            preview: '0',
        })

        // 改为可以支付的状态
        self.$store.commit('common/update', {
            payStatus: true,
        })
    },

    methods: {
        // 跳转到指定页面
        jump(option) {
            const self = this
            self.router.push(option)
        },

        // 替换当前页面为指定页面
        jumpReplace(option) {
            const self = this
            self.router.replace(option)
        },

        // 跳转到webView
        jumpWebView(url, title) {
            const self = this
            self.router.push({
                path: '/pages/webView/index',
                query: {
                    url: url,
                    title: title,
                },
            })
        },

        // 返回上一页
        back() {
            const self = this
            self.router.back()
        },
    },

    // 数据计算
    computed: {
        iphoneX() {
            return this.$store.state.common.iphoneX
        },
    },
})

// 注册过滤器
Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key])
})

const app = new Vue({
    ...App,
})
app.$mount()
