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

<script>
export default {
  inject: ["decImgDomain", "decAxios"],
  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: {
    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;
    },
  },
  methods: {
    go() {
      this.decAxios.decEventHandler(
        {
          moudle: "goodDiscount",
          type: "detail",
          desc: "跳折扣商品详情页",
        },
        this.good,
        null
      );
    },
    buy() {
      this.decAxios.decEventHandler(
        {
          moudle: "goodDiscount",
          type: "buy",
          desc: "购买折扣商品",
        },
        this.good,
        null
      );
    },
  },
};
</script>
