<template>
  <div class="pop-box">
    <img class="close" @click="cancel" src="/img/home/nav/close.png" alt="极度证券">
    <div class="title">{{ targetData.title }}</div>
    <div class="des" v-if="targetData.desc">
      {{ targetData.desc }}
    </div>
    <div class="product-list flex" v-if="productList.length == 1">
      <div class="product flex" v-if="productDataObj[productList[0]]" @click="$router.push('/product-detail/' + productList[0])">
        <div class="left">
          {{ productDataObj[productList[0]].title }}
        </div>
        <div class="number" :class="productDataObj[productList[0]].percentage >= 0 ? 'up' : 'down'">{{ productDataObj[productList[0]].percentage > 0 ? '+' : ''  }}{{ productDataObj[productList[0]].percentage }}%</div>
      </div>
    </div>
    <van-row v-else>
      <van-col span="12" v-for="(item, index) in productList" :key="index">
        <div class="product flex" @click="$router.push('/product-detail/' + item)">
          <div class="left">
            {{ productDataObj[item].title }}
          </div>
          <div class="number" :class="productDataObj[item].percentage >= 0 ? 'up' : 'down'">{{ productDataObj[item].percentage > 0 ? '+' : ''  }}{{ productDataObj[item].percentage }}%</div>
        </div>
      </van-col>
    </van-row>
    <div class="btns flex">
      <div class="btn ltn" @click="cancel">
        <!-- 我知道了 -->
        {{ $t('market.l15') }}
      </div>
      <template v-if="targetData.url || targetData.market">
        <div class="btn rtn" @click="toDetail(targetData)">
          <!-- 去看看 -->
          {{ $t('inform.l54') }}
        </div>
      </template>
    </div>
  </div>
</template>
<script>
export default {
  props: ['targetData', 'symbolList'],
  inject: ['getproductDataObj'],
  data () {
    return {
      
    }
  },
  computed: {
    productDataObj() {
      return this.getproductDataObj()
    },
    productList() {
      return this.symbolList.filter(item => this.productDataObj[item])
    }
  },
  methods: {
    cancel() {
      this.$emit('cancel')
    },
    toDetail(targetData) {
      this.cancel()
      if (targetData.market) {
        this.$router.push('/market/stock/' + targetData.market.toUpperCase())
        return
      }
      location.href = targetData.url
    }
  }
}
</script>
<style lang="less" scoped>
.pop-box {
  padding: 21px 21px 16px;
  position: relative;
  .close {
    cursor: pointer;
    position: absolute;
    top: 17px;
    right: 10px;
    width: 15px;
  }
  .title {
    font-weight: 500;
    font-size: 20px;
    text-align: center;
  }
  .des {
    font-weight: 400;
    font-size: 14px;
    color: #767676;
    line-height: 22px;
    text-align: left;
    padding-top: 13px;
    margin-bottom: 15px;
  }
  .van-row {
    margin: 0 -3px;
  }
  .van-col {
    padding: 0 3px 10px;
  }
  .product {
    border-radius: 5px;
    border: 1px solid #F1F3F4;
    column-gap: 6px;
    height: 35px;
    padding: 0 7px;
    cursor: pointer;
    .left {
      flex: 1;
      min-width: 10%;
      max-width: 100%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      font-weight: 600;
      font-size: 12px;
      color: #333333;
      line-height: 22px;
    }
    .number {
      font-weight: 400;
      font-size: 14px;
      line-height: 14px;
      &.up {
        color: #FF4730;
      }
      &.down {
        color: #22AF6E;
      }
    }
  }
}
.product-list {
  justify-content: center;
  margin-bottom: 10px;
  .product {
    width: 225px;
  }
}
.btns {
  justify-content: center;
  column-gap: 12px;
  .btn {
    text-align: center;
    cursor: pointer;
    flex: 1;
    min-width: 10%;
    max-width: 135px;
    font-size: 16px;
    line-height: 42px;
    border-radius: 6px;
  }
  .ltn {
    border: 1px solid #DEDEDE;
  }
  .rtn {
    background-color: #000;
    border: 1px solid #000;
    color: #FEFFFF;
  }
}
</style>