/*Toast自定义弹框*/
<template>
  <div>
    <transition name="marsk-fade">
      <div v-show="toastConfig.isShow" class="marsk" />
    </transition>
    <transition name="slide-fade">
      <div
        v-show="toastConfig.isShow"
        :class="['action-toast', toastConfig.center ? 'center' : '']"
      >
        <p>{{ toastConfig.message }}</p>
        <div class="button-group">
          <el-button
            type="danger"
            size="mini"
            round
            @click.native.prevent="sure"
            >确定</el-button
          >
          <el-button
            v-if="toastConfig.showCancel"
            type="info"
            size="mini"
            round
            @click.native.prevent="cancel"
            >取消</el-button
          >
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'Toast',
  props: {
    toastConfig: {
      isShow: {
        type: Boolean,
        default: () => false,
      },
      showCancel: {
        type: Boolean,
        default: () => false,
      },
      center: {
        type: Boolean,
        default: () => false,
      },
      message: {
        type: String,
        default: () => '',
      },
    },
  },
  methods: {
    // 点击确定
    sure() {
      this.$emit('putToast', true)
    },
    // 点击取消
    cancel() {
      this.$emit('putToast', false)
    },
  },
}
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';
@import '@/styles/mixin.scss';

.marsk-fade-enter-active,
.marsk-fade-leave-active {
  transition: all 0.5s;
}
.marsk-fade-enter,
.marsk-fade-leave-to {
  opacity: 0;
}
.marsk {
  @include position(fixed, 0, 0, 0, 0, 1000);
  background: rgba(4, 112, 204, 0.05);
}

.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateY(7.48rem);
  opacity: 0;
}
.action-toast {
  @include position(absolute, 50%, auto, 50%, auto, 1001);
  @include w_h(290px);
  transform: translate(-50%, -50%);
  padding: 30px 40px;
  font-size: 12px;
  line-height: 22px;
  color: $color_3;
  background: $color_f;
  text-align: justify;
  word-break: break-all;
  box-shadow: 0 0 7px 7px rgba(0, 0, 0, 0.04);
  .button-group {
    margin-top: 20px;
    @include flex(space-around);
  }
}
.center {
  text-align: center;
}
</style>

<style lang="scss">
@import '@/styles/variables.scss';
@import '@/styles/mixin.scss';

.action-toast .el-button--mini,
.action-toast .el-button--mini.is-round {
  padding: 7px 20px;
}
.action-toast .el-button--info {
  color: $color_9;
  background-color: $color_f5;
  border-color: $color_f5;
}
.action-toast .el-button--info:focus,
.action-toast .el-button--info:hover {
  background: $color_e;
  border-color: $color_e;
}
</style>
