<template>
  <div class="coupon-item flex-default" @click="handleClick">
    <div class="left flex-default">
      <div class="coupon-val flex-default">
        <div class="rmb">￥</div>
        <div class="val">{{ data.couponVal }}</div>
        <!-- <div class="discount">折</div> -->
      </div>
      <div class="condition-txt">{{ descLabel }}</div>
    </div>
    <div class="right flex-default">
      <div class="top flex-default">
        <div class="type">{{ couponObj.label }}</div>
        <div class="name">{{ data.name }}</div>
      </div>
      <div class="bottom flex-default">
        <div class="date">
          {{ data.startTime | formatTime }}-{{ data.endTime | formatTime }}
        </div>
        <van-button
          class="btn"
          type="primary"
          v-if="!isSelectMode"
          @click="$emit('get')"
          :disabled="btnDisabled"
          round
        >
          {{ btnLabel }}
        </van-button>
      </div>
      <div class="disabled-bottom flex-default" v-show="isSelectMode && disabled">
        <m-icon icon="icon-warning" :size="10" />
        <span class="text">不可使用</span>
      </div>
    </div>
    <div class="select flex-default" v-if="isSelectMode">
      <m-icon :icon="selectIcon" :size="16" />
    </div>
  </div>
</template>

<script>
import {
  CouponType,
  CouponTypeObj,
  CouponRangeType,
  CouponRangeTypeLabel,
} from "@/enums";
import { formatTime } from "@/utils/common";
export default {
  props: {
    index: {
      type: [Number, String],
    },
    data: {
      type: Object,
      default: () => {
        return {};
      },
    },
    // normal  select
    mode: {
      type: String,
      default: "normal",
    },
    select: {
      type: Boolean,
      default: false,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    isSelectMode() {
      return this.mode == "select";
    },
    selectIcon() {
      if (this.disabled) {
        return "icon-radio-hook-disabled";
      }
      return this.select ? "icon-radio-hook-check" : "icon-radio-hook";
    },
    couponObj() {
      if (this.data.type) {
        return CouponTypeObj[this.data.type];
      }
      return {};
    },
    descLabel() {
      if (this.data.type == CouponType.FULL_REDUCTION) {
        return `满${this.data.conditionVal}可用`;
      } else if (this.data.type == CouponType.DIRECT_REDUCTION) {
        return CouponRangeTypeLabel[this.data.rangeType];
      }
      return "";
    },
    btnDisabled() {
      if (this.data.uid) {
        return true;
      }
      return false;
    },
    btnLabel() {
      return this.btnDisabled ? "已领取" : "点击领取";
    },
  },

  filters: {
    formatTime(val) {
      if (!val || val.length == 0) {
        return "";
      }
      return formatTime(val, "yyyy/MM/dd");
    },
  },
  methods: {
    handleClick() {
      if (!this.disabled) {
        this.$emit("select", this.index, this.data);
      }
    },
  },
};
</script>

<style lang="less">
.coupon-item {
  height: 100px;
  width: 100%;
  margin-bottom: 13px;
  border-radius: 13px;
  background-image: url("~@/assets/img/coupon-bg.png");
  background-size: 100%;
  background-repeat: no-repeat;
  > .left {
    width: 115px;
    height: 100%;
    // background: linear-gradient(180deg, #f05b76 0%, #dd2e41 100%);
    border-radius: 10px 0 0 10px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    .coupon-val {
      align-items: flex-start;
      > uni-view {
        display: inline-block;
      }
      .rmb {
        font-size: 12px;
        line-height: 30px;
        font-family: DINAlternate-Bold, DINAlternate;
      }
      .val {
        letter-spacing: 0;
        font-size: 40px;
        line-height: 42px;
        font-family: DINAlternate-Bold, DINAlternate;
      }
      .discount {
        font-size: 12px;
      }
    }
    .condition-txt {
      font-size: 12px;
      line-height: 17px;
    }
  }
  > .right {
    // background: #ffffff;
    flex: 1;
    height: 100%;
    border-radius: 0 13px 13px 0;
    flex-direction: column;
    align-items: flex-start;
    padding: 10px;
    .top {
      align-items: flex-start;
      color: #140603;
      flex: 1;
    }
    .top .type {
      background: #fdbf30;
      border-radius: 13px;
      line-height: 20px;
      padding: 0 9px;
      font-size: 10px;
      margin-right: 7px;
    }
    .top .name {
      font-size: 14px;
      font-weight: bold;
      line-height: 18px;
    }
    .bottom {
      width: 100%;
      align-items: center;
      justify-content: space-between;
    }
    .bottom .date {
      font-size: 10px;
      color: #aeaeae;
    }
    .bottom .btn {
      font-size: 11px;
      height: 24px;
      padding: 0 10px;
    }
    .disabled-bottom {
      align-items: center;
    }
    .disabled-bottom .text {
      color: #AEAEAE;
      font-size: 9px;
      line-height: 12px;
      margin-left: 3px;
    }
  }
  > .select {
    height: 100%;
    align-items: center;
    padding-right: 16px;
  }
}
</style>