<template>
  <section>
    <nav-bar title="送空托盘"></nav-bar>
    <section class="content mgt186">
      <div class="filter-wraper">
        <div class="bottom-filter-tip">
          <div class="filter-label txtjustify">区域</div>
          <div class="fxcol mgl20 visible" >
            <dropdown-menu
            :option="option1"
            :active="active1"
            :open="open1"
            @toggleItem="toggleItem1"
            @dropdownMenu="dropdownMenu1">
            </dropdown-menu>
          </div>
        </div>
        <div class="bottom-filter-tip">
          <div class="filter-label txtjustify">点位</div>
          <div class="fxcol mgl20 visible" >
            <dropdown-menu
            :option="option2"
            :active="active2"
            :open="open2"
            @toggleItem="toggleItem2"
            @dropdownMenu="dropdownMenu2">
            </dropdown-menu>
          </div>
        </div>
        <search-box
        label="托盘"
        v-model="val1"
        :seaShow="false"
        ></search-box>
      </div>
    </section>
    <section class="submit-bar">
      <button class="btn submit-button" :class="{'btn-disabled' : val1 === '' || active1 === '' || active2 === ''}" :disabled="disabled1" @click="_sendEmptyconfirm">确定</button>
      <button class="btn submit-button" @click="toCancle">取消</button>
    </section>
  </section>
</template>

<script>
import NavBar from '@components/NavBar.vue'
import DropdownMenu from '@components/DropdownMenu.vue'
import SearchBox from '@components/SearchBox.vue'
import {sendEmptyqueryArea, sendEmptyqueryPointByArea, sendEmptyconfirm} from '@config/getData1'
export default {
  name: 'SendEmptyPallet',
  components: {
    NavBar,
    DropdownMenu,
    SearchBox
  },
  data () {
    return {
      val1: '',
      option1: [],
      active1: '',
      open1: false,
      option2: [],
      active2: '',
      open2: false,
      disabled1: false
    }
  },
  created () {
    this._sendEmptyqueryArea()
  },
  methods: {
    /** 查询区域 */
    async _sendEmptyqueryArea () {
      let res = await sendEmptyqueryArea()
      if (res.code === '1') {
        this.option1 = [...res.result]
        this.option1.map(el => {
          this.$set(el, 'value', el.area_code)
          this.$set(el, 'label', el.area_name)
        })
      } else {
        this.Dialog(res.desc)
      }
    },
    /** 查询点位 */
    async _sendEmptyqueryPointByArea (a) {
      let res = await sendEmptyqueryPointByArea(a)
      if (res.code === '1') {
        this.option2 = [...res.result]
        this.option2.map(el => {
          this.$set(el, 'value', el.point_id)
          this.$set(el, 'label', el.point_name)
        })
      } else {
        this.Dialog(res.desc)
      }
    },
    /** 确认 */
    async _sendEmptyconfirm () {
      this.disabled1 = true
      if (this.val1 === '' || this.active1 === '') {
        this.disabled1 = false
        return
      }
      try {
        let res = await sendEmptyconfirm(this.option2[this.active2].point_id, this.option2[this.active2].point_code, this.option2[this.active2].point_name, this.val1)
        if (res.code === '1') {
          this.toast(res.desc)
          this.toCancle()
        } else {
          this.Dialog(res.desc)
        }
        this.disabled1 = false
      } catch (e) {
        this.disabled1 = false
      }
    },
    /** 取消 */
    toCancle () {
      this.val1 = ''
      this.active1 = ''
      this.active2 = ''
      this.disabled1 = false
    },
    toggleItem1 () {
      if (!this.open1) {
        this.open1 = true
      } else {
        this.open1 = false
      }
    },
    dropdownMenu1 (i) {
      this.active1 = i + ''
      this.open1 = false
      this._sendEmptyqueryPointByArea(this.option1[this.active1].area_code)
    },
    toggleItem2 () {
      if (!this.open2) {
        this.open2 = true
      } else {
        this.open2 = false
      }
    },
    dropdownMenu2 (i) {
      this.active2 = i + ''
      this.open2 = false
    }
  }
}
</script>
