<template>
  <div class="set-meal-item">
    <div class="set-meal-item-title">
      {{ packageType[data.cloudSetMealType] }} 安卓{{ data.androidVersion }}
    </div>
    <img src="@/assets/image/claimCloudPhone/vip-bg.png" alt="" />
    <div :class="['set-meal-item_content', { 'expand-open': isExpand }]">
      <div
        v-for="item in data.mealList"
        :key="item.id"
        class="set-meal-item_content-item"
      >
        <div class="set-meal-item_content-item_left">
          <div v-if="!type" class="invited">
            <img :src="require(`@/assets/image/${item.phoneType}_icon.png`)" />
            <div class="invited-info">
              <div>{{ packageType[item.phoneType] }}{{ item.day }}天套餐</div>
              <div>
                <div><span>￥</span>{{ item.actualPrice }}</div>
                <div v-if="item.originalPrice"><span>￥</span>{{ item.originalPrice }}</div>
              </div>
            </div>
          </div>
          <div v-else>
            {{ packageType[item.phoneType] }}{{ item.day }}天套餐
          </div>
        </div>
        <div class="set-meal-item_content-item_right">
          <div class="set-meal-item_content-item_right-price" v-if="type">
            <span>￥</span
            >{{ item.originalPrice ? item.originalPrice : item.actualPrice }}
          </div>
          <div @click="add(item)">
            {{ type ? '0元领' : '新增云手机' }}
          </div>
        </div>
      </div>
    </div>
    <div class="expand" v-if="data.mealList.length > 2">
      <span @click="isExpand = !isExpand">
        {{ isExpand ? '收起' : '查看全部' }}
        <van-icon :name="isExpand ? 'arrow-up' : 'arrow-down'" />
      </span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'setMealItem',
  props: {
    type: {
      type: Number,
      default: 1, // 0是被邀请人 1是邀请人
    },
    data: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      isExpand: false,
      packageType: {
        VIP: '星动',
        SVIP: '星曜',
        STARRYSKY: '星空',
        STAR: '唔即',
        STARPRO: '唔即Pro',
      },
    };
  },
  mounted() {
  },
  methods: {
    add(data) {
      if (this.type) {
        this.$router.push('/claimCloudPhone/1?menuRuleId=' + data.id)
        return 
      } 
      this.$emit('buy', data)
    },
  },
};
</script>
<style lang="less" scoped>
.set-meal-item {
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #feffef;
  margin-top: 12px;
  padding: 16px;
  font-family: PingFangSC, PingFang SC;
  & > img {
    height: 59px;
    width: 100%;
    margin-top: 12px;
  }
  .set-meal-item_content {
    max-height: 130px;
    overflow: hidden;
    &.expand-open {
      max-height: none;
    }

    .set-meal-item_content-item {
      padding: 14px 0;
      border-bottom: 1px solid #f0f0f0;
      display: flex;
      justify-content: space-between;
      .set-meal-item_content-item_left {
        display: flex;
        align-items: center;
        font-weight: bold;
        font-size: 14px;
        color: #6d2b12;
        line-height: 20px;
        text-align: left;
        font-style: normal;
        .invited {
          display: flex;
          align-items: center;
          & > img {
            width: 36px;
            height: 36px;
          }
          .invited-info {
            margin-left: 8px;
            & > div:last-of-type {
              display: flex;
              & > div {
                font-weight: bold;
                line-height: 20px;
                font-style: normal;
              }
              & > div:first-of-type {
                font-size: 16px;
                color: #f04646;
              }
              & > div:last-of-type {
                font-size: 12px;
                color: #bbbbbb;
                line-height: 23px;
                text-decoration: line-through;
                margin-left: 8px;
              }
            }
          }
        }
      }
      .set-meal-item_content-item_right {
        display: flex;
        align-items: center;
        .set-meal-item_content-item_right-price {
          font-weight: bold;
          font-size: 16px;
          color: #f04646;
          line-height: 20px;
          text-align: left;
          font-style: normal;
          display: flex;
          align-items: center;
          margin-right: 5px;
          text-decoration: line-through;
        }
        & > div:last-of-type {
          height: 30px;
          padding: 6px 12px;
          background: linear-gradient(178deg, #fd8c50 0%, #fc3307 100%);
          border-radius: 21px;
          font-weight: bold;
          font-size: 14px;
          color: #ffffff;
          line-height: 18px;
          text-align: left;
          font-style: normal;
        }
      }
    }
  }

  .set-meal-item-title {
    font-weight: bold;
    font-size: 18px;
    color: #6d2b12;
    line-height: 20px;
    text-align: left;
    font-style: normal;
  }

  .expand {
    display: flex;
    justify-content: center;
    font-weight: 400;
    font-size: 12px;
    color: #7d6156;
    line-height: 16px;
    text-align: center;
    font-style: normal;
    margin-top: 16px;
  }
}
</style>
