<template>
  <section>
    <nav-bar :inner="true" title="扫码入库"></nav-bar>
    <section class="content mgt186">
      <div class="filter-wraper">
        <search-box
        label="备品备件"
        v-model="val1"
        @handleChange="handleChange1"
        ></search-box>
        <div class="bottom-filter-tip">
          <div class="filter-label txtjustify">入库单</div>
          <div class="fxcol mgl20">
            <input type="text" class="filter-input filter-scan-input" placeholder="" v-model="val2">
          </div>
        </div>
        <div class="bottom-filter-tip">
          <div class="filter-label txtjustify">物料</div>
          <div class="fxcol mgl20">
            <input type="text" class="filter-input filter-scan-input" placeholder="" v-model="val3">
          </div>
        </div>
        <div class="bottom-filter-tip">
          <div class="filter-label txtjustify">采购数量</div>
          <div class="fxcol mgl20">
            <input type="text" class="filter-input filter-scan-input" placeholder="" v-model="val4">
          </div>
        </div>
        <div class="bottom-filter-tip">
          <div class="filter-label txtjustify">入库数量</div>
          <div class="fxcol mgl20">
            <input type="text" class="filter-input filter-scan-input" placeholder="" v-model="val5">
          </div>
        </div>
      </div>
      <div class="grid-wraper">
        <div class="slide">
          <table class="layout-t">
            <tr>
              <th>备件唯一编码</th>
              <th>备件名称</th>
              <th>数量</th>
            </tr>
            <tr v-for="e in dataList" :key="e.maint_dtl_id" @click="toCheck(e)" :class="{'checked': e.maint_dtl_id === pkId}">
              <td>{{e.maint_item_name}}</td>
              <td>{{e.item_level}}</td>
              <td>{{e.contents}}</td>
            </tr>
          </table>
        </div>
      </div>
    </section>
    <section class="submit-bar">
      <button class="btn submit-button" :class="{'btn-disabled': dataList.length === 0}" :disabled="disabled1" @click="toSure1">删除</button>
      <button class="btn submit-button" :class="{'btn-disabled': dataList.length === 0}" :disabled="disabled2" @click="toSure2">确认</button>
    </section>
  </section>
</template>

<script>
import NavBar from '@components/NavBar.vue'
import SearchBox from '@components/SearchBox.vue'
import {queryMaintenanceDtl, dtlConfirm} from '@config/getData2.js'
export default {
  name: 'ScanInStore',
  components: {
    NavBar,
    SearchBox
  },
  data () {
    return {
      val1: '',
      val2: '',
      val3: '',
      val4: '',
      val5: '',
      dataList: [],
      pkId: '',
      pkObj: {},
      disabled1: false,
      disabled2: false
    }
  },
  methods: {
    handleChange1 (e, type) {
      if (type) {
        console.log(e)
      }
    },
    toCheck (e) {
      this.pkId = this.pkId === e.maint_dtl_id ? '' : e.maint_dtl_id
      this.pkObj = this.pkId === e.maint_dtl_id ? e : {}
    },
    /** 明细查询 */
    async _queryMaintenanceDtl () {
      let res = await queryMaintenanceDtl(this.$store.getters.materObj)
      if (res.code === '1') {
        this.dataList = [...res.content.rows]
      } else {
        this.Dialog(res.desc)
      }
    },
    async _dtlConfirm () {
      try {
        let res = await dtlConfirm(this.dataList)
        if (res.code === '1') {
          this.toast(res.desc)
        } else {
          this.Dialog(res.desc)
        }
        this.disabled1 = false
        this.disabled2 = false
      } catch (e) {
        this.disabled1 = false
        this.disabled2 = false
      }
    },
    toSure1 () {
      this.disabled1 = true
      if (!this.dataList.length) {
        this.disabled1 = false
        return
      }
      this._dtlConfirm()
    },
    toSure2 () {
      this.disabled2 = true
      if (!this.dataList.length) {
        this.disabled2 = false
        return
      }
      this._dtlConfirm()
    }
  }
}
</script>
