<template>
  <div>
    <!-- 審查文件 -->
    <div v-show="$route.name === 'FileReviewList'" class="shadow">
      <b-button
        @click="fileIssue()"
        class="btn1"
        :disabled="fileManagement.permission === 1"
      >
        <b-icon-file-earmark-plus />新增審查文件
      </b-button>
      <!-- <b-button
        class="btn"
        @click="ImportCSVModalOpen = true"
        >
        <b-icon-box-arrow-in-down />文件匯入
      </b-button> -->
      <!-- <b-button class="btn" @click="FileExportListModalOpen = true">
        <b-icon-list-check /> 匯出列表
      </b-button> -->
    </div>
    <!-- 提送文件 -->
    <div v-show="$route.name === 'FileSubmitList'" class="shadow">
      <b-button
        @click="fileSubmit()"
        class="btn1"
        :disabled="fileManagement.permission === 1"
      >
        <b-icon-file-earmark-plus />新增提送文件
      </b-button>
      <!-- <b-button
        class="btn"
        @click="ImportCSVModalOpen = true"
        >
        <b-icon-box-arrow-in-down />文件匯入
      </b-button> -->
      <!-- <b-button class="btn" @click="FileExportListModalOpen = true">
        <b-icon-list-check /> 匯出列表
        </b-button> -->
    </div>
    <!-- 匯出列表 Modal -->
    <modal
      :is-open="FileExportListModalOpen"
      title="匯出列表"
      @closeEvent="FileExportListModalOpen = false"
    >
      <fileExportList @closeEvent="FileExportListModalOpen = false" />
    </modal>
    <!-- 文件匯入 Modal -->
    <modal
      :is-open="ImportCSVModalOpen"
      title="文件匯入"
      @closeEvent="ImportCSVModalOpen = false"
    >
    <importCSV @closeEvent="ImportCSVModalOpen = false" />
    </modal>
  </div>
</template>

<script>
import fileExportList from '@/views/FileManagement/ModalContent/fileExportList.vue'
import importCSV from '@/views/FileManagement/ModalContent/importCSV.vue'
import { mapState, mapMutations } from 'vuex'

export default {
  components: {
    modal: () => import('@/views/Modal/index.vue'), // 不用寫在import只需寫在這邊
    fileExportList,
    importCSV
  },
  data () {
    return {
      FileExportListModalOpen: false,
      ImportCSVModalOpen: false,
      initialDoc: [],
      fileManagement: {}
    }
  },
  mounted () {
    this.usePermission()
  },
  methods: {
    ...mapMutations(
      'newDocument', ['setNewDoc', 'resetNewDoc']
    ),
    fileIssue () {
      this.resetNewDoc()
      this.setNewDoc(this.initialDoc)
      this.$router.push({ name: 'FileReviewCreate' })
    },
    fileSubmit () {
      this.resetNewDoc()
      this.setNewDoc(this.initialDoc)
      this.$router.push({ name: 'FileSubmitCreate' })
    },
    usePermission () { // 確認權限
      Object.values(this.currentUser.tenderPermissions).forEach(obj => {
        if (obj.tenderId === this.currentUser.defaultTender) {
          let permission = obj.permission
            .filter(name => name.title === '工作協同')
            .map(val => { return val.functionItem })
          for (const element of permission) {
            for (const a of element) {
              if (a.name === '文件提審') this.fileManagement = a
            }
          }
        }
      })
    }
  },
  computed: {
    ...mapState({
      currentUser: (state) => state.user.current
    })
  }
}
</script>

<style lang="scss" scoped>
.shadow {
  background-color: #ffff;
  height: 65px;
  width: 100%;
  box-shadow: 2px 2px 20px rgba(0, 0, 0, 40);
  /* border-bottom-width:3px;
    border-bottom-color:#1D325F;
    border-bottom-style:solid */
  position: fixed;
  top: 55px;
  z-index: 500;
}

.btn {
  background-color: white;
  font-size: 16px;
  margin-top: 15px;
  margin-left: 15px;
  padding-left: 7px;
  padding-right: 7px;
  padding-top: 5px;
  padding-bottom: 5px;
  color: #383838;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
  border: none;
  hover {
    color: black;
    background-color: rgb(228, 228, 228);
  }
}
.btn1 {
  background-color: rgb(75, 102, 255);
  font-size: 16px;
  margin-top: 15px;
  margin-left: 15px;
  padding-left: 7px;
  padding-right: 7px;
  padding-top: 5px;
  padding-bottom: 5px;
  color: #ffffff;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
  border: none;
  hover {
    color: rgb(255, 255, 255);
    background-color: rgb(49, 68, 175);
  }
}
.btn1.btn-secondary[disabled] {
  background-color: rgb(224, 224, 224);
  color: rgb(150, 150, 150);
}
</style>
