<template>
  <div class="page-contain list-contain">
    <top-nav title="竞品信息"
             :showQuery="false"></top-nav>
    <div v-if="dataList.length"
         class="data-list">
      <div v-for="(item, index) in dataList"
           :key="index"
           class="collapse-box">
        <div class="top">
          <div class="row title">
            <span class="fb"></span>
            <div @click="handleExtend(index)"
                 class="fc8CEE">
              <span v-if="item.isExtend">收起</span>
              <span v-else>更多</span>
              <van-icon :name="item.isExtend?'arrow-up':'arrow-down' " />
            </div>
          </div>
          <div class="row ptb20">
            <span>存储品牌：{{item.brandName}}</span>
            <span>存储类型：{{item.storageType}}</span>
          </div>
          <div class="row">
            <span>存储型号：{{item.storageModelType}}</span>
            <span>采购价：{{item.purchasePrice}}</span>
          </div>
        </div>
        <div v-show="item.isExtend"
             class="info-box">
          <div class="info-item">
            <span class="left">预计份额</span>
            <span class="right">{{item.estimatedProportion}}%</span>
          </div>
          <div class="info-item">
            <span class="left">货源供应</span>
            <span class="right">{{item.sourceSupplyKey}}</span>
          </div>
        </div>
      </div>
    </div>

    <van-empty v-if="!dataList.length && showNoData"
               description="暂无数据！" />
  </div>
</template>

<script>

export default {
  name: 'project-competitive',
  created () {
    this.projectId = this.$route.params.projectId
    this.getCompetitiById()
  },
  methods: {
    //  根据 项目id 查询竞品信息
    getCompetitiById () {
      this.$axios.post({
        domain: 'crmUrl',
        url: 'projectCompetitive.getCompetitives',
        data: { projectId: this.projectId },
        requestType: 'body',
        isShow: true,
        success: function (res) {
          if (res.errorCode === 200) {
            this.dataList = res.data || []
            this.dataList.forEach(item => {
              this.$set(item, 'isExtend', true)
            })
          } else {
            this.$toast({ type: 'fail', message: res.msg })
          }
        }.bind(this),
        error: function (err) {
          this.$toast({ type: 'fail', message: err, duration: 3000 })
        }.bind(this),
        complete: function () {
          this.showNoData = true;
        }.bind(this)
      })
    },
    handleExtend (index) {
      this.dataList[index].isExtend = !this.dataList[index].isExtend
    }

  },
  data () {
    return {
      projectId: '',
      dataList: [],
      showNoData: false,
    }
  }
}
</script>

<style scoped  lang="scss">
</style>
