<template>
  <div v-if="pageflag" class="right_center_wrap beautify-scroll-def">
    <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="dibu" v-if="i < 1"></div>
        <span class="orderNum">{{ item.name }}</span>
        <div class="inner_right">
          <div class="flex">
            <div class="info">
              <span class="nums zhuyao"> {{ item.saleNums }}</span>
              <span class="labels">销售数量</span>
            </div>
            <div class="info">
              <span class="nums warning"> {{ item.salesAmount }}</span>
              <span class="labels">销售金额</span>
            </div>
          </div>
        </div>
      </li>
    </ul>
  </div>
  <Reacquire v-else @onclick="getData" style="line-height:200px" />

</template>

<script>
import { querySaleMonthWeek } from '@/api/bigScreen.js'
import { formatThousands } from '@/utils/util.js'
export default {
  data () {
    return {
      list: [],
      pageflag: true,
      timer: null,
      loading: false
    }
  },
  computed: {
  },
  created () {
    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
      querySaleMonthWeek().then(res => {
        if (!this.timer) {
          console.log('本月/周销售', res)
        }
        if (res.status == 200) {
          const data = res.data
          this.list = [
            { 'salesAmount': formatThousands(data.monthAmount ? data.monthAmount.toFixed(2) : 0), 'saleNums': data.monthQty ? formatThousands(data.monthQty) : 0, 'name': '月' },
            { 'salesAmount': formatThousands(data.weekAmount ? data.weekAmount.toFixed(2) : 0), 'saleNums': data.weekQty ? formatThousands(data.weekQty) : 0, 'name': '周' }
          ]
          this.switper()
        } else {
          this.pageflag = false
        }
        this.loading = false
      })
    }
  }
}
</script>
<style lang="less" scoped>
.right_center {
  width: 100%;
  height: 100%;

  .right_center_item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: auto;
    padding: 13px 15px;
    font-size: 14px;
    color: #fff;
    position: relative;

    .dibu {
      position: absolute;
      height: 2px;
      width: 104%;
      background-image: url("../../../assets/img/zuo_xuxian.png");
      bottom: 0;
      left: -2%;
      background-size: cover;
    }

    .orderNum {
      font-size: 25px;
      font-weight: bold;
      border: 3px solid rgba(0, 170, 255, 0.5);
      border-radius: 200px;
      color: rgba(0, 170, 255, 0.6);
      display: inline-block;
      text-align: center;
      height: 70px;
      width: 70px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .inner_right {
      height: 100%;
      width: 400px;
      flex-shrink: 0;
      line-height: 1.5;
      .flex{
        display:flex;
      }
    }

    .info {
      width: 50%;
      margin:0 10px;
      display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: center;

      .labels {
        flex-shrink: 0;
        font-size: 16px;
        color: rgba(255, 255, 255, 0.4);
      }

      .nums {
        font-size: 32px;
        font-weight: bold;
      }

      .zhuyao {
        color: #00aaff;
      }

      .ciyao {
        color: rgba(255, 255, 255, 0.8);
      }

      .warning {
        color: #E6A23C;
      }
    }

  }
  .tit{
    align-items: center;
    justify-content: center;
    color: #31abe3;
    font-weight: 900;
    letter-spacing: 2px;
    margin-top:10px;
    span{
      display: inline-block;
      padding:10px 16px;
    }
  }
  .day_box{
    margin-bottom: 10px;
  }

}

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

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