<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">
            ￥<span>{{ item.faceValue }}</span>
          </view>
          <view class="Gci-amount-desc">{{ item.limitDesc }}</view>
        </view>
        <view class="Gci-left-desc">
          <span class="Gcil-desc-name">{{ item.name }}</span>
          <!-- <span v-if="!item.pickupAble" class="Gcil-desc-time"
            >{{ item.startDate }}-{{ item.endDate }}</span
          > -->
          <span class="Gcil-desc-time">{{ item.couponValidTime }}</span>
          <view>
            <span class="Gcil-desc-detail" />
            <span />
          </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, index)"
        >
          {{ item.pickupAble ? '已领取' : '立即领取' }}
        </button>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  name: 'CouponCard',
  props: {
    couponList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      // list: []
    };
  },
  computed: {
    list() {
      return 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)) || '';
        return el;
      });
    }
  },
  methods: {
    pickupCoupon(coupon, index) {
      if (coupon.pickupAble) {
        return;
      }
      this.$emit('pickupCoupon', coupon, index);
    }
  }
};
</script>
<style lang="less" scoped>
.goods-coupon {
  // margin: 0 12px;
  // padding-bottom: 30px;
  // padding-top: 20px;
  // height: 350px;
  // overflow-y: scroll;
  &-item {
    position: relative;
    margin-bottom: 10px;
    // width: 100%;
    height: 90px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 @padding-md;
    border-radius: 6px;
    .Gc-item-left {
      display: flex;
      flex: 1;
      padding-right: 12rpx;
      .Gci-left-type {
        position: absolute;
        top: 0;
        left: 0;
        width: 44px;
        height: 16px;
      }
      .Gci-left-amount {
        display: flex;
        flex-direction: column;
        width: 70px;
        margin-right: 18px;
        align-items: center;
        .Gcil-amount-price {
          .text-size(16);
          color: #f23e33;
          font-weight: bold;
          span {
            font-size: 30px;
          }
        }
        .Gci-amount-desc {
          // font-size: 12px;
          .text-size(12);
          color: #f23e33;
          width: 75px;
          text-align: center;
        }
      }
      .Gci-left-desc {
        display: flex;
        flex-direction: column;
        justify-content: center;
        .Gcil-desc-name {
          font-weight: bold;
          // font-size: 14px;
          .text-size(14);
          color: #333;
          text-align: left;
        }
        .Gcil-desc-time {
          // font-size: 12px;
          .text-size(12);
          color: #666;
        }
      }
    }
    .Gc-item-right {
      .Gci-right-receive {
        position: absolute;
        top: 0;
        right: 10px;
        width: 60px;
        // height: 25px;
      }
      .Gci-right-button {
        width: 82px;
        height: 24px;
        line-height: 24px;
        text-align: center;
        font-size: 12px;
        color: @white;
        background: @background-primary;
        border-radius: 20px;
        vertical-align: super;
        &_received {
          opacity: 0.6;
          // background-img: @background-primary;
        }
      }
    }
  }
  .Gc-item_pink {
    background: #ffece6;
  }
  .Gc-item_white {
    background: @white;
  }
}
</style>
