<template>
  <view class="detail" @click="$emit('toDetail', itemInfo)" :style="isPadding">
    <view class="content">
      <image :src="itemInfo.goods.image" mode="" class="content-img"></image>
      <view class="mask" v-if="itemInfo.goods.status == 'down'">
        <view class="text-1"> 已下架 </view>
      </view>
      <view class="content-right">
        <view class="goods-title">
          <view class="_label" v-if="itemInfo.goods.source == 2"> 供应商 </view>
          <view
            class="_label"
            style="background-color: #f83224"
            v-if="itemInfo.goods.source == 1"
          >
            自营
          </view>
          <view class="_label" v-if="itemInfo.goods.source == 0"> 团长 </view>
          <view class="title" v-if="productAndCommodity == 'product'">
            {{ itemInfo.name_cn }}
          </view>
          <view class="title" v-else>{{ itemInfo.goods.name_cn }}</view>
        </view>
        <view class="inventory" v-if="productAndCommodity">
          <text>库存：</text>
          <text>{{ itemInfo.goods.stock }}</text>
        </view>
        <view class="inventory" v-else>
          <text>{{ itemInfo.labels.join(" | ") }} </text>
        </view>

        <view class="price">
          <view class="commodity-price">
            <text style="font-size: 20rpx">￥</text>
            <text>{{ itemInfo.goods.discount_price.split(".")[0] }}</text
            >.
            <text style="font-size: 20rpx">{{
              itemInfo.goods.discount_price.split(".")[1]
            }}</text>
          </view>
          <view
            class="discount_price"
            v-if="itemInfo.goods.price != itemInfo.goods.discount_price"
          >
            ￥{{ itemInfo.goods.price }}</view
          >
        </view>
      </view>
    </view>

    <view class="btn-list" v-if="!batch && productAndCommodity == 'commodity'">
      <button
        class="btn-1"
        v-if="itemInfo.goods.status == 'normal'"
        @click.stop="$emit('openDiscountsPopup', itemInfo)"
      >
        我要打折
      </button>
      <button
        class="btn-1"
        v-if="itemInfo.goods.status == 'normal'"
        @click.stop="$emit('addAndRemove', itemInfo, 'down')"
      >
        下架
      </button>
      <button
        class="btn-1"
        v-if="itemInfo.goods.status == 'down'"
        @click.stop="$emit('deleteGoods', itemInfo)"
      >
        删除
      </button>
      <button
        class="btn-1"
        v-if="itemInfo.goods.status == 'down'"
        @click.stop="$emit('addAndRemove', itemInfo, 'normal')"
      >
        上架
      </button>
      <!-- <button class="btn-2" v-if="itemInfo.goods.status == 'down'">编辑</button> -->
    </view>
  </view>
</template>

<script>
export default {
  props: {
    status: {
      typeof: String,
      default: "",
    },
    itemInfo: {
      typeof: Object,
      default: () => {
        return {};
      },
    },
    productAndCommodity: {
      typeof: String,
      default: "",
    },
    batch: {
      typeof: Boolean,
      default: false,
    },
  },
  watch: {},
  data() {
    return {
      obj: {
        url: "https://img11.360buyimg.com/jdcms/s460x460_jfs/t1/136953/20/42322/162799/665e6a6cF32604c1e/b9586c7ae52dc284.jpg.avif",
        title: "La Chapelle Sport拉夏贝尔高…",
        price: "75.00",
      },
      lebelList: [],
    };
  },
  computed: {
    isPadding() {
      if (this.productAndCommodity == "product") {
        return "padding: 28rpx 20rpx 20rpx;";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.detail {
  background-color: #fff;
  border-radius: 16rpx;
  margin: 10rpx 0;
  width: 94vw;

  .content {
    display: flex;
    position: relative;
    flex-shrink: 0;
    justify-content: flex-start;
    width: 100%;

    .content-img {
      width: 164rpx;
      height: 164rpx;
      border-radius: 12rpx;
      margin-right: 20rpx;
      flex-shrink: 0;
    }

    .mask {
      width: 164rpx;
      height: 164rpx;
      border-radius: 12rpx;
      position: absolute;
      background-color: rgba(255, 255, 255, 0.3);
      z-index: 100;
      display: flex;
      justify-content: center;
      align-items: center;

      .text-1 {
        width: 108rpx;
        height: 44rpx;
        text-align: center;
        line-height: 44rpx;
        color: #fff;
        background-color: rgba(0, 0, 0, 0.4);
        border-radius: 22rpx;
        font-size: 20rpx;
      }
    }

    .content-right {
      width: 80%;
      .goods-title {
        color: #333;
        margin-bottom: 20rpx;
        width: 88%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        word-break: break-word;
        display: flex;
        justify-content: flex-start;
        align-items: center;

        .title {
          width: 75%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          word-break: break-word;
        }

        ._label {
          color: #fff;
          background-color: #ffb111;
          width: 72rpx;
          height: 32rpx;
          text-align: center;
          line-height: 32rpx;
          height: 32rpx;
          border-radius: 4rpx;
          font-size: 20rpx;
          margin-right: 10rpx;
        }
      }

      .inventory {
        color: rgba(54, 54, 54, 0.5);
        font-size: 24rpx;
        margin-bottom: 30rpx;
      }

      .commodity-price {
        color: #f83224;
        font-size: 32rpx;
        font-weight: 600;
      }
      .price {
        display: flex;
        align-items: flex-end;
        .discount_price {
          margin-left: 20rpx;
          font-size: 26rpx;
          color: rgba(51, 51, 51, 0.5);
          text-decoration-line: line-through;
        }
      }
    }
  }

  .btn-list {
    display: flex;
    justify-content: flex-end;

    .btn-1 {
      height: 60rpx;
      margin: 0;
      padding: 0;
      font-size: 26rpx;
      color: #333;
      border: 2rpx solid rgba(151, 151, 151, 0.3);
      border-radius: 30rpx;
      background-color: #fff;
      line-height: 60rpx;
      margin-left: 20rpx;
      padding: 0 30rpx;
    }

    .btn-2 {
      height: 60rpx;
      margin: 0;
      padding: 0;
      font-size: 26rpx;
      color: #f83224;
      border: 2rpx solid #f83224;
      border-radius: 30rpx;
      background-color: #fff;
      margin-left: 20rpx;
      line-height: 60rpx;
      padding: 0 30rpx;
    }
  }
}
</style>
