import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets
// global css
import Element from 'element-ui'
import './assets/styles/element-variables.scss'
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
// customize css
import '@/assets/styles/index.scss'
import '@/assets/styles/customize.scss'
import App from './App'
import store from './store'
import router from './router'
import permission from './directive/permission'


import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictLabels,
  download,
  handleTree,
  formatOrganName,
} from "@/utils/customize";
import Pagination from "@/components/Pagination";

// 2021-12-1 Another 防止重复点击
import preventReClick from './preventRepeatClick';

// 引入vue-amap
import VueAMap from 'vue-amap';
Vue.use(VueAMap);

// 初始化vue-amap
// VueAMap.initAMapApiLoader({
//   // 高德的key
//   key: '02e8528c09511e90eb703035a4650bfd',
//   // 插件集合
//   plugin: [
//     "AMap.Autocomplete", //输入提示插件
//     "AMap.PlaceSearch", //POI搜索插件
//     "AMap.Scale", //右下角缩略图插件 比例尺
//     "AMap.OverView", //地图鹰眼插件
//     "AMap.ToolBar", //地图工具条
//     "AMap.MapType", //类别切换控件，实现默认图层与卫星图、实施交通图层之间切换的控制
//     "AMap.PolyEditor", //编辑 折线多，边形
//     "AMap.CircleEditor", //圆形编辑器插件
//     "AMap.Geolocation",//定位控件，用来获取和展示用户主机所在的经纬度位置
//     "AMap.Marker"
//   ],
//   uiVersion: "1.0.11",
//   // 高德 sdk 版本，默认为 1.4.4
//   v: '1.4.4'
// });

//Vue.use(Viewer) 默认配置写法
Vue.use(Viewer, {
  defaultOptions: {
    zIndex: 9999
  }
})

VueAMap.initAMapApiLoader({
  key: "d9e86245068de376797a48478cd7ad82",
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor', 'AMap.Geolocation', 'AMap.Geocoder'],
  uiVersion: "1.1", // ui库版本，不配置不加载,
  v: "1.4.4"
});

// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree

// 代理一下返回值
Vue.prototype.formatOrganName = function(id){
  return formatOrganName(store.getters.dataScope,id)
}

// 打印太麻烦 简单封装下
Vue.prototype.log = function (msg) {
  console.log(JSON.stringify(msg))
}

Vue.prototype.msgSuccess = function (msg) {
  this.$message({ showClose: true, message: msg, type: "success" });
}


Vue.prototype.msgError = function (msg) {
  this.$message({ showClose: true, message: msg, type: "error" });
}

Vue.prototype.msgInfo = function (msg) {
  this.$message.info(msg);
}

// 全局组件挂载


Vue.component('Pagination', Pagination)

Vue.use(permission)

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})

// 2021-12-1 Another 防止重复点击
Vue.use(preventReClick)

// 2021-12-15 Another 格式化时间为：年-月-日 时：分
Vue.filter('formatDateTime', function(time) {
  if (!time) {
    return '';
  }

  let date = new Date(time)
  let year = date.getFullYear();
  let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  let minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  return year + "-" + month + "-" + day + " " + hour + ":" + minute;
})

// 2021-12-15 Another 格式化时间为：年-月-日 时:分(若 时分 是 00:00 则 不显示 时分)
Vue.filter('formatDateTimeMonth', function(time) {
  if (!time) {
    return '';
  }

  let date = new Date(time)
  let year = date.getFullYear();
  let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  let minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  if (hour === '00' && minute === '00') {
    return year + "-" + month + "-" + day;
  } else {
    return year + "-" + month + "-" + day + " " + hour + ":" + minute;
  }

})

// 2021-12-16 Another 视频播放组件
import VideoPlayer from 'vue-video-player'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'

Vue.use(VideoPlayer)

// 2021-12-21 Another 校验机构是否是项目
Vue.prototype.$validCommunity = function(id, organList) {
  let flag = false;
  if (!id || !organList || organList.size === 0) {
    return flag;
  }

  this.organList.forEach(vo => {
    if (vo.id === id && vo.type === '003') {
      flag = true;
    }
  })
  return flag;
}

