<template>
  <div class="toggleStore">
    <!--寄售-->
    <div class="sale list-item" @click="open('/store/33069557578d44e69bd91ad12d28a8d4')">
      <div class="header">
        <div class="kind"><span></span>优软寄售</div>
        <a class="enter" @click="open('/store/33069557578d44e69bd91ad12d28a8d4')">进入店铺 <i class="fa fa-angle-right"></i></a>
      </div>
      <div class="body">
        <p>海量库存，不赚差价</p>
      </div>
    </div>
    <!--原厂-->
    <div class="factory list-item" :class="{active: storeType === 'factory'}" @click="toggleStore('factory')">
      <div class="header">
        <div class="kind"><span></span>原&nbsp;&nbsp;&nbsp;&nbsp;厂</div>
        <div class="count">
          <span>已入驻</span>
          <div class="count_num">
            <span v-for="item in formatNumber(originalCount, 4)" v-text="item">1</span>
          </div>
        </div>
      </div>
      <div class="body">
        <p>原厂直营，品质保障</p>
      </div>
    </div>
    <!--代理经销-->
    <div class="agent list-item" :class="{active: storeType === 'origin'}" @click="toggleStore('origin')">
      <div class="header">
        <div class="kind"><span></span>代理经销</div>
        <div class="count">
          <span>已入驻</span>
          <div class="count_num">
            <span v-for="item in formatNumber(storeCount, 4)" v-text="item">1</span>
          </div>
        </div>
      </div>
      <div class="body">
        <p>百强代理，一站找齐</p>
      </div>
    </div>
    <!--供应商-->
    <div class="agent list-item" :class="{active: storeType === 'supplier'}" @click="toggleStore('supplier')">
      <div class="header">
        <div class="kind"><span></span>供应商</div>
        <div class="count">
          <span>已入驻</span>
          <div class="count_num">
            <span v-for="item in formatNumber(supplierArr, 4)" v-text="item">1</span>
          </div>
        </div>
      </div>
      <div class="body">
        <p>产业资源，免费共享</p>
      </div>
    </div>
    <!--品牌墙-->
    <div class="agent list-item" :class="{active: storeType === 'brand'}" @click="toggleStore('brand')">
      <div class="header">
        <div class="kind"><span></span>品牌墙</div>
        <div class="count">
          <span>已入驻</span>
          <div class="count_num">
            <span v-for="item in formatNumber(brandArr, 4)" v-text="item">1</span>
          </div>
        </div>
      </div>
      <div class="body">
        <p>全球品牌，自由筛选</p>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  name: 'excellent-suppliers',
  data () {
    return {
      supplierArr: '',
      brandArr: ''
    }
  },
  computed: {
    storeType () {
      return this.$route.params.type
    },
    store () {
      return this.$store.state.provider.storeCms.recommendStore.data
    },
    storeCount () {
      return this.$store.state.provider.stores.storeCount.data
    },
    originalCount () {
      return this.$store.state.provider.stores.originalCount.data
    },
    count () {
      let allCount = this.$store.state.option.counter.data ? this.$store.state.option.counter.data : []
      if (allCount && Array.isArray(allCount)) {
        allCount.forEach((value) => {
          if (value.item === '供应商') {
            this.supplierArr = value.count
          }
          if (value.item === '品牌') {
            this.brandArr = value.count
          }
        })
      }
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.count
    })
  },
  create () {
    this.$store.dispatch('loadCounterData')
  },
  methods: {
    // 切换Store
    toggleStore (type) {
      if (type === this.storeType) return
      localStorage.setItem('pageChange', 'false')
      this.$store.dispatch('loadBanners', {type: type + '_banner_carousel'})
      this.$store.dispatch('provider/findSimilarStoreList', { page: 1, count: 10, type: type === 'factory' ? 'ORIGINAL_FACTORY' : 'AGENCY-DISTRIBUTION' })
      if (type === 'brand') {
        this.$router.push('/eCommerce/home/brand/?initial=A')
      }
      if (type === 'supplier') {
        this.$router.push('/eCommerce/home/supplier')
      }
      if (type === 'factory') {
        this.$router.push('/eCommerce/home/factory')
      }
      if (type === 'origin') {
        this.$router.push('/eCommerce/home/origin')
      }
    },
    // 店铺入驻数量
    formatNumber (num, key) {
      let count = ('0000' + num).substr(-key)
      let _arr = []
      for (var i = 0; i < count.length; i++) {
        _arr.push(count[i])
      }
      return _arr
    },
    // 寄售
    open (url) {
      window.open(url)
    }
  }
}
</script>
<style lang="scss" scoped>
  .toggleStore {
    float: left;
		width: 220px;
    height: 402px;
		padding: 0;
    .list-item{
      width: 100%;
      height: 81px;
      background: #fff;
      border-bottom: 1px solid #ece9ec;
      .header {
        overflow: hidden;
        padding: 10px 8px 0;
        .kind{
          float: left;
          font-size: 16px;
          font-weight: bold;
          color: #2496f1;
            span{
              display: inline-block;
              margin-right: 4px;
              width: 6px;
              height: 12px;
              background: url('/images/original/angle-blue.png') no-repeat;
            }
        }
        .count{
          overflow: hidden;
          float: right;
          padding: 0 5px;
          width: 120px;
          height: 26px;
          line-height: 24px;
          background-color: #fff;
          border-radius: 2px;
          border: solid 1px #bfbfbf;
          span {
            float: left;
            margin-right: 4px;
            font-size: 12px;
            letter-spacing: 0;
            color: #666;
          }
          .count_num{
            float: left;
            margin-top: 3px;
            span{
              display: inline-block;
              width: 14px;
              height: 18px;
              line-height: 18px;
              font-size: 12px;
              color: #fff;
              text-align: center;
              background-color: #a1a0a0;
              border-radius: 2px;
              &:last-child{
                margin-right: 0;
               }
            }
          }
        }
        .enter{
          float: right;
          display: inline-block;
          width: 72px;
          height: 22px;
          line-height: 20px;
          text-align: center;
          font-size: 12px;
          color: #2496f1;
          background-color: #ffffff;
          border-radius: 11px;
          border: solid 1px #2496f1;
          i{
            font-size: 16px;
          }
          &:hover{
            color: #fff;
            background: #2496f1;
            border: solid 1px #2496f1;
           }
        }
      }
      .body {
        margin-top: 15px;
        padding: 0 20px 0;
        p{
          width: 195px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          font-size: 14px;
          letter-spacing: 0;
          color: #666666;
        }
      }
      &:hover, &.active{
         background: #fa9819;
         cursor: pointer;
        .kind {
          color: #fff;
          span{
            background: url('/images/original/angle-white.png') no-repeat;
          }
        }
        .count{
          background-color: #d87c05;
          border: solid 1px #d87c05;
          span {
            color: #fff;
          }
          .count_num{
            span{
              color: #626364;
              background-color: #fff;
            }
          }
        }
        .body{
          p{
            color: #fff;
          }
        }
      }
    }
    .factory {
      border-top-left-radius: 5px;
      border-top-right-radius: 5px;
    }
    .sale{
      border-bottom-left-radius: 5px;
      border-bottom-right-radius: 5px;
    }
	}
</style>
