<!-- 人員資料 -->
<template>
  <div>
    <functionBar class="F_bar"></functionBar>
    <div>
      <b-table
        class="text-center"
        thead-class="thClass"
        small
        responsive="sm"
        ref="selectableTable"
        striped
        bordered
        :fields="fields"
        :per-page="perPage"
        :current-page="currentPage"
        fixed
        :items="list"
        :sort-desc.sync="sortDesc"
        :sort-by.sync="sortBy"
      >
        <!-- HEAD -->
        <template #head()="{ label, field: { key, sortable } }">
          <span style="font-weight: normal; color: white; font-size: 15px">{{
            label
          }}</span>
          <template v-if="sortable">
            <b-icon
              font-scale="1.3"
              v-if="sortBy !== key"
              icon="arrow-down-up"
            ></b-icon>
            <b-icon
              font-scale="1.3"
              v-else-if="sortDesc"
              icon="arrow-down"
            ></b-icon>
            <b-icon font-scale="1.3" v-else icon="arrow-up"></b-icon>
          </template>
        </template>

        <!-- BODY -->
        <template #cell(staffID)="data">
          <span style="font-weight: normal; color: black; font-size: 14px">{{
            data.value
          }}</span>
        </template>

        <template v-if="test" #cell(name)="data">
          <span style="font-weight: normal; color: black; font-size: 15px">{{
            data.value
          }}</span>
        </template>
        <template v-else #cell(name)="data">
          <span style="font-weight: normal; color: black; font-size: 15px">{{
            data.value
          }}</span>
        </template>

        <template #cell(email)="data">
          <span style="font-weight: normal; color: black; font-size: 14px">{{
            data.value
          }}</span>
        </template>
        <template #cell(projectTitle)="data">
          <span style="font-weight: normal; color: black; font-size: 14px">{{
            data.value
          }}</span>
        </template>
        <template #cell(group)="data">
          <span style="font-weight: normal; color: black; font-size: 14px">{{
            data.value
          }}</span>
        </template>
        <template #cell(contactNumber)="data">
          <span style="font-weight: normal; color: black; font-size: 14px">{{
            data.value
          }}</span>
        </template>
        <template #cell(substitute)="data">
          <span style="font-weight: normal; color: black; font-size: 14px">{{
            data.value.name
          }}</span>
        </template>
      </b-table>
    </div>
    <b-pagination
      v-model="currentPage"
      :total-rows="rows"
      :per-page="perPage"
      aria-controls="my-table"
    ></b-pagination>
  </div>
</template>

<script>
import functionBar from '@/views/BasicSetting/PersonalSetting/MainPage/functionBar.vue'
import staffInformation from '@/views/BasicSetting/PersonalSetting/ModalContent/staffInformation.vue'

export default {
  data () {
    return {
      test: true,
      StaffInformationModalOpen: false,
      perPage: 12,
      currentPage: 1,
      sortBy: null,
      sortDesc: false,
      list: [],
      fields: [
        {
          key: 'staffID',
          label: '人員編號',
          sortable: true,
          thStyle: { width: '10%' }
        },
        {
          key: 'name',
          label: '姓名',
          thStyle: { width: '10%' }
        },
        {
          key: 'email',
          label: '電子郵件',
          thStyle: { width: '15%' }
        },
        {
          key: 'contactNumber',
          label: '聯絡電話',
          thStyle: { width: '10%' }
        },
        {
          key: 'group',
          label: '群組',
          sortable: true,
          thStyle: { width: '10%' }
        },
        {
          key: 'projectTitle',
          label: '計畫職稱',
          sortable: true,
          thStyle: { width: '10%' }
        },
        {
          key: 'substitute',
          label: '職務代理人',
          thStyle: { width: '10%' }
        }
      ],
      selectMode: 'single'
    }
  },
  methods: {
    async pushTo (data) {
      this.$router.push({
        name: 'StaffInformationSetting',
        query: { sid: data._id }
      })
    }
  },
  async mounted () {
    this.list = await this.$store.dispatch('project/lookupStaffs', {
      selects: ['_id', 'staffID', 'name', 'email', 'contactNumber', 'group', 'projectTitle', 'substitute']
    })
    console.log(this.list)
  },
  computed: {
    rows () {
      return this.list.length
    }
  },
  components: {
    functionBar,
    modal: () => import('@/views/Modal/index.vue'),
    staffInformation
  }
}
</script>

<style >
.thClass {
  background-color: #1d325f;
  color: white;
}
.table.b-table > thead > tr > th,
.table.b-table > tfoot > tr > td {
  background-image: none !important;
}
</style>
<style scoped>
.text-center {
  width: 100%;
  height: 100%;
  padding-left: 5%;
  padding-right: 5%;
  margin-top: 90px;
}
.text {
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn1 {
  background-color: rgb(75, 102, 255);
  font-size: 16px;
  color: #ffffff;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
  border: none;
}
.btn1:hover {
  color: rgb(255, 255, 255);
  background-color: rgb(49, 68, 175);
  transform: translateY(0);
}
.btn2 {
  background-color: #f7fafc;
  font-size: 14px;
  padding-left: 7px;
  padding-right: 7px;
  padding-top: 5px;
  padding-bottom: 5px;
  margin-left: 10px;
  color: #1d325f;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
}
.btn2:hover {
  color: black;
  background-color: rgb(228, 228, 228);
  transform: scale(1.1);
}
.pagination {
  padding-left: 45%;
  padding-bottom: 20px;
  margin-top: 70px;
}
</style>
