<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">
      
      <PrintFoshan :detailData="detailData" v-if="currentType === 1" />
      <PrintGuangzhou :detailData="detailData" v-if="currentType === 2" />

    </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 { getDetail, addPrint } from "@/api/supply/pickup";
import PrintFoshan from "@/components/Common/print-foshan";
import PrintGuangzhou from "@/components/Common/print-guangzhou";

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

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

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

    changeType() {

    },

    // 获取详情
    getDetail() {
      getDetail({id: this.listItem[0].id}).then(res => {
        this.detailData = res.data;
      })
    },

    // 添加次数
    addPrint() {
      let ids = this.listItem.map(item => {
        return item.invoiceOrderId;
      });
      addPrint({ids: ids.join(',')}).then(res => {
        // this.$successMsg('提交成功');
        this.$parent.getList();
      })
    }
  }
}
</script>

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