<template>
  <div v-if="pageflag" class="right_center_wrap beautify-scroll-def">
    <div id="scrollView2" class="rowup2">
      <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-2">
              <span class="ciyao"> {{ item.productCode }}</span>
            </div>
            <div class="info col-3">
              <span class="zhuyao"> {{ item.productBrandName + item.productTypeName3 }}</span>
            </div>
            <div class="info col-4">
              <span class="warning" v-if="curTab==1"> {{ item.resultQty||'--' }}</span>
              <span class="warning" v-if="curTab==2"> {{ 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-2">
              <span class="ciyao"> {{ item.productCode }}</span>
            </div>
            <div class="info col-3">
              <span class="zhuyao"> {{ item.productBrandName + item.productTypeName3 }}</span>
            </div>
            <div class="info col-4">
              <span class="warning" v-if="curTab==1"> {{ item.resultQty||'--' }}</span>
              <span class="warning" v-if="curTab==2"> {{ item.resultAmount | montionFilter }}</span>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
  <Reacquire v-else @onclick="getData" style="line-height:200px" />

</template>

<script>
import { addKeyFrames } from '@/utils/domUtil.js'
import Kong from '@/bigScreenComponents/kong.vue'
import { queryProductPurchase } from '@/api/bigScreen'
export default {
  components: { Kong },
  props: {
  	curTab: {
  		type: Number,
  		default: 1
  	},
    curYear: {
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      list: [],
      pageflag: true,
      timer: null,
      queryType: 'amount',
      loading: false
    }
  },
  created () {
    this.$nextTick(() => {
      this.getData()
    })
  },
  watch: {
    curYear (a,b){
      this.getData()
    },
  	curTab (newValue, oldValue) {
      this.queryType = newValue == 1 ? 'qty' : 'amount'
  		this.getData()
  	}
  },
  mounted () { },
  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 () {
      this.loading = true
      const date = this.curYear + '-01-01'
      document.getElementById('scrollView2').className = ''
      queryProductPurchase({ queryDate: date, queryType: this.queryType }).then(res => {
        if (res.status == 200) {
          this.list = res.data
          this.list.map(item => {
            item.resultAmount = item.resultAmount / 10000
          })
          document.getElementById('scrollView2').className = 'rowup2'
          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('rowup2', '-' + 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: rgba(255, 255, 255, 0.8);
      }
      .dibu {
        position: absolute;
        height: 2px;
        width: 104%;
        background-image: url("../../../assets/img/zuo_xuxian.png");

        bottom: -12px;
        left: 0;
        background-size: cover;
      }
    }
    .col-2{
          width: 25%;
    }
    .col-3{
          width: 40%;
    }
    .col-4{
          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>
