<template>
  <div class="dashboard-container">
    <div class="dashboard-text">name: {{ name }}</div>
    <div>时间：{{ $moment('2018-09-19T05:54:32.767Z').format("YYYY-DD-MM HH:mm:ss") }}</div>
    <div class="dashboard-text">
      roles:
      <span v-for="role in roles" :key="role">{{ role }}</span>
    </div>
    <div>
      身份证：
      <el-input v-model="iDCard" style="width:300px" placeholder="请输入身份证号" @change="checkId" />
      <el-button @click="checkId">查询</el-button>
      <span v-show="show" style="color:red">{{ message }}</span>
      <span v-show="show != true">{{ message }}</span>
    </div>
    <el-button type="primary" @click="drawer = true">2.12.0组件的Drawer 抽屉</el-button>
    <el-drawer title="我是标题" :visible.sync="drawer" direction="rtl">
      <span>我来啦!</span>
    </el-drawer>
    <el-button type="primary" icon="iconfont chinawealicon_group">按钮</el-button>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'Dashboard',
  data: function() {
    return {
      drawer: false,
      iDCard: '',
      message: '',
      show: false
    }
  },
  computed: {
    ...mapGetters(['name', 'roles'])
  },
  mounted() {
  },
  methods: {
    checkId() {
      var IDValidator = require('id-validator')
      // var GB2260 = require('id-validator/src/GB2260')
      var Validator = new IDValidator()
      // var id = '123456789012345678'
      Validator.isValid(this.iDCard)
      // 合法号码return true, 不合法return false
      if (Validator.isValid(this.iDCard, 18) === false) {
        this.show = true
        this.message = '请输入合法的身份证号码'
      } else {
        this.message = '身份证校验通过'
        this.show = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

</style>
