<template>
  <div style="flex: 1;margin-bottom: 10px">
    <Card style="width:100%">
      <div class="config_meta">
        <p class="fl">
          在检任务
        </p>
        <div class="fr">
          <ButtonGroup shape="circle" size="small">
            <Button
              v-for="(item,index) in buttonList"
              :key="index"
              :class="{buttonActive :activityIndex === index}"
              @click="_buttonChange(index)"
              type="primary"
            >
              {{ item }}
            </Button>
          </ButtonGroup>
        </div>
        <div class="clear" />
      </div>
      <div class="config_footer">
        <div>
          <span @click="toSendTask()" class="fl" style="color: #00b5ec;cursor: pointer;">{{ num }}</span>
          <div class="clear" />
        </div>
      </div>
    </Card>
  </div>
</template>

<script>
import Global from '../../../api/config'
import { meterSample } from '../../../api'
export default {
  data() {
    return {
      buttonList: ['本月', '本周', '今天'],
      activityIndex: 2, // 按钮0:本月  1：本周   2：当天
      type: 0,
      num: 0
    }
  },
  mounted() {
    if (Global.getLn()) {
      this._request()
    }
  },
  methods: {
    toSendTask() {
      this.$router.push('/meter/test/send_sample_input')
      // window.location.href = '/meter/test/send_sample_input'
    },
    _request: async function() {
      // type  请求 0:当天  1：本周   2：本月
      const result = await meterSample.testingCount({ type: this.type })
      if (result) {
        this.num = result
      }
    },
    _buttonChange(index) {
      this.activityIndex = index
      switch (index) {
        case 0:
          this.type = 2
          break
        case 1:
          this.type = 1
          break
        case 2:
          this.type = 0
          break
      }
      // this._request();
    }
  }
}
</script>
