<template>
  <div class="past-source" :class="CustomClass">
    <i v-if="closable" class="el-icon-close" @click="close"></i>
    <el-badge :value="num" :max="99" :hidden="!num" class="item">
      <i class="iconfont iconPDF"></i>
    </el-badge>
    <!-- <p>病例资料整理</p> -->
    <!-- <p>{{getNameText(item.meetingFileName)}}</p> -->
    <p>{{ item.meetingFileName }}</p>
    <div class="btn-option"><span @click="preview(item)">预览</span><span @click="downLoad(item)">导出</span><span @click="copyUrl(item)">复制链接</span></div>
  </div>
</template>
<script>
import {handleMdtShare} from '@/request/mdt.js'
import { copyContent,newDownLoad,getNameText } from 'aegle-sp-components/src/utils/index.js'
export default {
  props: {
    item: Object,
    num: {//num是该文件的评论数
      type: [String, Number],
      default: 0
    },
    closable: {
      type: Boolean,
      default: true
    },
    CustomClass: {
      type: String,
      default: ''
    },
    env: {
      type: String,
      default: 'test'
    }
  },
  inject: ['topObj'],
  methods: {
    getNameText(d) {
      return getNameText(d)
    },
    close () {
      const h = this.$createElement;
      this.$msgbox({
        title: "提示",
        message: h(
          "div",
          {
            style: {
              lineHeight: "26px",
              fontFamily: "font-family: PingFangSC, PingFangSC-Regular;",
            },
          },
          [
            h("div", { style: { fontSize: "14px" } }, "是否确认删除该文件？"),
          ]
        ),
        customClass: 'self-com-dialog',
        showCancelButton: true,
        confirmButtonText: "是",
        cancelButtonText: "否",
        closeOnClickModal: false,
        closeOnPressEscape: false,
        showClose: false,
        beforeClose: (action, instance, done) => {
          if (action === "confirm") {
            this.$emit('close', this.item)
          }
          done();
        },
      }).then((res) => {
        console.log(res);
      });
    },
    preview(d) {
      this.$emit('preview', d)
    },
    //导出
    async downLoad(d) {
      newDownLoad(d.pdfFileUrl)
    },
    //复制链接
    copyUrl(item) {
      handleMdtShare({id:item.id}).then(res => {
        if(res.code == 0){
          const data = {
            docId: this.topObj.doctorInfo.id,
            id: item.id
          }
          copyContent(data,()=>{
            this.$message.success('复制成功！')
          },this.env)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.past-source {
  margin-top: 2px;
  position: relative;
  width: 175px;
  height: 107px;
  cursor: default;
  background: #f6faff;
  border: 1px solid rgba(62, 152, 255, 0.4);
  border-radius: 4px;
  margin-right: 16px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px 0 0;
  p {
    box-sizing: border-box;
    color: #262626;
    line-height: 26px;
    font-size: 13px;
    margin: 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    width: 100%;
    padding: 0 5px;
    text-align: center;
    font-family: PingFangSC, PingFangSC-Regular;
  }
  i {
    font-size: 32px;
    color: #1890FF;
  }
  > i {
    width: 15px;
    height: 15px;
    line-height: 14px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    background: #1890ff;
    position: absolute;
    top: -3px;
    right: -3px;
    font-size: 12px;
    border-radius: 50%;
    border: 1px solid rgba(62,152,255,0.40);
    color: #E6E7EC;
  }
  .btn-option {
    display: flex;
    span {
      color: #1890ff;
      text-decoration: underline;
      font-size: 13px;
      cursor: pointer;
      margin-right: 10px;
      &:last-child {
        margin-right: 0;
      }
    }
  }
}
</style>
