<template>
  <div>
    <b-row>
      <b-form-group
        label="選擇檔案類型 :"
        label-for="input-default"
        style="width: 200px"
      >
        <b-form-select
          :options="
            $store.getters['getEnumWord'](
              'officialDocument_typeEnum',
              officialDoc.document_type
            )
          "
          v-model="officialDoc.document_type"
        >
        </b-form-select>
      </b-form-group>
    </b-row>
    <div class="btns100">
      <b-button class="btn" style="margin-right: 10px" @click="printOut">
        輸出
      </b-button>
      <b-button class="btn" style="margin-right: 10px" @click="closeModal">
        取消
      </b-button>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'
export default {
  data () {
    return {}
  },
  methods: {
    ...mapActions('officialDocument', [
      'addRecord',
      'patch',
      'download',
      'printBatch'
    ]),
    async printOut () {
      if (this.officialDoc.document_type === '') {
        alert('請選擇輸出類型')
      } else {
        await this.patch()
        await this.download()
        await this.printBatch()
        this.addRecord({ staffName: this.currentUser.name, todo: '書函輸出' })
        this.$emit('closeEvent')
      }
    },
    closeModal () {
      this.$emit('closeEvent')
    }
  },
  computed: {
    ...mapState({
      officialDoc: state => state.officialDocument.officialDoc,
      currentUser: state => state.user.current,
      enums: state => state.enums
    })
  }
}
</script>

<style>
</style>
