<template>
  <div v-if="show" class="snapdragon">
    <basicbackground @closeClick="closeClick">
      <img class="icon" :src="iconSrc" alt=""/>
      <div>
        <span>{{ prizeValue }}{{ prizeName }}</span>
        <span class="couponType">{{ couponType }}</span>
      </div>
      <button v-if="prizeType ===3" v-lz-click="'23'" @click="buttonClick(prizeResultData.datas)">
        填写邮寄地址
      </button>
      <button v-else v-lz-click="'4'" @click="buttonClick(prizeResultData.datas)">进店逛逛</button>
    </basicbackground>
  </div>
</template>
<script>
import basicbackground from './basicbackground.vue';
import {AddressPopComService} from '../../../util/comCreate.js';
import store from '../../../store/store';
import {goToShopPage} from '../../../util/tools.js';

export default {
  name: 'acquirecoupon',
  components: {basicbackground},
  data() {
    return {
      icons: {
        // 京豆
        '1': '//img10.360buyimg.com/imgzone/jfs/t1/180602/34/3961/56630/609dd693E52fa9522/5ecfb13e7edcb96c.png',
        // 优惠券，折扣
        '2': '//img10.360buyimg.com/imgzone/jfs/t1/183386/30/3981/54253/609dd693Ebf0084b3/2046696efcb9954a.png',
        // 实物
        '3': '',
        // 其他(暂时按积分处理)
        '4': '//img10.360buyimg.com/imgzone/jfs/t1/188025/6/3033/59458/609dd693Ef325c08d/af5b57ed06140ef1.png',
      },
      keyData: {},
      datas: {},
      prizeValue: '',
      prizeType: '',
      prizeName: '',
      couponType: '',
      iconSrc: ''
    };
  },
  props: [],
  created() {
    this.datas = this.prizeResultData.datas;
    this.keyData = this.prizeResultData.keyData;
    this.prizeType = Number(this.datas[this.keyData.prizeType])
    this.prizeName = this.datas[this.keyData.prizeName];
    this.iconSrc = this.datas[this.keyData.prizeUrl] || this.icons[this.prizeType];
    switch (this.prizeType) {
      case 1:
        // this.prizeValue = this.datas.beanNum;
        break;
      case 2:
        // this.prizeValue = this.datas[this.keyData.priceInfo];
        const discountType = this.initDatas[this.keyData.discountType];
        if (discountType === 1) {
          const couponType = this.initDatas[this.keyData.couponType];
          if (couponType === 0) {
            this.couponType = '京券';
          } else if (couponType === 1) {
            this.couponType = '东券';
          }
        } else if (discountType === 2) {
          this.prizeName = '折';
        }
        break;
      case 3:
        break;
      case 4:
        // this.prizeValue = this.datas.beanNum;
        break;
    }
    // console.log(this.prizeResultData, this.initDatas);
  },
  mounted() {
  },
  methods: {
    buttonClick(prizeResultData) {
      document.querySelector('body').removeAttribute('style')
      if (this.prizeType === 3) {
        //填写地址
        sessionStorage.setItem('addressId', this.initDatas.addressId);
        sessionStorage.setItem('prizeGrantId', this.initDatas.id);
        var datas = {
          isEditAddress: true,
          isAlLookAddress: false
        }
        AddressPopComService.create(datas, submit => {
          AddressPopComService.close();
        });
        this.submit();
      } else {
        //查看
        let shopId = store.state.shopId;
        goToShopPage(shopId);
        this.submit();
      }
    },
    closeClick() {
      document.querySelector('body').removeAttribute('style')
      this.submit();
    },
  },
};
</script>
<style lang="scss" scoped>

.snapdragon {
  text-align: center;

  .icon {
    width: 2rem;
    //height: 1.84rem;
    //margin: 0.47rem;
  }

  .couponType {
    display: none;
    font-size: small;
  }

  button {
    display: block;
    width: 100%;
    height: 0.94rem;
    background-color: #495975;
    border-radius: 0.1rem;
    font-size: 0.46rem;
    color: #ffffff;
    margin-top: 0.63rem;
  }

}
</style>
