<template>
  <van-dialog
    v-model="showPopup"
    class="m-confirm-dialog"
    closeOnClickOverlay
    :showConfirmButton="false"
  >
    <div class="m-confirm">
      <div class="title">{{ title }}</div>
      <div class="content">{{ content }}</div>
      <div class="btn-con flex-default">
        <van-button
          color="#AEAEAE"
          plain
          round
          @click="handleCancel"
          v-if="!hideCancel"
        >
          {{ cancelTxt }}
        </van-button>
        <van-button type="primary" round @click="handleConfirm">
          {{ confirmTxt }}
        </van-button>
      </div>
    </div>
  </van-dialog>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: "",
    },
    content: {
      type: String,
      default: "",
    },
    cancelTxt: {
      type: String,
      default: "取 消",
    },
    confirmTxt: {
      type: String,
      default: "确 定",
    },
    hideCancel: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      showPopup: false,
    };
  },
  methods: {
    handleCancel() {
      this.showPopup = false;
      this.cancel && this.cancel();
    },
    handleConfirm() {
      this.showPopup = false;
      this.confirm && this.confirm();
    },
  },
  mounted() {
    this.showPopup = true;
  },
};
</script>

<style lang="less">
.m-confirm-dialog {
  width: 290px;
  border-radius: 10px;
}
.m-confirm {
  padding: 30px;
  > .title,
  .content {
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 10px;
  }
  > .btn-con {
    justify-content: center;
    margin-top: 20px;
    button {
      height: 28px;
      width: 100px;
      margin-left: 15px;
      font-size: 13px;
      &:first-of-type {
        margin-left: 0;
      }
    }
  }
}
</style>
