<template>
  <div class="simple-dialog" v-if="value">
    <div class="simple-dialog__container">
      <span
        class="el-icon-close simple-dialog__colse"
        @click="onCloseClick"
      ></span>
      <div class="simple-dialog__title">
        <span class="simple-dialog__title__text">提示</span>
        <slot name="title"></slot>
      </div>
      <div
        class="simple-dialog__content"
        :style="{ textAlign: center && 'center' }"
      >
        <slot></slot>
        <span class="simple-dialog__content__text" v-text="description"></span>
      </div>
      <div class="simple-dialog__footer">
        <slot name="footer" v-if="!confirm || !cancel"></slot>
        <div
          class="simple-dialog__confirm simple-dialog__btn"
          v-if="confirm"
          @click="onConfirm"
        >
          {{ confirmText }}
        </div>
        <div
          class="simple-dialog__cancel simple-dialog__btn"
          v-if="cancel"
          @click="onCancel"
        >
          {{ cancelText }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  model: {
    prop: 'value',
    event: 'change',
  },
  props: {
    confirmText: {
      type: String,
      default: '确定',
    },
    cancelText: {
      type: String,
      default: '取消',
    },
    value: {
      type: Boolean,
      default: false,
    },
    confirm: {
      type: Boolean,
      default: true,
    },
    cancel: {
      type: Boolean,
      default: true,
    },
    description: {
      type: String,
      default: '',
    },
    center: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    onCloseClick() {
      this.$emit('change', false)
    },
    onConfirm() {
      this.$emit('confirm')
    },
    onCancel() {
      this.$emit('cancel')
    },
  },
}
</script>

<style lang="scss" scoped>
@media screen and (min-width: 768px) {
  .simple-dialog {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.39);

    .simple-dialog__container {
      position: relative;
      width: 400px;
      background: #fff;

      .simple-dialog__colse {
        width: 36px;
        height: 36px;
        font-size: 26px;
        position: absolute;
        top: 8px;
        right: 12px;
        text-align: center;
        line-height: 36px;
        color: #c2c2c2;
        cursor: pointer;
      }

      .simple-dialog__title {
        padding: 12px 24px;
        border-bottom: 1px solid #c2c2c2;
        .simple-dialog__title__text {
          font-size: 18px;
          color: #282828;
        }
      }

      .simple-dialog__content {
        padding: 24px 24px;

        .simple-dialog__content__text {
          font-size: 16px;
          color: #282828;
        }
      }

      .simple-dialog__footer {
        padding: 0 24px 24px;

        .simple-dialog__btn {
          width: 100%;
          height: 40px;
          text-align: center;
          line-height: 40px;
          font-size: 16px;
          border-radius: 4px;
          cursor: pointer;
        }

        .simple-dialog__confirm {
          background: #f3920d;
          color: #fff;
        }

        .simple-dialog__cancel {
          color: #666666;
          box-sizing: border-box;
          border: 1px solid #c2c2c2;
          margin-top: 16px;
        }
      }
    }
  }
}

@media screen and (max-width: 768px) {
  .simple-dialog {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.39);

    .simple-dialog__container {
      position: relative;
      width: 76vw;
      min-height: 20vw;
      background: #fff;

      .simple-dialog__colse {
        width: 6.4vw;
        height: 6.4vw;
        font-size: 5vw;
        position: absolute;
        top: 3vw;
        right: 3vw;
        text-align: center;
        line-height: 6.4vw;
        color: #c2c2c2;
      }

      .simple-dialog__title {
        padding: 3vw 4.8vw;
        border-bottom: 1px solid #c2c2c2;
        .simple-dialog__title__text {
          font-size: 4.2vw;
          color: #282828;
        }
      }

      .simple-dialog__content {
        padding: 3vw 4.8vw;

        .simple-dialog__content__text {
          font-size: 3.6vw;
          color: #282828;
        }
      }

      .simple-dialog__footer {
        padding: 0 24px 24px;

        .simple-dialog__btn {
          width: 100%;
          height: 8.8vw;
          text-align: center;
          line-height: 8.8vw;
          font-size: 3.6vw;
          border-radius: 0.4vw;
        }

        .simple-dialog__confirm {
          background: #f3920d;
          color: #fff;
        }

        .simple-dialog__cancel {
          color: #666666;
          box-sizing: border-box;
          border: 1px solid #c2c2c2;
          margin-top: 2.8vw;
        }
      }
    }
  }
}
</style>
