<template>
  <div>
    <cr-popup
      :value="show"
      :style="{ backgroundColor: 'transparent' }"
      :closeable="closeable"
      close-icon="close"
      class="gift"
      @close="onClose"
    >
      <div v-show="show" class="gift-container">
        <cr-image v-if="imgUrl" class="gift-img" :src="imgUrl" width="221px" height="171px" />
        <div class="gift-tip" v-html="txt" />
        <div class="gift-btns">
          <cr-button shape="circle" @click="go">{{ btnTxt }}</cr-button>
          <a href="javascript:;" @click="onClose">知道了</a>
        </div>
      </div>
    </cr-popup>
  </div>
</template>

<script>
const DIALOG_CLOSE_EVENT = 'close';
export default {
  name: 'GiftPopup',
  props: {
    value: null,
    txt: String,
    imgUrl: String,
    closeable: Boolean,
    btnTxt: {
      type: String,
      default: '确定'
    }
  },
  data() {
    return {
      show: false
    };
  },
  watch: {
    value: {
      immediate: true,
      handler(val) {
        this.show = val;
      }
    }
  },
  methods: {
    onClose() {
      this.$emit(DIALOG_CLOSE_EVENT, 1);
    },
    go() {
      this.$emit(DIALOG_CLOSE_EVENT, 2);
    }
  }
};
</script>

<style lang="less" scoped>
.gift {
  overflow: initial;
  @{deep} .cr-popup--close {
    top: -50px;
    right: 0px;
    color: @white;
    font-size: 29px;
    z-index: 103;
  }
  &-container {
    width: 289px;
    height: 320px;
    position: relative;
    background-color: #fff;
    border-radius: 6px;
    padding: 20px 0;
  }
  &-tip {
    font-size: 16px;
    color: #666666;
    text-align: center;
    line-height: 22px;
    min-height: 44px;
  }
  &-img {
    margin: 0 auto 20px;
    display: block;
  }
  &-btns {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .cr-button {
      color: #fff;
      height: 40px;
      width: 210px;
      background-image: linear-gradient(269deg, #ff5d00 12%, #ff1900 86%);
      border-width: 0;
    }
    a {
      color: #ec3333;
      font-size: 14px;
      margin-top: 15px;
    }
  }
}
</style>
