<template>
  <div>
    <functionBar class="F_bar" />
      <!-- 通訊錄列表 -->
      <div>
        <div class="container" fluid></div>
        <div style="margin-left: 20vw; margin-top: 25px; color: black; width: 45vw">
          <!-- 關鍵字 -->
          <b-row>
            <b-col cols="2">
            <div style="margin-top: 10px; text-align: right">關鍵字:</div>
            </b-col>
            <b-col cols="8">
              <b-form-input id="filter-input" v-model="filter" type="search" style="width:35vw; margin-left: -1.3vw"
            placeholder="請輸入關鍵字">
              </b-form-input>
            </b-col>
          </b-row>
        </div>
        <div style="width:80vw;overflow: auto;margin-left:3.5vw;height:75vh;margin-top: 1.5vh;position: relative; z-index: 1"
        >
          <!-- TABLE -->
        <b-table
          id="my-table"
          class="text-center"
          thead-class="thClass"
          small
          ref="selectableTable"
          striped
          fixed
          bordered
          :fields="fields"
          :filter="filter"
          :per-page="perPage"
          :current-page="currentPage"
          :items="list"
          :sort-desc.sync="sortDesc"
          :sort-by.sync="sortBy"
          align="center"
        >
          <!-- HEAD -->
          <template #head()="{ label, field: { key, sortable }}">
            <span style="font-weight: normal; color: white; font-size: 2vh">{{
              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(company)="data">
            <span style="font-weight:normal; color:black; font-size:1.9vh">{{data.value}}</span>
          </template>

          <!-- 標案組織 -->
          <template #cell(projectTitle)="data">
            <span style="font-weight:normal; color:black; font-size:1.9vh">{{data.value}}</span>
          </template>

          <!-- 計畫職稱 -->
          <template #cell(title)="data">
            <span style="font-weight:normal; color:black; font-size:1.9vh">{{data.value}}</span>
          </template>

          <!-- 人員名稱 -->
          <template #cell(name)="data">
            <span style="font-weight:normal; color:blue; font-size:1.9vh; cursor: pointer" @click="open(data.item._id)">{{data.value}}</span>
          </template>

          <!-- 聯絡電話 -->
          <template #cell(contractNumber)="data">
            <span style="font-weight:normal; color:black; font-size:1.9vh">{{data.value}}</span>
          </template>

          <!-- Email -->
          <template #cell(email)="data">
            <span style="font-weight:normal; color:black; font-size:1.9vh">{{data.value}}</span>
          </template>

          <!-- Gmail -->
          <template #cell(gmail)="data">
            <span style="font-weight:normal; color:black; font-size:1.9vh">{{data.value}}</span>
          </template>

          <!-- line -->
          <template #cell(line)="data">
            <span style="font-weight:normal; color:black; font-size:1.9vh">{{data.value}}</span>
          </template>

          <!-- 備註 -->
          <template #cell(remark)="data">
            <span style="font-weight:normal; color:black; font-size:1.9vh">{{data.value}}</span>
          </template>
        </b-table>
        </div>
      </div>
      <modal
      :isOpen="EditDirectoryModalOpen"
      title="編輯聯絡人"
      @closeEvent="EditDirectoryModalOpen = false"
    >
      <editDirectory @closeEvent="EditDirectoryModalOpen = false" />
    </modal>
    <!-- 分頁符號 -->
      <b-pagination
        v-model="currentPage"
        :total-rows="rows"
        :per-page="perPage"
        aria-controls="my-table"
        style="margin-top:4vh"
      ></b-pagination>
  </div>
</template>

<script>
import functionBar from '@/views/BasicSetting/DirectorySetting/MainPage/functionBar.vue'
import { mapActions, mapState } from 'vuex'
import editDirectory from '@/views/BasicSetting/DirectorySetting/ModalContent/editDirectory.vue'

export default {
  components: {
    functionBar,
    modal: () => import('@/views/Modal/index.vue'),
    editDirectory
  },
  data () {
    return {
      EditDirectoryModalOpen: false,
      filter: null,
      perPage: 10,
      currentPage: 1,
      sortBy: null,
      sortDesc: false,
      fields: [
        {
          key: 'company',
          label: '公司名稱',
          sortable: true,
          tdClass: 'align-middle'
        },
        {
          key: 'projectTitle',
          label: '標案組織',
          tdClass: 'align-middle'
        },
        {
          key: 'title',
          label: '計畫職稱',
          sortable: true,
          tdClass: 'align-middle'
        },
        {
          key: 'name',
          label: '人員名稱',
          tdClass: 'align-middle'
        },
        {
          key: 'contactNumber',
          label: '聯絡電話',
          tdClass: 'align-middle'
        },
        {
          key: 'email',
          label: 'Email',
          tdClass: 'align-middle'
        },
        {
          key: 'gmail',
          label: 'Gmail',
          tdClass: 'align-middle'
        },
        {
          key: 'line',
          label: 'LINE ID',
          tdClass: 'align-middle'
        },
        {
          key: 'remark',
          label: '備註',
          tdClass: 'align-middle'
        }
      ],
      selectMode: 'single'
    }
  },
  async mounted () {
    await this.$store.dispatch('project/lookupDirectories')
  },
  methods: {
    ...mapActions('project', ['getDirectories']),
    async open (id) {
      this.EditDirectoryModalOpen = true
      await this.getDirectories(id)
    }
  },
  computed: {
    ...mapState({
      list: (state) => state.project.list
    }),
    rows () {
      return this.list.length
    }
  }
}
</script>

<style>
.thClass {
  font-size: 2vh;
  background-color: #1d325f;
  color: white;
}
.table.b-table > thead > tr > th,
.table.b-table > tfoot > tr > td {
  background-image: none !important;
}
</style>
<style lang="scss" scoped>
/deep/ .align-middle {
  white-space: normal !important;
  overflow-wrap: break-word;
}
.container {
  height: 6.25vh;
  margin-top: 0px;
  margin-left: 5vw;
  padding-top: 1.25vh;
  padding-left: 0.125vw;
  padding-right: 0.125vw;
}
.F_bar {
  z-index: 999;
}
// .text-center {
//   width: 75vw;
//   height: 80vh;
//   padding-left: 7vw;
//   padding-right: 4vw;
//   margin-top: 0.5vh;
// }
.text {
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn1{
  background-color: rgb(75, 102, 255);
  font-size: 2vh;
  color: #ffffff;
  box-shadow: 0.25vw 0.25vw 1.25vw 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: 2vh;
  padding-left: 2vw;
  padding-right: 1vw;
  padding-top: 0.8vh;
  padding-bottom: 0.5vh;
  margin-left: 2vw;
  color: #1d325f;
  box-shadow: 0.25vw 0.25vw 1.25vw rgba(0, 0, 0, 0.1);
}
.btn2:hover {
  color: black;
  background-color: rgb(228, 228, 228);
  transform: scale(1.1);
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 2.5vh;
  margin-top: 2.5vh;
  color: #383838;
}
</style>
