<template>
  <a-modal
    centered
    class="imgShow-modal"
    :footer="null"
    :maskClosable="false"
    title="预览"
    v-model="isShow"
    @cancel="isShow=false"
    :width="500">
    <div class="imgShow-con">
      <img :src="mainContent" alt="图片走丢了" />
    </div>
    <div class="btn-cont">
      <a-button id="imgShow-modal-back" @click="isShow = false">关闭</a-button>
    </div>
  </a-modal>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
export default {
  name: 'ImgShowModal',
  mixins: [commonMixin],
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      mainContent: '' // 主要显示内容
    }
  },
  methods: {
    // 初始化
    pageInit (url) {
      this.mainContent = url
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .imgShow-modal{
    .imgShow-con{
      width:90%;
      margin:0 auto;
      max-height:700px;
      overflow-y:scroll;
      scrollbar-width: none;
      img{
         width:100%;
         height:auto;
         object-fit:cover;
       }
    }

    .btn-cont {
      text-align: center;
      margin: 30px 0 0px;
    }
  }
</style>
