<template>
    <div class="order-wraper">
        <div class="search-confirm-wrap">
            <div class="search-wrap">
                <div class="search-item">
                    <div class="search-label">车间</div>
                    <div class="filter_input_wraper">
                        <el-select v-model="value1" filterable clearable placeholder="请选择">
                          <el-option
                              v-for="item in options1"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                          </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="search-item">
                    <div class="search-label">设备</div>
                    <div class="filter_input_wraper">
                        <el-select v-model="value2" filterable clearable placeholder="请选择">
                            <el-option
                              v-for="item in options2"
                              :key="item.device_code"
                              :label="item.device_name"
                              :value="item.device_code">
                          </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="search-item">
                    <div class="search-label">数量</div>
                    <div class="filter_input_wraper">
                        <input type="number" class="filter-input" v-model="qty">
                    </div>
                </div>
                <div class="search-item_3">
                    <button class="button button--primary" :disabled="disabled1" :class="{'button--defalut': qty === '' || value2 === ''}" @click="toSure">人工倒料</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {pourDictList, pourDeviceList, pourdeviceinstorQty} from '@config/getData2.js'
export default {
  data () {
    return {
      options1: [],
      value1: '',
      options2: [],
      value2: '',
      qty: '',
      disabled1: false
    }
  },
  created () {
    this._pourDeviceList()
    this._pourDictList()
  },
  methods: {
    // 设备下拉框
    async _pourDeviceList () {
      let res = await pourDeviceList()
      this.options2 = [...res.data]
    },
    // 车间下拉框
    async _pourDictList () {
      let res = await pourDictList('product_area')
      this.options1 = [...res.data]
    },
    // 确认入库
    async toSure () {
      this.disabled1 = true
      if (this.qty === '' || this.value2 === '') {
        this.disabled1 = false
        return
      }
      try {
        let res = await pourdeviceinstorQty(this.qty, this.value2)
        this.toast(res.message)
        this.value1 = ''
        this.qty = ''
        this.value2 = ''
        this.disabled1 = false
      } catch (e) {
        this.disabled1 = false
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
</style>
