<template>
  <div class="dec-discount-l-good" :class="className">
    <!-- 图片 角标 -->
    <div class="good-image" :style="{ width: imgW, height: imgW }">
      <img :src="decImgDomain(good.productImg || '')" />
      <div class="time flex" v-if="show.time">
        <span class="start">{{ inLine }}</span>
        <span>{{ endTime }}</span>
      </div>
    </div>
    <div class="info">
      <div class="intro">
        <div class="title dec-truncate2 mb" v-if="show.title">
          {{ good.productName }}
        </div>
        <div class="desc dec-truncate mb" v-if="show.desc">
          {{ good.introduction || good.productName }}
        </div>
      </div>
      <div class="price-wrap dec-row-flex a-bottom" v-if="show.price">
        <span class="dot" v-if="show.price">¥</span>
        <span class="sale" v-if="show.price">{{ good.grouponPrice || 0 }}</span>
        <span class="origin" v-if="opriceShow">￥{{ good.smarketPrice }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  inject: ["decImgDomain"],
  props: {
    show: {
      type: Object,
      default: () => {
        return {};
      },
    },
    good: {
      type: Object,
      default: () => {
        return {};
      },
    },
    imgArg: {
      type: String,
      default: "",
    },
    imgW: {
      type: String,
      default: "36%",
    },
    time: {
      type: Object,
      default: () => {
        return {};
      },
    },
    state: {
      type: String,
      default: "",
    },
  },
  computed: {
    _hide() {
      return this.show._hide || [];
    },
    endTime() {
      if (!this.time.hour) {
        return "活动" + this.state;
      }
      if (this.time.day) {
        return `${this.time.day}天:${this.time.hour}:${this.time.minutes}:${this.time.seconds}`;
      }
      return `${this.time.hour}:${this.time.minutes}:${this.time.seconds}`;
    },
    inLine() {
      return ["已结束", "未开始"].includes(this.state) ? "" : "距结束";
    },
    remain() {
      return parseInt(this.good.activityStock - this.good.saleCount);
    },
    className() {
      let str = [];
      if (this.imgArg) str.push(this.imgArg);
      if (this.show.border) str.push(this.show.border);
      if (this.show.radius) str.push("radius");
      return str;
    },
    opriceShow() {
      if (this.show.origin && this.good.smarketPrice) {
        return this.good.smarketPrice > this.good.activityPrice;
      }
      return false;
    },
  },
};
</script>
