<template>
  <div v-if="pageflag" class="right_center_wrap beautify-scroll-def">
    <div class="rowup1">
      <div class="loading" v-if="loading"><a-spin /></div>
      <ul class="right_center">
        <li class="right_center_item" v-for="(item, i) in list" :key="i">
          <div class="inner_right">
            <div class="dibu"></div>
            <span class="orderNum">{{ i + 1 }}</span>
            <div class="info col-1">
              <span class="ciyao"> {{ item.dealerName }}</span>
            </div>
            <div class="info col-2">
              <span class="zhuyao"> {{ item.dealerLevelDictValue }}</span>
            </div>
            <div class="info col-3">
              <span class="warning"> {{ item.resultAmount | montionFilter }}</span>
            </div>
          </div>
        </li>
      </ul>
      <ul class="right_center" v-if="list.length>8">
        <li class="right_center_item" v-for="(item, i) in list" :key="i">
          <div class="inner_right">
            <div class="dibu"></div>
            <span class="orderNum">{{ i + 1 }}</span>
            <div class="info col-1">
              <span class="ciyao"> {{ item.dealerName }}</span>
            </div>
            <div class="info col-2">
              <span class="zhuyao"> {{ item.dealerLevelDictValue }}</span>
            </div>
            <div class="info col-3">
              <span class="warning"> {{ item.resultAmount | montionFilter }}</span>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
  <Reacquire v-else @onclick="getData" style="line-height:200px" />

</template>

<script>
import Kong from '@/bigScreenComponents/kong.vue'
import { addKeyFrames } from '@/utils/domUtil.js'
import { queryDealerPurchase } from '@/api/bigScreen'
export default {
  props: {
    curYear: {
      type: [Number, String],
      default: ''
    }
  },
  components: { Kong },
  data () {
    return {
      list: [],
      pageflag: true,
      timer: null,
      loading: false
    }
  },
  created () {
    this.getData()
  },
  watch:{
    curYear (a,b){
      this.getData()
    }
  },
  beforeDestroy () {
    this.clearData()
  },
  methods: {
    clearData () {
      if (this.timer) {
        clearInterval(this.timer)
        this.timer = null
      }
    },
    // 轮询
    switper () {
      if (this.timer) {
        return
      }
      const looper = (a) => {
        this.getData()
      }
      this.timer = setInterval(looper, this.$store.state.setting.echartsAutoTime)
    },
    getData () {
      const date = this.curYear + '-01-01'
      this.loading = true
      queryDealerPurchase({ queryDate: date }).then(res => {
        if (res.status == 200) {
          this.list = res.data
          this.list.map(item => {
            item.resultAmount = item.resultAmount / 10000
          })
          if (!this.timer) {
            console.log('采购金额TOP100加盟商', res)
            // 无缝滚动
            const len = this.list.length
            if (len > 8) {
              const height = len * 48.5
              const dur = len * 2
              addKeyFrames('rowup1', '-' + height + 'px', dur)
            }
          }
          this.switper()
        } else {
          this.pageflag = false
        }
        this.loading = false
      })
    }
  }
}
</script>
<style lang="less" scoped>
.right_center {
  width: 100%;
  height: 100%;

  .right_center_item {
    padding: 13px 0;
    font-size: 14px;
    color: #fff;

    .inner_right {
      display: flex;
      align-items: center;
      position: relative;
      height: 100%;
      width: 100%;
      flex-shrink: 0;
      line-height: 1.5;
      .orderNum {
        width: 10%;
        text-align: center;
        color: #fff;
      }
      .dibu {
        position: absolute;
        height: 2px;
        width: 104%;
        background-image: url("../../../assets/img/zuo_xuxian.png");
        bottom: -12px;
        left: 0;
        background-size: cover;
      }
    }
    .col-1{
      width: 40%;
    }
    .col-2{
      width: 25%;
    }
    .col-3{
      width: 25%;
    }
    .info {
      text-align: center;
      .zhuyao {
        color: #a6e0ff;
        font-size: 15px;
      }
      .ciyao {
        color: rgba(255, 255, 255, 1);
      }
      .warning {
        color: #ffb442;
        font-size: 15px;
        font-weight: bold;
      }
    }

  }
}

.right_center_wrap {
  overflow: hidden;
  width: 100%;
  height: 390px;
}

.overflow-y-auto {
  overflow-y: auto;
}
</style>
