<template>
  <div class="main-container">
    <div class="con1">
      <button v-if="dataInfo.button_name" @click="clickSave">{{dataInfo.button_name}}</button>
    </div>
    <div class="con2">
      <div class="infoli">
        <img src="../../../images/aio/icon2.png">
        <span class="title">设备信息：</span>
        <span class="txt">{{dataInfo.device_info}}</span>
      </div>
      <div class="infoli">
        <img src="../../../images/aio/icon5.png">
        <span class="title">当前任务：</span>
        <span class="txt">{{dataInfo.task_name}}</span>
      </div>
      <div class="infoli">
        <img src="../../../images/aio/icon5.png">
        <span class="title">任务状态：</span>
        <span class="txt">{{dataInfo.task_status}}</span>
      </div>
      <div class="infoli">
        <img src="../../../images/aio/icon5.png">
        <span class="title">任务数量：</span>
        <span class="txt">{{dataInfo.task_num}}</span>
      </div>
      <div class="infoli">
        <img src="../../../images/aio/icon6.png">
        <span class="title">当前速度：</span>
        <span class="txt">{{dataInfo.speed}}</span>
      </div>
      <div class="infoli">
        <img src="../../../images/aio/icon4.png">
        <span class="title">AGV故障：</span>
        <span class="txt">{{dataInfo.error_name}}</span>
      </div>
    </div>
  </div>
</template>

<script>
import {queryHomePage, clickSave} from '@/config/getData.js'
import NavBar from '@components/NavBar.vue'
export default {
  name: 'Home',
  components: {
    NavBar
  },
  data () {
    return {
      interTime: this.$store.getters.setTime,
      timer: null,
      dataInfo: {}
    }
  },
  created () {
    this.initData()
    this.refresh()
  },
  beforeDestroy () {
    clearInterval(this.timer)
  },
  methods: {
    refresh () {
      this.timer = setInterval(() => {
        this.initData()
      }, this.interTime)
    },
    async initData () {
      let res = await queryHomePage()
      if (res.code === '1') {
        this.dataInfo = res.result
      } else {
        this.toast(res.desc)
      }
    },
    async clickSave () {
      if (!this.dataInfo.button_name) {
        return
      }
      let res = await clickSave(this.dataInfo.button_code)
      if (res.code === '1') {
        this.toast(res.desc)
        this.initData()
      } else {
        this.toast(res.desc)
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~@style/mixin'
.bgred
  background #fa6400
.bggreen
  background #54C0B3
.cred
  color #fa6400
.cgreen
  color #54C0B3
.con0
  height 1rem
  margin-top .26rem
  margin-bottom .5rem
  margin-left .4rem
.site_nav
  _wh(2rem,1rem)
  _bis('../../../images/aio/btn_dis.png',100%,100%)
  margin-bottom .2rem
  margin-right .3rem
  &:nth-of-type(3)
    margin-right 1.8rem
.site_nav_a
  display block
  _font(.32rem,1rem,,,center)
  cursor pointer
  color #ffffff
.active
  _bis('../../../images/aio/btn_checked.png',100%,100%)
.white
  color #464646
.con1
  float left
  position relative
  width 4.5rem
  height 4.5rem
  // background center / 100% 100% url(../../../images/aio/car2.png) no-repeat
  background center / 100% 100% url(../../../images/aio/AGV223.gif) no-repeat
  margin-left .95rem
  margin-right .95rem
  margin-top 1.1rem
  button
    box-sizing border-box
    border 8px solid #F1F1F5
    border-radius 16px
    font-size .3rem
    background #ffffff
    padding 0.2rem
    font-size 24px
.con2
  float left
  width 4.8rem
  height 4.5rem
  background center / 100% 100% url(../../../images/aio/bg2.png) no-repeat
  padding-top .2rem
  margin-top 1.1rem
  .infoli
    width 4.5rem
    line-height 0.65rem
    height 0.65rem
    background #ffffff
    margin 0 auto
    // margin-bottom 2px
    border-bottom 1px dotted #cccccc
    img
      float left
      margin .22rem .15rem 0 .31rem
      width .22rem
      height .22rem
    .title
      float left
      display inline-block
      font-size .2rem
      color #323232
    .txt
      float left
      display inline-block
      font-size .2rem
      color #FA6400
</style>
