<template>
  <section>
    <nav-bar title="备件出库"></nav-bar>
    <section class="content mgt186">
      <div class="grid-wraper">
        <div class="left_fixed">
          <table class="layout-t left_layout_t">
            <tr>
            <th>出库单号</th>
            </tr>
            <tr v-for="e in dataList" :key="e.iostorinvdtl_id" @click="toCheck(e)" :class="{'checked': e.iostorinvdtl_id === pkId}">
              <td>{{e.bill_code}}</td>
            </tr>
          </table>
        </div>
        <div class="slide">
          <table class="layout-t">
            <tr>
              <th>物料编码</th>
              <th>物料名称</th>
              <th>数量</th>
              <th>已出数</th>
              <th>单位</th>
              <th>关联设备</th>
            </tr>
            <tr v-for="e in dataList" :key="e.iostorinvdtl_id" @click="toCheck(e)" :class="{'checked': e.iostorinvdtl_id === pkId}">
              <td>{{e.material_code}}</td>
              <td>{{e.material_name}}</td>
              <td>{{e.plan_qty}}</td>
              <td>{{e.finish_qty}}</td>
              <td>{{e.qty_unit_name}}</td>
              <td>{{e.device_code}}</td>
            </tr>
          </table>
        </div>
      </div>
    </section>
    <section class="submit-bar">
      <button class="btn submit-button" :class="{'btn-disabled': !pkId}" @click="scaninstore">扫码出库</button>
    </section>
  </section>
</template>

<script>
import NavBar from '@components/NavBar.vue'
import { queryIODtl } from '@config/getData1.js'
export default {
  name: 'SparePartOutstore',
  components: {
    NavBar
  },
  data () {
    return {
      dataList: [],
      pkId: '',
      pkObj: {}
    }
  },
  beforeRouteLeave (to, from, next) {
    if (to.path === '/home' || to.path === '/login') {
      this.$store.dispatch('setKeepAlive', [])
    }
    next()
  },
  created () {
    this._queryIODtl()
  },
  activated () {
    this._queryIODtl()
  },
  methods: {
    /** 1.1出入库单查询 */
    async _queryIODtl () {
      let res = await queryIODtl('1')
      if (res.code === '1') {
        this.dataList = [...res.content.rows]
      } else {
        this.Dialog(res.desc)
      }
    },
    toCheck (e) {
      this.pkId = this.pkId === e.iostorinvdtl_id ? '' : e.iostorinvdtl_id
      this.pkObj = this.pkId === e.iostorinvdtl_id ? e : {}
    },
    scaninstore () {
      if (this.pkId) {
        this.$store.dispatch('materObj', this.pkObj)
        this.$router.push({
          path: '/ScanOutStore'
        })
      }
    }
  }
}
</script>
