<template>
  <div class="box relative">
    <t-header title2="浙江恒森实业集团WMS系统">
      <el-select class="header_select" v-model="value" placeholder="请选择" @change="change">
        <el-option
          v-for="item in options"
          :key="item.code"
          :label="item.name"
          :value="item.code">
        </el-option>
      </el-select>
    </t-header>
    <div class="box body_container">
      <div v-if="itemData.length >= 1" class="relative n_wraper">
        <div class="absolute bg_j bg_j_1"></div>
        <div class="absolute bg_j bg_j_2"></div>
        <div class="absolute bg_j bg_j_3"></div>
        <div class="absolute bg_j bg_j_4"></div>
        <div class="relative title_wraper">
          <p class="relative title_h1">装配一车间</p>
          <p class="absolute title_h2">当前任务&nbsp;-&nbsp;<span style="color: #00b678;font-weight: 700;">{{ itemData[0].task_code }}</span></p>
        </div>
        <div class="zd-row content_wraper">
          <div class="zd-col-18">
            <div class="zd-row flexwrap item_wraper">
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">库内料箱:</div>
                  <div class="item_value">{{ itemData[0].vehicle_code }}<span class="item_unit"></span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">物料名称:</div>
                  <div class="item_value">{{ itemData[0].material_name }}<span class="item_unit"></span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">物料规格:</div>
                  <div class="item_value">{{ itemData[0].material_spec }}<span class="item_unit"></span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">物料数量:</div>
                  <div class="item_value">{{ itemData[0].qty }}<span class="item_unit">个</span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">箱内剩余数量:</div>
                  <div class="item_value">{{ itemData[0].remaining_qty }}<span class="item_unit">个</span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">拣选称重:</div>
                  <div class="item_value">{{ itemData[0].actual_weight }}<span class="item_unit">g</span></div>
                </div>
              </div>
              <div class="info_item_1">
                <div class="zd-row info_item_1_i">
                  <div class="zd-col-16">
                    <div class="item_label_1">拣选数量</div>
                    <div class="item_value_1">{{ itemData[0].assign_qty }}<span class="item_unit">个</span></div>
                  </div>
                  <div class="zd-col-8 info_icon"></div>
                </div>
              </div>
              <div class="info_item_1">
                <div class="zd-row info_item_1_i">
                  <div class="zd-col-16">
                    <div class="item_label_1">理论数量</div>
                    <div class="item_value_1">{{ itemData[0].theory_qty }}<span class="item_unit">个</span></div>
                  </div>
                  <div class="zd-col-8 info_icon info_icon_2"></div>
                </div>
              </div>
            </div>
          </div>
          <div class="zd-col-6 height-100">
            <div class="info_item info_item_2">
              <div class="box zd-row jccenter info_item_i">
                <div class="item_label">单重:</div>
                <input type="number" class="item_value_input" v-model="itemData[0].single_weight" @keyup.enter="changeWeight"  @blur="changeWeight">
                <div class="item_unit">g</div>
              </div>
            </div>
            <div class="tip_wraper" :class="itemData[0].assign_qty === itemData[0].theory_qty ? 'tip_wraper_bg1' : 'tip_wraper_bg2'">
            <div class="tip_txt">料箱{{ itemData[0].vehicle_code }}<br/>{{itemData[0].assign_qty === itemData[0].theory_qty ? '拣选成功！' : '称重错误！'}}</div>
          </div>
          </div>
        </div>
      </div>
      <div v-if="itemData.length >= 2" class="relative n_wraper">
        <div class="absolute bg_j bg_j_1"></div>
        <div class="absolute bg_j bg_j_2"></div>
        <div class="absolute bg_j bg_j_3"></div>
        <div class="absolute bg_j bg_j_4"></div>
        <div class="relative title_wraper">
          <p class="relative title_h1">装配二车间</p>
          <p class="absolute title_h2">下一任务&nbsp;-&nbsp;<span style="color: #00b678;font-weight: 700;">{{ itemData[1].task_code }}</span></p>
        </div>
        <div class="zd-row content_wraper">
          <div class="zd-col-24">
            <div class="zd-row flexwrap item_wraper">
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">料箱号</div>
                  <div class="item_value">{{ itemData[1].vehicle_code }}<span class="item_unit"></span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">物料名称</div>
                  <div class="item_value">{{ itemData[1].material_name }}<span class="item_unit"></span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">物料规格</div>
                  <div class="item_value">{{ itemData[1].material_spec }}<span class="item_unit"></span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">物料数量</div>
                  <div class="item_value">{{ itemData[1].qty }}<span class="item_unit">个</span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">拣选数量</div>
                  <div class="item_value">{{ itemData[1].assign_qty }}<span class="item_unit">个</span></div>
                </div>
              </div>
              <div class="info_item">
                <div class="box zd-row jccenter info_item_i">
                  <div class="item_label">单重</div>
                  <div class="item_value">{{ itemData[1].single_weight }}<span class="item_unit">g</span></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-if="itemData.length === 0" class="zd-row jccenter wraning">当前拣选工位无拣选作业</div>
    </div>
  </div>
</template>

<script>
import THeader from '@components/header.vue'
import { queryPickingPoint, pickingInfo, updateMaterialInfo } from '@js/getData2.js'
export default {
  components: {
    THeader
  },
  data () {
    return {
      interTime: this.$store.getters.setJxtTime,
      timer: null,
      options: [],
      value: '',
      itemData: []
    }
  },
  created () {
    this._queryPickingPoint()
  },
  beforeDestroy () {
    if (this.timer !== null) {
      clearInterval(this.timer)
    }
  },
  methods: {
    refresh () {
      this._pickingInfo()
      this.timer = setInterval(() => {
        this._pickingInfo()
      }, this.interTime)
    },
    async _pickingInfo () {
      let res = await pickingInfo(this.value)
      this.itemData = [...res]
    },
    async _queryPickingPoint () {
      let res = await queryPickingPoint()
      this.options = [...res]
      if (res.length > 0) {
        this.value = res[0].code
        this.refresh()
      }
    },
    change (e) {
      if (e) {
        if (this.timer !== null) {
          clearInterval(this.timer)
        }
        this.refresh()
      }
    },
    changeWeight (event) {
      this._updateMaterialInfo(event.target.value)
    },
    async _updateMaterialInfo (e) {
      let id = this.itemData.length > 0 ? this.itemData[0].material_id : ''
      let res = await updateMaterialInfo(id, e)
      if (res.code === '200') {
        this.$message({
          message: '操作成功',
          type: 'success'
        })
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
@import './style.stylus'
.wraning
  height 100%
  font-size 50px;
  color: yellow;
  font-weight: 700;
  text-align: center;
</style>
