<template>
  <div class="card-content flex-l" :class="{invalid: data.invalid || isgrey}">
    <div class="card-top flex-h">
      <div>
        <img :src="logo" class="logo">
        <span>￥ <span> {{data.price}} </span> 元</span>
        <img :src="line3" class="line3">
      </div>
      <div>
        <h2>{{data.title}}</h2>
        <span class="descs">{{data.desc}}</span>
        <span>{{data.startDate}}-{{data.endDate}}</span>
      </div>
    </div>
    <div class="card-main flex-h">
      <img :src="line">
      <div class="flex-h">
        <span>总数量</span>
        <span>{{data.totalCount}}</span>
      </div>
      <div>
        <span>总剩余</span>
        <span>{{data.totalCount - data.SentCount}}</span>
      </div>
      <div>
        <span>用户领取</span>
        <span>{{ismanger?data.SentCount:userGet.length}}</span>
      </div>
      <div>
        <span>用户使用</span>
        <span>{{ismanger?data.UsedCount:userGet.filter(x => x.status===1).length}}</span>
      </div>
    </div>
    <div class="card-bottom" @click.stop="share">
      分享卡券
    </div>
  </div>
</template>

<script>
import logo from '../../common/icon/logo-t.png'
import line from '../../common/icon/cicyle.png'
import line3 from '../../common/icon/Line3.png'
export default {
  name: 'myCard',
  data () {
    return {
      logo,
      line,
      line3
    }
  },
  props: {
    data: {
      type: Object,
      default: () => { }
    },
    isgrey: {
      type: Boolean,
      default: false
    },
    userGet: {
      type: Array,
      default: []
    },
    ismanger: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    share () {
      if (!this.data.invalid) {
        if (this.isgrey) {
          this.$toast('您的卡券分享功能已被关闭，请联系主管')
        } else {
          this.$emit('share', this.data)
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.card-content {
  box-shadow: 0px 2px 0.1rem 0px rgba(193, 204, 217, 0.5);
  border-radius: 0.08rem;
  overflow: hidden;
  margin-bottom: 0.2rem;
  &.invalid {
    filter: grayscale(100%);
    opacity: 0.5;
  }
  .card-top {
    height: 1rem;
    padding: 0.1rem;
    box-sizing: border-box;
    .descs {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      height: 0.32rem;
      line-height: 0.16rem;
    }
    div:nth-of-type(1) {
      width: 1.15rem;
      position: relative;
      .logo {
        width: 85%;
        position: absolute;
      }
      .line3 {
        height: 80%;
        position: absolute;
        right: 0.15rem;
        top: 10%;
      }
      > span {
        color: #fc6243;
        position: absolute;
        top: 50%;
        left: 40%;
        transform: translate(-50%, -50%);
        font-size: 0.14rem;
        display: flex;
        align-items: baseline;
        span {
          color: #fc6243;
          font-size: 0.22rem;
        }
      }
    }
    div:nth-of-type(2) {
      flex: 1;
      h2 {
        font-size: 0.16rem;
      }
      span {
        color: #323645;
        font-size: 12px;
        padding-top: 0.05rem;
      }
    }
  }
  .card-main {
    position: relative;
    img {
      width: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }
    div {
      flex: 1;
      display: flex;
      flex-flow: column nowrap;
      justify-content: center;
      align-items: center;
      padding-top: 0.15rem;
      span:nth-of-type(1) {
        font-size: 0.12rem;
        color: #323645;
      }
      span:nth-of-type(2) {
        font-size: 0.12rem;
        color: #fc6243;
      }
    }
  }
  .card-bottom {
    padding: 0.1rem;
    margin-top: 0.1rem;
    background-color: #fc6243;
    text-align: center;
    color: #fff;
    border-radius: 0 0 0.08rem 0.08rem;
  }
}
</style>
