<template>
  <div>
    <div v-if="value.canSelectPrices.length > 1 && position === 'top'" class="chooseModal top">
      <good-price-choose
        :show="showMask"
        :good-info="value"
        :position="position"
        @closeModal="closeModal"
      />
    </div>
    <div v-if="value.activityShowInfo" class="activityPrice" @click="changePrice">
      <div class="discountPrice" :style="{ color: priceColor }">
        ￥{{ value.activityShowInfo.discountPrice }}
      </div>
      <img
        v-if="value.activityShowInfo.icon"
        :src="value.activityShowInfo.icon"
        style="height: 14px"
        :style="{ width: iconWidth }"
      />
      <span v-if="value.canSelectPrices.length > 1" class="iconfont icon-arrow-down icon" />
    </div>
    <div
      v-if="value.canSelectPrices.length > 1 && position === 'bottom'"
      class="chooseModal bottom"
    >
      <good-price-choose
        :show="showMask"
        :good-info="value"
        :position="position"
        @closeModal="closeModal"
      />
    </div>
    <div v-if="!value.activityShowInfo" class="salePrice">￥{{ value.salePrice }}</div>
  </div>
</template>
<script>
import goodPriceChoose from './goodPriceChoose.vue';
export default {
  components: { goodPriceChoose },
  inject: ['cart'],
  props: {
    value: {
      type: Object,
      default: () => {}
    },
    position: {
      type: String,
      default: 'top'
    }
  },
  data() {
    return {
      show: false
    };
  },
  computed: {
    showMask: function() {
      return this.cart.showMask && this.show;
    },
    iconWidth: function() {
      return 14 * +this.value.activityShowInfo.iconRate + 'px';
    },
    priceColor: function() {
      if (this.value.activityShowInfo.priceFontColor) {
        return `#${this.value.activityShowInfo.priceFontColor}`;
      } else {
        if (this.value.activityShowInfo.discountType === 9) {
          return '#4330B7';
        } else {
          return '#ec3333';
        }
      }
    }
  },
  methods: {
    closeModal() {
      this.show = false;
    },
    changePrice(e) {
      if (this.value.canSelectPrices.length <= 1) return;
      this.$emit('getPosition');
      this.show = true;
      e.stopPropagation();
      e.preventDefault();
    }
  }
};
</script>
<style lang="less" scoped>
.activityPrice {
  display: flex;
  align-items: center;
  .discountPrice {
    font-size: 16px;
    font-weight: 500;
  }
  .icon {
    font-size: 12px;
    transform: scale(0.66);
    margin-left: 3px;
  }
}
.salePrice {
  font-weight: bold;
  font-size: 16px;
  color: #ec3333;
}
.chooseModal {
  position: absolute;
  left: 0px;
}
.top {
  bottom: 20px;
  // margin-bottom: 16px;
}
.bottom {
  margin-top: 6px;
}
</style>
