<template>
  <div v-if="pageflag" class="right_center_wrap beautify-scroll-def">
    <div class="rowup2">
      <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="zhuyao"> {{ item.productCode }}</span>
            </div>
            <div class="info col-3">
              <span class="ciyao"> {{ 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">
        <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="zhuyao"> {{ item.productCode }}</span>
            </div>
            <div class="info col-3">
              <span class="ciyao"> {{ 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
  	}
  },
  data () {
    return {
      list: [],
      pageflag: true,
      timer: null,
      queryType: 'amount'
    }
  },
  created () {
    this.getData()
  },
  watch: {
  	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 () {
      const date = new Date().getFullYear() + '-01-01'
      queryProductPurchase({ queryDate: date, queryType: this.queryType }).then(res => {
        if (res.status == 200) {
          this.list = res.data
          if (!this.timer) {
            console.log('销售数量/金额TOP100产品', res)
            // 无缝滚动
            const height = this.list.length * 48.5
            const dur = this.list.length * 2
            addKeyFrames('rowup2', '-' + height + 'px', dur)
          }
          this.switper()
        } else {
          this.pageflag = 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-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, 0.8);
      }
      .warning {
        color: #E6A23C;
        font-size: 15px;
      }
    }

  }
}

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

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