<template>
  <div class="detail-container">
    <!-- <div class="top-container">
      <el-radio-group v-model="currentType" size="medium" @change="changeType()">
        <el-radio-button v-for="(item, index) in typeList" :key="index" :label="item.value">{{item.label}}</el-radio-button>
      </el-radio-group>
    </div> -->

    <div id="printMe">
      
      <PrintCommon :detailData="detailData" :company="company" v-if="currentType === 0" />
      <PrintFoshan :detailData="detailData" :company="company" v-if="currentType === 1" />
      <PrintGuangzhou :detailData="detailData" :company="company" v-if="currentType === 2" />
      <PrintShaoguan :detailData="detailData" :company="company" v-if="currentType === 3" />

    </div>
    
    <div class="page-footer">
      <div class="footer">
        <el-button  type="primary" icon="el-icon-printer" v-print="printObj">打 印</el-button>
        <el-button @click="goBack">关 闭</el-button>
      </div>
    </div>

  </div>
</template>

<script>
import print from 'vue-print-nb'
import { getDeliverDetail, getEnginDetail } from "@/api/supply/deliver";
import { addPrint } from "@/api/supply/pickup";
import { getCompanyList } from "@/api/user";
import PrintCommon from "@/components/Common/print-common";
import PrintFoshan from "@/components/Common/print-foshan";
import PrintGuangzhou from "@/components/Common/print-guangzhou";
import PrintShaoguan from "@/components/Common/print-shaoguan";

export default {
  name: 'ReturnDetail',
  componentName: 'ReturnDetail',
  props: ['printId', 'printType'],
  components: {
    PrintFoshan,
    PrintGuangzhou,
    PrintShaoguan,
    PrintCommon,
  },
  directives: {
    print
  },
  data() {
    return {
      currentType: 0,
      typeList: [
        { label: '通用', value: 0 },
        { label: '佛山', value: 1 },
        { label: '广州', value: 2 },
        { label: '韶关', value: 3 },
      ],
      printObj: {
        id: 'printMe',
        closeCallback: () => {
          this.addPrint();
        }
      },
      detailData: {},
      company: '',
    }
  },

  created() {
    this.getDetail();
    this.getCompanyList();
  },

  methods: {
    // 返回列表
    goBack() {
      this.$emit('backDetail');
    },

    changeType() {

    },

    // 获取详情
    getDetail() {
      // if(this.printType === 1) {
        getDeliverDetail({id: this.printId}).then(res => {
          this.detailData = res.data;
        })
      // }else {
        // getEnginDetail({id: this.printId}).then(res => {
          // this.detailData = res.data;
        // })
      // }
    },

    getCompanyList() {
      getCompanyList().then(res => {
        this.company = res.data ? res.data[0].companyName : '';
      })
    },

    // 添加次数
    addPrint() {
      addPrint({ids: this.printId}).then(res => {
        // this.$successMsg('提交成功');
        this.$parent.getList();
      })
    }
  }
}
</script>

<style scoped lang="scss">
  .detail-container {
    width: 100%;
    height: 100%;
  }
  .top-container {
    margin-top: 20px;
  }
</style>