<template>
  <div>
    <Subtitle :subtitle="subtitle"/>
    <ul class="goods">
      <li v-for="(item, index) in products"
          :key="index"
          @click="$emit('funJump', item)">
        <div class="left goods-cover">
          <img :src="routerName === 'loanRecommend' ? item.productPartnerUrl : item.productImgUrl" alt="">
        </div>
        <div class="right">
          <div class="div">
            <p class="name">{{ item.productName }}</p>
            <p class="money" v-if="routerName === 'loanRecommend'">{{ item.productDesc }}</p>
            <p class="money" v-else>最高可贷{{ item.productPrice | toThousands }}元</p>
          </div>
          <p class="specialty"
             :style="{'color': routerName === 'loanRecommend' ? '#FD4646' : ''}">
            {{ routerName === 'loanRecommend' ? '可帮您节省' + (item.saveMoney | toThousands) + '元利息' : item.productDesc }}</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import Subtitle from './subtitle'

export default {
  name: 'goods',
  components: {
    Subtitle
  },
  props: {
    subtitle: {
      type: String,
      default: ''
    },
    products: {
      type: Array,
      default: function () {
        return []
      }
    }
  },
  computed: {
    routerName () {
      // loanRecommend: 推荐商品
      return this.$route.name
    }
  }
}
</script>

<style lang="scss" scoped>
.goods {
  width: 343px;
  margin-left: 16px;

  li {
    display: flex;
    width: 100%;
    background: #FFFFFF;
    box-shadow: 0 2px 0px -1px rgba(224, 224, 224, 0.5);
    border-radius: 16px;
    padding: 10px;
    margin-bottom: 22px;

    &:nth-last-of-type(1) {
      margin-bottom: 0;
    }
  }

  .goods-cover {
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;

    img {
      display: block;
      width: 100%;
    }
  }

  .right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 7px 0 7px 16px;

    p {
      word-break: break-all;
    }
  }

  .name {
    font-size: 16px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    line-height: 22px;
  }

  .money {
    margin-top: 4px;
    font-size: 14px;
    color: #333333;
    line-height: 20px;
  }

  .specialty {
    font-size: 14px;
    color: #999999;
    line-height: 20px;
  }
}
</style>
