<template>
<el-row class="query">
  <div class="query__retrieve">
    <!-- <el-input
      class="query__item"
      v-model="query.zoneCode"
      placeholder="快捷查询（库区编码）"
      @keyup.enter.native="e => toGetList()"
    ></el-input>
    <el-input
      class="query__item"
      v-model="query.locCode"
      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 v-auth="50920110102" class="query__item" type="primary" @click="moreQuery">更多</el-button>
        <el-button v-auth="50920110101" 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>
        <el-form-item label="库容状态">
          <el-select
          class="query__item"
          multiple
          placeholder="库容状态"
          v-model="invCapStatusResults"
          @change="invCapStatusChange"
        >
          <el-option value="PL_PART" label="库容未满"></el-option>
          <el-option value="PL_FULL" label="库容已满"></el-option>
        </el-select>
        </el-form-item>
         <!--输入框-->
    <template v-for="item in inputs">
      <el-form-item :key="item.prop" :label="item.label" :prop="item.prop">
        <el-input v-model="query[item.prop]" @keyup.enter.native="handleSearch"></el-input>
      </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, // 显示更多查询
      invCapStatusResults: [], // 库容状态选择结果, 默认库容未满状态
      baseUrl: '/rep_web/repweb',
      publicQueries: [
        { label: '库区', valueField: 'zoneCode', textField: 'zoneName', cfgKey: 'repWmsZone', rowData: {} },
        { label: '库位编码', valueField: 'locCode', cfgKey: 'repWmsLoc', rowData: {} },
      ],
      inputs: [
        { label: '剩余托盘数', prop: 'traceRemainNum' },
      ],
      moreData: {}
    }
  },
  methods: {
    handleRefresh () {
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query, traceRemainNum: `%${this.query.traceRemainNum || ''}%` }
      this.moreData = query
      this.$emit('getList', query)
    },
    // 查询
    toGetList (query = {}) {
      this.$emit('getList', Object.assign({}, this.query, query))
      this.moreData = query
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
    // 库容状态变化
    invCapStatusChange (val) {
      this.query.invCapStatuss = val.join(',')
      this.handleSearch()
    },
    handleExcel () {
      const url = this.$API.summaryReport.capacityList
      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>
