<template>
  <div>
    <a-button
      key="1"
      type="default"
      v-if="$hasPermissions('B_transferReturnPrint')"
      id="editGrap-db-print-btn"
      :disabled="disabled"
      @click="handlePrint('preview')">打印预览</a-button>
    <a-button
      key="2"
      type="primary"
      class="button-info"
      v-if="$hasPermissions('B_transferReturnPrint')"
      id="editGrap-dbfl-print-btn"
      :disabled="disabled"
      @click="handlePrint('print')">快捷打印</a-button>
    <a-divider type="vertical" />
    <a-button
      key="3"
      type="primary"
      class="button-warning"
      v-if="$hasPermissions('B_transferReturnExport')"
      id="editGrap-export-btn"
      :disabled="disabled"
      @click="handleExcel">导出Excel</a-button>
    <!-- 打印导出 -->
    <print-modal :openModal="openModal" :itemData="basicInfoData" :nowType="nowType" @ok="handleOk" @close="openModal=false" />
    <!-- 打印 -->
    <div id="print"></div>
  </div>
</template>

<script>
import { printFun, exportExcel } from '@/libs/JGPrint.js'
import printModal from './printModal.vue'
import { allocateReturnExcel, allocateReturnPrint } from '@/api/allocateReturn'
export default {
  components: { printModal },
  props: {
    params: {
      type: Object,
      default: function () {
        return {}
      }
    },
    basicInfoData: {
      type: Object,
      default: function () {
        return {}
      }
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      openModal: false,
      nowType: null
    }
  },
  methods: {
    // 打印预览/快捷打印
    handlePrint (type) {
      this.nowType = type
      this.openModal = true
    },
    handleOk (obj) {
      const _this = this
      const params = {
        allocateReturnSn: obj.allocateReturnSn || '',
        printType: obj.printType
      }
      _this.$emit('loading')
      printFun(allocateReturnPrint, params, obj.isPreview, '调拨退货单', () => { _this.$emit('unloading') })
    },
    // 导出
    handleExcel () {
      const _this = this
      _this.$emit('loading')
      exportExcel(allocateReturnExcel, { allocateReturnSn: this.params.allocateReturnSn || '' }, '调拨退货单明细', function () {
        _this.$emit('unloading')
      })
    }
  }
}
</script>

<style>
</style>
