<template>
  <div class="dialog-xx-success">
    <el-dialog
      :visible.sync="modelVisible"
      :lock-scroll="false"
      width="600px">
      <div class="flex column center stretch">
        <div class="flex center img-wrap" v-if="imgShow">
          <img
            src="@/assets/img/msg_right.png"
            v-if="imgType" />
          <img
            src="@/assets/img/msg_error.png"
            v-else />
        </div>
        <div class="content-area">
          <div class="content" v-if="content">{{ content }}</div>
          <div
            v-if="desc && desc.length"
            class="desc">
            {{ desc }}
          </div>
        </div>
        <div class="flex center">
          <div
            class="btn-ok flex center"
            @click="notifyParent">
            OK
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    imgShow: {
      type: Boolean,
      default: true,
    },
    imgType: {
      type: Boolean,
      default: true,
    },
    content: {
      type: String,
      default: '',
    },
    desc: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      modelVisible: false,
    }
  },
  watch: {
    modelVisible(value) {
      this.$emit('update:visible', value)

      if (value) {
        document.addEventListener('keydown', this.close)
      } else {
        document.removeEventListener('keydown', this.close)
      }
    },
    visible() {
      this.modelVisible = this.visible
    },
  },
  methods: {
    notifyParent(){
      this.modelVisible = false
      this.$emit('notify-parent');
    },
    close(e) {
      if (e.keyCode === 13) {
        this.modelVisible = false
      }
    },
  },
}
</script>

<style lang="scss">
.dialog-xx-success {
  .el-dialog__header {
    position: relative;
    padding: 0px 20px;
    .el-dialog__headerbtn {
      position: absolute;
      top: -41px;
      right: 0;
      .el-icon-close:before {
        content: '\e78d';
        color: #fff;
        font-size: 22px;
      }
    }
  }
  .el-dialog__body {
    box-sizing: border-box;
    padding: 20px
  }
  .content-area {
    font-weight: bold;
    font-size: 26px;
    color: #00213b;
    text-align: center;
    margin-bottom: 38px;
  }
  .desc {
    margin-top: 31px;
    font-size: 16px;
    color: #666;
    line-height: 24px;
  }
  .img-wrap {
    margin-bottom: 20px;
  }
  img {
    width: 58px;
  }
  .btn-ok {
    cursor: pointer;
    color: #fff;
    font-size: 20px;
    font-family: Proxima Nova;
    font-weight: bold;
    width: 120px;
    height: 54px;
    background: #00213b;
    border-radius: 6px;
  }
}
</style>
