<template>
  <div>
    <!-- 新增現況 -->
    <div v-show="$route.name === 'ProjectStatusList'" class="shadow" >
      <b-button
      class="btn1"
      @click="addSituation"
      :disabled = "this.projectStatus.permission === 1">
        <b-icon-file-earmark-plus />新增現況
      </b-button>
    </div>
    <!-- 新增現況Modal -->
    <modal
      :is-open="AddSituationModalOpen"
      title="新增現況"
      @closeEvent="AddSituationModalOpen = false"

    >
      <addSituation @closeEvent="AddSituationModalOpen = false" />
    </modal>
  </div>
</template>
<script>
import addSituation from '@/views/BasicSetting/ProjectStatus/ModalContent/addSituation.vue'
import { mapActions, mapState } from 'vuex'
export default {
  data () {
    return {
      AddSituationModalOpen: false,
      projectStatus: {}
    }
  },
  mounted () {
    this.usePermission()
  },
  methods: {
    ...mapActions('tenders', ['initProjectStatus']),
    async addSituation () {
      await this.initProjectStatus()
      this.AddSituationModalOpen = true
    },
    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.projectStatus = a
            }
          }
        }
      })
    }
  },
  components: {
    modal: () => import('@/views/Modal/index.vue'),
    addSituation
  },
  computed: {
    ...mapState({
      currentUser: (state) => state.user.current
    })
  }
}
</script>
<style lang="scss" scoped>
.shadow {
  background-color: #ffff;
  height: 60px;
  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;
}
.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>
