<template>
<el-row class="query">
  <div class="query__retrieve">
    <!-- <el-input
      class="query__item"
      v-model="query.quickZoneCode"
      placeholder="快捷查询（库区编码）"
      @keyup.enter.native="e => toGetList()"
    ></el-input>
    <el-input
      class="query__item"
      v-model="query.quickLocCode"
      placeholder="快捷查询（库位编码）"
      @keyup.enter.native="e => toGetList()"
    ></el-input> -->
    <el-row type="flex" justify="start">
      <el-col :span="21"></el-col>
      <el-col :span="3">
        <el-button class="query__item" type="primary" @click="moreQuery">更多</el-button>
        <el-button icon="el-icon-refresh" class="query__item" type="primary" @click="handleRefresh" plain circle></el-button>
        <el-button
        v-if="false"
          icon="el-icon-download"
          type="primary"
          @click="handleExcel"
          plain
          circle
        ></el-button>
      </el-col>
    </el-row>

    <div class="inputBox">
        <el-form inline :model="query" ref="query" label-position="left">
          <!--公用查询框-->
        <template v-for="item in publicQueries">
          <el-form-item :key="item.valueField" :label="item.label" :prop="item.valueField">
            <PublicQuery
              single
              :title="item.label"
              :cfgKey="item.cfgKey"
              :baseUrl="baseUrl"
              :valueField.sync="query[item.valueField]"
              @change="handleSearch"
            ></PublicQuery>
          </el-form-item>
        </template>

        <!--选择框-->
        <template v-for="selector in selectors">
          <el-form-item
            :key="selector.prop"
            :label="selector.label"
            :prop="selector.prop"
          >
            <el-select multiple :value="selector.result" @change="val => selectChange(selector, val)">
              <el-option
                v-for="item in $keys.warehouseBasic[selector.keyName || selector.prop]"
                :key="item.id"
                :label="item.name"
                :value="item.key"
              ></el-option>
            </el-select>
          </el-form-item>
        </template>
        </el-form>
      </div>

    <MoreQuery
      :queryProp="query"
      :showMore="showMore"
      @close="showMore = false"
      @toGetList="toGetList"
    ></MoreQuery>
  </div>
</el-row>
</template>

<script>
import MoreQuery from './MoreQuery'
export default {
  components: { MoreQuery },
  created () {
  },
  mounted () {
  },

  data () {
    return {
      query: {}, // 查询条件
      showMore: false, // 显示更多查询
      baseUrl: '/rep_web/repweb',
      publicQueries: [
        { label: '区域', valueField: 'areaCode', cfgKey: 'repWmsArea', rowData: {} },
        { label: '库区', valueField: 'zoneCode', cfgKey: 'repWmsZone', rowData: {} },
      ],
      selectors: [
        { label: '库位类型', prop: 'locUseType', result: [] },
        { label: '库位种类', prop: 'category', keyName: 'cdwlCategory', result: [] }, // keyName为在keys中的字段名, 与本业务页面提交时的prop不一致时使用此属性
      ],
      moreData: {}
    }
  },
  methods: {

    handleRefresh () {
      for (const item of this.selectors) {
        item.result = []
      }
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query }
      this.moreData = query
      this.$emit('getList', query)
    },

    selectChange (selector, val) {
      const copy = [...val]
      this.$set(selector, 'result', val) // 深层修改页面渲染值对象
      Object.assign(this.query, { [selector.prop]: copy.join(',') }) // 以接口规定的传值格式合并query
      this.handleSearch()
    },
    // 查询
    toGetList (query = {}) {
      this.moreData = query
      this.$emit('getList', Object.assign({}, this.query, query))
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
    handleExcel () {
      const url = this.$API.summaryReport.emptyLocList
      const options = this.moreData
      this.$exportExcel(url, options)
    },
  },
}
</script>

<style lang="scss" scoped>
.inputBox {
  width: 100%;
  border: 1px solid #d1d5db;
  margin-top: 10px;
  margin-bottom: 10px;
  border-radius: 10px;
  padding-bottom: 10px;
  padding-left: 10px;
  .el-form-item {
    margin-bottom: 0px;
    margin-top: 10px;
  }
}
  // .query {
  //   &__retrieve {
  //     float: right;
  //     .el-input {
  //       max-width: 180px;
  //     }
  //   }
  //   &__item {
  //     margin-left: 10px;
  //   }
  // }
</style>
