<template>
  <view v-if="value" class="common-dialog">
    <view class="common-dialog__content">
      <slot name="header">
        <view class="common-dialog__header">{{ title }}</view>
      </slot>

      <view class="common-dialog__body">
        <slot></slot>
      </view>

      <view class="common-dialog__footer common-dialog__footer--with-shadow">
        <slot name="footer"> </slot>
      </view>

      <view class="common-dialog__close">
        <text
          class="common-dialog__close-icon iconfont icon-shibai1"
          @click="handleClose"
        ></text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: "CommonDialog",
  model: {
    prop: "value",
    event: "input",
  },
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      default: "",
    },
  },
  methods: {
    handleClose() {
      this.$emit("input", false);
      this.$emit("close");
    },
  },
};
</script>
<style scoped lang="less">
/* 块级命名规范 */
.common-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 99999;

  /* 元素命名规范（双下划线连接） */
  &__content {
    padding: 25.6px 19.2px;
    width: 420px;
    box-sizing: border-box;
    background-image: linear-gradient(
      -6deg,
      #f9ffe7 0%,
      #ffffff 12%,
      #fcfeff 73%,
      #ccf1ff 100%
    );
    border: 0.4px solid rgba(224, 224, 224, 1);
    border-radius: 12px;
    position: relative;
  }

  &__header {
    font-size: 18px;
    color: #000000;
    line-height: 26px;
    font-weight: 500;
    margin-bottom: 12px;
  }

  &__body {
    font-size: 16px;
    color: #000000;
    text-align: center;
    line-height: 24px;
    font-weight: 400;
    margin-bottom: 24px;
  }

  &__close {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);

    &-icon {
      color: #fff;
      font-size: 24px;
    }
  }
}
</style>
