// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import apis1 from './util/apis1.js'
import animated from "animate.css";
import jdLogin from "./util/login";
import store from "./store/store";
import scroll from 'vue-seamless-scroll'
import axios from "axios";
// import LzEvent from 'lz-event-tracking/lib/vue';
// const LzEvent = require('./js/tracking.js')
// import LzEvent from './js/tracking.js'

import LzEvent from '../static/utils/tracking.js'
console.log(LzEvent,'LzEvent11222');

// import clickOut from './util/directive/customInstruction.js'

// console.log(Vue, 'Vue')
// 引入所有自定义封装的组件
// console.log(LzEvent)
import './router/GlobalComponents.js'

// import wx from "@weixin-js-sdk";
var wx = require('weixin-js-sdk');

import {
	getUrlQueryValueByKey
} from './util/tools.js'
import VConsole from 'vconsole';


import {
	Toast,
	Dialog,
	NoticeBar
} from "vant";
Vue.use(Toast);
Vue.use(Dialog);
Vue.use(NoticeBar);



// 多个指令引入
Vue.use((Vue) => {
	((requireContext) => {
		const arr = requireContext.keys().map(requireContext);
		(arr || []).forEach((directive) => {
			directive = directive.__esModule && directive.default ? directive.default : directive;
			Object.keys(directive).forEach((key) => {
				Vue.directive(key, directive[key]);
			});
		});
	})(require.context('./util/directive', false, /^\.\/.*\.js$/));
});


import VueAwesomeSwiper from 'vue-awesome-swiper';
import Swiper, {
	Pagination,
	Autoplay
} from "swiper";
Swiper.use([Pagination, Autoplay]);
Vue.use(VueAwesomeSwiper, /* { default options with global component } */ )

Vue.use(scroll)
Vue.use(animated);
Vue.config.productionTip = false
Vue.prototype.publicData = new Vue()
Vue.prototype.toast = Toast
Vue.prototype.dialog = Dialog
// console.log('******', process)

sessionStorage.setItem('isC', 'c');
// import basicCom from './components/basicCom/basicMain.vue'
// Vue.component('basicCom',()=>import ('./components/basicCom/basicMain.vue'))
// Vue.use(basicCom)

let cur_url = location.href;
var appName = ''
appName = getUrlQueryValueByKey('prd', cur_url)
Vue.use(LzEvent, {

	env: process.env.TRACKING, //test 测试 prod生产
	platform: 'JD', // JD、SUNING、…………
	sys: 'interaction', // 系统来源，例如：interact - 营销子系统， decoration - 装修子系统，不可以为空
	appName: appName, // 应用名称：crm - 云鹿， cjwx - 超级无线，不可以为空
	scrollOnBody: false, // 页面body元素是否可以滚动，可以为空
	axios, // axios，不可以为空
	requestType: 1, // 请求使用的类库 1 - axios，可以为空

	// 以下信息京东数据回流的时候需要使用
	siteId: 'JA2019_2132395', // 京东侧注册的网站id
	userPin: store.state.customerId, // 京东用户pin(customerId)
	shareUserPin: store.state.shareUserPin, // 如果是分享进入的本页面需要分享人的标识
})

let {
	getToken,
	initPage,
	initPage1
} = apis1;

// let cur_url = location.href;
// console.log(location.href,"zzzzzzzzzzzzzzzzzzzzzz")
var templatePage = getUrlQueryValueByKey('templatePage', cur_url);
if (templatePage) {
	this.isTemplatePage = true
} else {
	this.isTemplatePage = false
}

router.beforeEach((to, from, next) => {
	console.log(to, 'to')
	console.log(process.env.ENV_CONFIG, 'process.env.ENV_CONFIG111')
	if (this.isTemplatePage && !to.name) {
		next({
			replace: true,
			name: 'InitIndex',
			query: to.query
		});
	} else {
		if (store.state.token) {
			// console.log(to, 'to')
			console.log('已经登录成功');
			next();
		} else if (to.name === 'index') {
			// console.log(to, 'to')
			next({
				replace: true,
				name: 'InitIndex',
				query: to.query
			});
		} else {
			// console.log(to, 'to')
			console.log('已经登录')
			// window.location.href = '/index';
			next() //新增这一句
		}
	}
});
let vConsole = new VConsole();
// const createApp = () => {
new Vue({
	router,
	store,
	render: h => h(App),
	mounted: function() {
		this.fetchData();

	},
	methods: {
		fetchData() {
			const that = this;
		},
	},
}).$mount("#appC");
// };

// initPage1(() => {
//   let cur_url = location.href;
//   let index = cur_url.indexOf('?');
//   let paramStr = cur_url.substring(index + 1, cur_url.length);
//   let params = paramStr.split('&');

//   let paramsName = 'activityType' //活动类型
//   let paramsActivityId = 'activityId' //活动id
//   let shareUserId = 'shareUserId' //分享人id
//   let templatePages = 'templatePage' //分享人id
//   // console.log(cur_url.indexOf(templatePages))

//   if (cur_url.indexOf(templatePages) >= 0) {
//     this.isTemplatePage = true;
//   } else {
//     this.isTemplatePage = false;
//   }

//   params.forEach(element => {
//     if (element.indexOf(paramsName) >= 0) {
//       this.activityType = element.substring(element.indexOf('=') + 1, element.length);
//       sessionStorage.setItem('activityType', this.activityType)
//     }
//     if (element.indexOf(paramsActivityId) >= 0) {
//       var activityId = element.substring(element.indexOf('=') + 1, element.length);
//       store.commit('setActivityId', activityId); //1344185866492006402
//     }

//     //判断是否有分享人id shareUserId
//     if (element.indexOf(shareUserId) >= 0) {
//       var shareUserId1 = element.substring(element.indexOf('=') + 1, element.length);
//       store.commit('setShareUserId', shareUserId1); //1344185866492006402
//     } else {
//       store.commit('setShareUserId', ''); //1344185866492006402
//     }

//   });
//   // console.log('this.isTemplatePage', this.isTemplatePage)
//   // console.log(location.origin)

//   // if (this.isTemplatePage) {
//     createApp();
//   // } else {
//   //   if (process.env.NODE_ENV == "development") {
//   //     getToken(() => {
//   //       createApp();
//   //     })
//   //   } else {
//   //     jdLogin(() => {
//   //       getToken(() => {
//   //         createApp();
//   //       })
//   //     });
//   //   }
//   // }

// });
