<template>
  <div class="dec-discount-s-good" :class="className">
    <div class="image">
      <img
        :style="{ height: imgH }"
        :src="decImgDomain(good.productImg || '')"
        alt=""
      />
    </div>
    <div class="flex time" v-if="imgArg != 'small' && show.time">
      <span class="start">{{ inLine }}</span>
      <div class="limit">
        <template v-if="inLine2">
          <span>{{ inLine2 }}</span
          ><br />
        </template>
        <span>{{ endTime }}</span>
      </div>
    </div>
    <div class="info">
      <div class="title dec-truncate2" v-if="show.title">
        {{ good.productName }}
      </div>
      <div class="desc dec-truncate" v-if="show.desc">
        {{ good.introduction || good.productName }}
      </div>
      <!-- 价格 购买｜兼容点击宽高问题 -->
      <div
        class="price-wrap dec-row-flex a-bottom"
        v-if="show.price || show.origin"
      >
        <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: {
    good: {
      type: Object,
      default: () => {
        return {};
      },
    },
    show: {
      type: Object,
      default: () => {
        return {};
      },
    },
    imgArg: {
      type: String,
      default: "",
    },
    imgH: {
      type: String,
      default: "auto",
    },
    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.imgArg == "big") {
        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}`;
      } else {
        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() {
      let name = "";
      if (this.imgArg == "big") {
        name = ["已结束", "未开始"].includes(this.state) ? "" : "拼团抢购";
      } else {
        name = ["已结束", "未开始"].includes(this.state) ? "" : "距结束";
      }
      return name;
    },
    inLine2() {
      let name = "";
      if (this.imgArg == "big") {
        name = ["已结束", "未开始"].includes(this.state)
          ? "活动状态"
          : "距结束仅剩";
      }
      return name;
    },
    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>
