<template>
  <div class="fee-container">
    <div class="goods">
      <div class="fee-statistic mg-bottom-20">
        <span>商品总额</span>
        <span class="fee-statistic__bold">{{ formatPrice(calcFeeInfo.totalSkuFee) }} </span>
      </div>
      <div class="fee-statistic">
        <span>运费</span>
        <span>{{ formatPrice(calcFeeInfo.totalFreightFee) }}</span>
      </div>
    </div>
    <div class="coupon">
      <template v-for="(item, idx) in showList">
        <div
          :key="idx"
          class="fee-statistic freight-discount"
          :class="{ 'mg-bottom-20': idx !== showList.length - 1 }"
          @click="handleCouponShow(item)"
        >
          <span :class="{ giftcardTitle: item.couponActivityType == 20 }">
            {{ item.title }}
            <cr-icon
              v-if="
                item.couponActivityType == 20 &&
                  generalProp &&
                  generalProp.giftCardMaxUseAmt &&
                  generalProp.giftCardUseDesc
              "
              size="15px"
              type="info-o"
              @click.stop="showGiftCardDetail"
            />
          </span>
          <span :class="item.descObj.className">
            {{ item.descObj.desc }}
          </span>
          <i v-if="item.isVisibleIcon" class="iconfont icon-arrow" />
        </div>
      </template>
    </div>
    <cr-popup v-model="showGiftCardContext" class="giftCardDescModalContainer">
      <div class="giftCardDescModal">
        <div class="title">礼品卡使用明细</div>
        <div class="desc">
          <span class="desc-pre">本单最高可使用礼品卡抵扣的金额:</span>
          <span class="desc-amt">-{{ generalProp.giftCardMaxUseAmt || 0 }}元</span>
        </div>
        <div class="rule">
          <div class="rule-title">礼品卡权益说明</div>
          <div class="rule-detail" v-html="generalProp.giftCardUseDesc || ''" />
        </div>
        <div class="confirm" @click="showGiftCardContext = false">我知道了</div>
      </div>
    </cr-popup>
  </div>
</template>
<script>
import { formatPrice, checkEqualZero } from '@/service/utils.service';
export default {
  name: 'CouponInfo',
  props: {
    couponActivityInfoList: {
      type: Array,
      default: () => []
    },
    calcFeeInfo: {
      type: Object,
      default: () => {}
    },
    generalProp: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      showGiftCardContext: false
    };
  },
  computed: {
    showList() {
      return this.couponActivityInfoList.filter(item => {
        return [10, 9, 2, 20].includes(item.couponActivityType);
      });
    }
  },
  methods: {
    formatPrice,
    checkEqualZero,
    handleCouponShow(data) {
      this.$emit('coupon-show', data);
    },
    showGiftCardDetail() {
      const { giftCardMaxUseAmt, giftCardUseDesc } = this.generalProp;
      if (giftCardMaxUseAmt && giftCardUseDesc) this.showGiftCardContext = true;
    }
  }
};
</script>
<style scoped lang="less">
@modalBorderColor: #e8e8e8;
.giftcardTitle {
  display: flex;
  align-items: center;
  .cr-icon {
    margin-left: 2px;
  }
}
.mg-bottom-20 {
  margin-bottom: @padding-lg;
}
.goods,
.coupon {
  background: @white;
  padding: @padding-sm @padding-xs;
  border-radius: @border-radius-md;
  margin-bottom: @padding-sm;
}
.fee {
  &-statistic {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    span {
      .text-size(13);
      &:first-child {
        color: @gray-4;
        margin-right: auto;
      }
      &:last-child {
        color: @black;
      }
      &.free-ship {
        color: @gray-4;
      }
      &.has-coupon {
        color: @black;
      }
    }
    &__bold {
      color: @red !important;
      font-weight: 500;
    }
    .icon-arrow {
      .text-size(12);
      color: @gray-4;
    }
  }
}
.giftCardDescModalContainer {
  background: transparent !important;
  .giftCardDescModal {
    width: 300px;
    // height: 350px;
    border-radius: 16px;
    background: @white;
    box-sizing: border-box;
    padding: 20px 0 0;
    .title {
      padding: 0 @padding-md;
      box-sizing: border-box;
      font-size: 16px;
      color: #323233;
      text-align: center;
      font-weight: bold;
    }
    .desc {
      padding: 0 @padding-md;
      box-sizing: border-box;
      margin-top: @padding-md;
      display: flex;
      justify-content: space-between;
      align-items: center;
      &-pre {
        font-size: 12px;
        color: @gray-4;
      }
      &-amt {
        font-size: 13px;
        color: @red;
        font-weight: bold;
      }
    }
    .rule {
      padding: 0 @padding-md;
      box-sizing: border-box;
      margin-top: @padding-xs;
      &-title {
        width: 100%;
        height: 28px;
        background: #f7f8f9;
        border: 1px solid @modalBorderColor;
        box-sizing: border-box;
        font-size: 14px;
        font-weight: bold;
        color: @gray-5;
        line-height: 28px;
        text-align: center;
        border-bottom: 0;
      }
      &-detail {
        width: 100%;
        font-size: 12px;
        color: @gray-5;
        border: 1px solid @modalBorderColor;
        border-top: 0;
        padding: @padding-sm;
        box-sizing: border-box;
        line-height: 17px;
        max-height: 300px;
        overflow-x: hidden;
        overflow-y: auto;
        white-space: pre-wrap;
      }
    }
    .confirm {
      margin-top: @padding-x;
      border-top: 1px solid @modalBorderColor;
      text-align: center;
      font-weight: bold;
      color: @red;
      font-size: 16px;
      padding: @padding-md 0;
    }
  }
}
</style>
