<template>
  <view class="goods-coupon">
    <view v-for="(item, index) in list" :key="index" class="goods-coupon-item Gc-item_pink">
      <view class="Gc-item-left">
        <image class="Gci-left-type" :src="item.iconUrl" />
        <view class="Gci-left-amount">
          <view class="Gcil-amount-price"
            >￥<text>{{ item.faceValue }}</text></view
          >
          <view class="Gci-amount-desc">{{ item.limitDesc }}</view>
        </view>
        <view class="Gci-left-desc">
          <text class="Gcil-desc-name">{{ item.name }}</text>
          <!-- <text v-if="!item.pickupAble" class="Gcil-desc-time"
            >{{ item.startDate }}-{{ item.endDate }}</text
          > -->
          <text class="Gcil-desc-time">{{ item.couponValidTime }}</text>
          <view>
            <text class="Gcil-desc-detail" />
            <text />
          </view>
        </view>
      </view>
      <view class="Gc-item-right">
        <image
          v-if="item.pickupAble"
          class="Gci-right-receive"
          src="https://img.lkbang.net/xcx/coupon_received@2x.png"
        />
        <button
          class="Gci-right-button"
          :class="{ 'Gci-right-button_received': item.pickupAble }"
          @click="pickupCoupon(item)"
        >
          {{ item.pickupAble ? "已领取" : "立即领取" }}
        </button>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  name: "CouponCard",
  props: {
    couponList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      list: []
    };
  },
  computed: {
    // list() {
    //   const coupon = []
    //    this.couponList.map(el => {
    //     el.startDate = el.startDate && el.startDate.replace(/-/g, '.').slice(0,10) || ''
    //     el.endDate = el.endDate && el.endDate.replace(/-/g, '.').slice(0,10) || ''
    //     coupon.push(el)
    //   });
    //   return coupon
    // }
  },
  watch: {
    couponList: {
      handler() {
        this.list = [];
        this.couponList.map(el => {
          el.startDate = (el.startDate && el.startDate.replace(/-/g, ".").slice(0, 10)) || "";
          el.endDate = (el.endDate && el.endDate.replace(/-/g, ".").slice(0, 10)) || "";
          this.list.push(el);
        });
      },
      immediate: true
    }
  },
  methods: {
    pickupCoupon(coupon) {
      if (coupon.pickupAble) {
        return;
      }
      this.$emit("pickupCoupon", coupon);
    }
  }
};
</script>
<style lang="scss" scoped>
.goods-coupon {
  margin: 0 24rpx;
  &-item {
    position: relative;
    margin-bottom: 20rpx;
    width: 100%;
    height: 180rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 $padding-md;
    border-radius: $border-radius-base;
    .Gc-item-left {
      display: flex;
      flex: 1;
      padding-right: 16rpx;
      .Gci-left-type {
        position: absolute;
        top: 0;
        left: 0;
        width: 88rpx;
        height: 32rpx;
      }
      .Gci-left-amount {
        display: flex;
        flex-direction: column;
        width: 140rpx;
        margin-right: $margin-1 - 4;
        align-items: center;
        .Gcil-amount-price {
          font-size: $font-lg;
          color: $font-color-red;
          font-weight: bold;
          text {
            font-size: $font-1;
          }
        }
        .Gci-amount-desc {
          font-size: $font-sm;
          color: $font-color-red;
          width: 150rpx;
          text-align: center;
        }
      }
      .Gci-left-desc {
        display: flex;
        flex-direction: column;
        justify-content: center;
        .Gcil-desc-name {
          font-weight: bold;
          font-size: $font-base;
          color: $text-color-n5;
        }
        .Gcil-desc-time {
          font-size: $font-sm;
          color: $text-color-n3;
        }
      }
    }
    .Gc-item-right {
      .Gci-right-receive {
        position: absolute;
        top: 0;
        right: 20rpx;
        width: 120rpx;
        height: 100rpx;
      }
      .Gci-right-button {
        width: 164rpx;
        height: 48rpx;
        line-height: 48rpx;
        text-align: center;
        font-size: $font-sm;
        color: $white;
        background-image: $background-primary;
        border-radius: $border-radius-2;
        &_received {
          opacity: 0.6;
          // background-image: $background-primary;
        }
      }
    }
  }
  .Gc-item_pink {
    background: $bg-color-pink;
  }
  .Gc-item_white {
    background: $white;
  }
}
</style>
