<template>
  <div>
    <el-dialog
      title="材料预览"
      destroy-on-close
      :visible.sync="Visible"
      width="50%"
      top="2vh"
    >
      <div class="main flex flexc aic">
        <div class="header tac mb20">
          <div class="materals-name mb10">{{ materialsInfo.materialName }}</div>
          <p class="abbreviation">
            材料全称：{{ materialsInfo.materiaFullName }}
          </p>
        </div>
        <div class="preview-box">
          <img class="sample-sheet-img" :src="materialsPreview" />
        </div>
      </div>
      <div slot="footer" class="tac">
        <el-button
          type="primary"
          :loading="loading"
          @click="handlePrint(materialsInfo)"
          >下 载</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    materialsInfo: {
      type: Object,
      required: true,
      default: () => {
        return {};
      },
    },
    previewVisible: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  computed: {
    Visible: {
      get() {
        return this.previewVisible;
      },
      set(val) {
        this.$emit("update:previewVisible", val);
      },
    },
    materialsPreview() {
      return this.materialsInfo.preViewPath;
    },
  },
  data() {
    return {
      loading: false,
    };
  },
  methods: {
    handlePrint(info) {
      const a = document.createElement("a");
      a.href = info.samplePath;
      a.download = info.sampleName;
      a.click();
    },
  },
};
</script>

<style lang="less" scoped>
:deep(.el-dialog__body) {
  height: 78vh;
  overflow-y: auto;
}
.main {
  width: 100%;
  .materals-name {
    font-size: 18px;
  }
  .abbreviation {
    font-size: 14px;
    color: #999;
  }

  .preview-box {
    width: 80%;
    // box-shadow: 2px 2px 8px 8px #ccc;
    .sample-sheet-img {
      width: 100%;
    }
  }
}
</style>
