import Vue from 'vue'
// import store from '@/store'

// let permissionArr = store.getters.permission

Vue.directive('permission', {
  inserted (el, binding) {
    let value = binding.value
    let permission = window.localStorage.getItem('permission')
    permission = permission.split(',')
    // 如果一个权限判断不了则用两个
    // 格式： v-permission="{child: 'child', parent: 'parent'}"
    // 在特殊情况下才会用到两个参数，基本情况只会用到一个标识
    if (typeof value == 'string') {
      if (!permission.includes(value)) {
        // el.style.display = 'none'
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      if (permission.includes(value.parent) && permission.includes(value.child)) {
        // el.style.display = 'none'
      } else {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }

  }
})


Vue.directive('number', {
  inserted (el) {
    el.oninput = function (e) {
      let value = '' + e.target.value
      if (value.indexOf('.') != -1) {
        let arr = value.split('')
        arr.splice(arr.length - 1)
        let str2 = arr.join('')
        e.target.value = +str2
        return
      }
    }
  }
})
