import Vue from 'vue'
import App from './App'
import uView from 'uview-ui'
Vue.use(uView)

Vue.config.productionTip = false

import store from './store'
import _ from 'lodash'

import globalMixin from './mixins/global'

import { jump, jumpToTabbar, goBack, getJumpParam } from './utils/jumpUtil'

Vue.mixin({
	data() {
		return {
			baseUrl: 'https://adminapi.jfcmei.com/admin/storage/fetch/',
			lazyLoadingMode: 'skeleton-2',
			common: {
				// 拼接展示图片url
				// splicingImgUrl() {
				// 	return 'https://adminapi.jfcmei.com/admin/storage/fetch/'
				// },
				seamingImgUrl(url) {
					if (!url) return ''
					// return url.startsWith('https://') ? url : 'https://adminapi.jfcmei.com/admin/storage/fetch/' + url
					return url.startsWith('https://') ? url : 'https://jufeng-shop-1317254189.cos.ap-guangzhou.myqcloud.com/' + url
				},
				explainMembership(roleIds) {
					let roleName
					switch (roleIds) {
						case 1:
							roleName = '超级管理员'
							break
						case 2:
							roleName = '分公司管理员'
							break
						case 3:
							roleName = '高级营销策划师'
							break
						case 4:
							roleName = '初级营销策划师'
							break
						case 5:
							roleName = '普通营销策划师'
							break
						case 6:
							roleName = '会员商户'
							break
						case 7:
							roleName = '普通商户'
							break
						case 8:
							roleName = '商户高级业务员'
							break
						case 9:
							roleName = '商户初级业务员'
							break
						case 10:
							roleName = '普通会员'
							break
						case 11:
							roleName = '游客'
							break
						case 12:
							roleName = '推广管理员'
							break
						case 13:
							roleName = '商场管理员'
							break
						default:
							roleName = '未知会员类型'
							break
					}
					return roleName
				}
			}
		}
	},
	methods: {
		$showToast(text, icon) {
			uni.showToast({
				title: text,
				duration: 2000,
				icon: icon || 'none'
			})
		},
		go(url) {
			if (!url) {
				return
			}
			uni.navigateTo({
				url
			})
		},
		$copy(text, title = '复制成功') {
			uni.setClipboardData({
				data: text,
				success: () => {
					uni.showToast({
						title
					})
				}
			})
		},
		$switchTab(url) {
			if (!url) return
			uni.switchTab({ url })
		}
	}
})

Vue.prototype.$store = store
Vue.prototype.$lodash = _
Vue.prototype.$jump = jump
Vue.prototype.$jumpToTabbar = jumpToTabbar
Vue.prototype.$goBack = goBack
Vue.prototype.$getJumpParam = getJumpParam
Vue.use(globalMixin)
App.mpType = 'app'

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