<template>
  <div class="container">
    <div class="btn">
      <Button type="primary" @click="closeDoor">关门</Button>
    </div>
    <div class="store">{{ getStoreTitle(plcCode, door) }}</div>
    <div class="title">{{ time }}</div>
    <div class="sub-title">请选择您要进行的操作</div>
    <div class="menu">
      <div class="item" @click="go(0)">
        <img :src="inPic" alt="">
        <span class="label green">入库</span>
      </div>
      <div class="item" @click="go(1)">
        <img :src="outPic" alt="">
        <span class="label blue">出库</span>
      </div>
      <div class="item" @click="go(2)">
        <img :src="stock" alt="">
        <span class="label other">调仓</span>
      </div>
    </div>
  </div>
</template>

<script>
import inPic from '_static/images/in.png'
import outPic from '_static/images/out.png'
import stock from '_static/images/stock.png'
import {SendInOutState,OpenOrCloseStorageDoor } from "@/api/integrated";
import { getStoreTitle } from '@/libs/util'
import store from "@/store";
export default {
  name: "Home",
  data() {
    return {
      getStoreTitle,
      inPic,
      outPic,
      stock,
      time: null,
      timer: null,
      plcCode: 1,
      door: 1
    }
  },
  methods: {
    closeDoor() {
      OpenOrCloseStorageDoor({
        token: '_token',
        plcCode: sessionStorage.getItem('plcCode'),
        e_OpenOrCloseDoor: 0
      }).then(res => {
        if (res.code === 0) {
          this.$Message.info(res.msg || '操作成功！')
        }
      })
    },
    go(type) {
      if (!this.plcCode) {
        return this.$Message.error('缺少仓库参数')
      }
      if (!this.door) {
        return this.$Message.error('缺少仓库门参数')
      }
      if (type == 0) {
        SendInOutState({
          inOutType: type, token: '_token',
          storageType: sessionStorage.getItem('plcCode'),
          storageDoor: sessionStorage.getItem('door')
        })
      } else if (type == 1 || type == 2) {
        SendInOutState({
          inOutType: 1, token: '_token',
          storageType: sessionStorage.getItem('plcCode'),
          storageDoor: sessionStorage.getItem('door')
        })
      }
      if (this.$store.state.token) {
        if (type == 0) {
          this.$router.replace({
            name: 'store-in'
          })
        } else if (type == 1) {
          this.$router.replace({
            name: 'store-out-list'
          })
        } else if (type == 2) {
          this.$router.replace({
            name: 'store-change'
          })
        }
      } else {
        this.$router.push({
          name: 'login',
          query: {
            type
          }
        })
      }
    }
  },
  mounted() {
    this.$store.commit('setHasGetInfo', false)
    this.plcCode = this.$route.query.plcCode // 仓库名
    this.door = this.$route.query.door // 仓库门
    this.title = getStoreTitle(this.plcCode, this.door)
    sessionStorage.setItem('plcCode', this.plcCode)
    sessionStorage.setItem('door', this.door)
    this.time = this.$dayjs().format('HH:mm:ss')
    this.timer = setInterval(() => {
      this.time = this.$dayjs().format('HH:mm:ss')
    }, 1000)
  },
  destroyed() {
    clearInterval(this.timer)
  }
}
</script>
<style lang="scss" scoped>
.container{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  min-width: 500px;
  min-height: 400px;
  //background-color: rgba(1, 84, 120, 0.8);
  background-image: linear-gradient(270deg,
      #2c3034 0%,
      #50575e 49%,
      #2c3034 100%);
  .title {
    font-size: 4vw;
    font-weight: bold;
    color: #fff;
  }
  .sub-title {
    padding-bottom: 20px;
    font-size: 2vw;
    font-weight: bold;
    color: #fff;
  }
  .menu {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      margin-right: 3vw;
      width: 15vw;
      height: 20vw;
      min-width: 190px;
      min-height: 250px;
      background-color: #ffffff;
      border-radius: 10px;
      cursor: pointer;
      &:last-child {
        margin-right: 0;
      }
      img {
        width: 60%;
      }
      .label {
        padding-top: 30px;
        font-size: 2vw;
        font-weight: bold;
        &.green {
          color: #4B7902;
        }
        &.blue {
          color: #000080;
        }
        &.other {
          color: #8bde06;
        }
      }
    }
  }
}
.btn {
  position: fixed;
  top: 20px;
  right: 20px;
}
.store {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  height: 32px;
  line-height: 32px;
  font-size: 32px;
  font-weight: bold;
  color: #FFFFFF;
}
</style>
