<template>
<el-dialog
  width="70%"
  class="more-query"
  title="高级查询"
  :visible="showMore"
  @close="close"
>
  <el-form
    inline
    label-position="top"
    :model="query"
    ref="queryForm"
  >
    <!--公用查询框-->
    <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]"
          :textField.sync="item.textField === undefined ? false : query[item.textField]"
        ></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-item label="是否启用" prop="isEnables">
      <el-select multiple v-model="isEnablesResults" @change="isEnablesChange">
        <el-option value="Y" label="是"></el-option>
        <el-option value="N" 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]"></el-input>
      </el-form-item>
    </template>
  </el-form>
  <div class="more-query__btn">
    <el-button v-auth="50920110103" type="primary" @click="submitForm">查询</el-button>
    <el-button v-auth="50920110104" @click="reset">重置</el-button>
  </div>
</el-dialog>
</template>

<script>
import { time } from 'apec-fe-utils'
import * as shortcuts from '@/config/shortcuts'
export default {
  props: ['showMore', 'queryProp'],
  created () {
  },
  mounted () {
  },

  data () {
    return {
      query: { ...this.queryProp }, // 查询条件
      baseUrl: '/rep_web/repweb',
      publicQueries: [
        { label: '库区', valueField: 'zoneCode', textField: 'zoneName', cfgKey: 'repWmsZone', rowData: {} },
        { label: '库位编码', valueField: 'locCode', cfgKey: 'repWmsLoc', rowData: {} },
      ],
      selectors: [
        { label: '库位类型', prop: 'locUseTypes', keyName: 'locUseType', result: [] },
        { label: '库位种类', prop: 'categorys', keyName: 'cdwlCategory', result: [] }, // keyName为在keys中的字段名, 与本业务页面提交时的prop不一致时使用此属性
      ],
      inputs: [
        { label: '最大托盘数', prop: 'maxPl' },
        { label: '占用托盘数', prop: 'traceCount' },
        { label: '剩余托盘数', prop: 'traceRemainNum' },
      ],
      isEnablesResults: [], // 是否启用选择结果
    }
  },
  methods: {
    // 关闭弹窗
    close () {
      this.$emit('close')
    },
    // 提交表单
    submitForm () {
      this.$emit('toGetList', this.query)
      this.close()
    },
    // 重置表单
    reset () {
      this.dateTime = []
      this.query.tranTimeFrom = ''
      this.query.tranTimeTo = ''
      this.query.zoneName = ''
      this.isEnablesResults = []
      for (const item of this.selectors) {
        item.result = []
      }
      this.$refs.queryForm.resetFields()
    },
    // 多选变化
    selectChange (selector, val) {
      const copy = [...val]
      this.$set(selector, 'result', val) // 深层修改页面渲染值对象
      Object.assign(this.query, { [selector.prop]: copy.join(',') }) // 以接口规定的传值格式合并query
    },
    // 是否启用变化
    isEnablesChange (val) {
      this.query.isEnables = val.join(',')
    }
  },
}
</script>

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