<template>
<el-dialog
  class="more-query"
  title="高级查询"
  width="70%"
  :visible="showMore"
  @close="close"
>
  <el-form
    inline
    label-position="top"
    :model="query"
    ref="queryForm"
  >
    <template v-if="type === 'queryInvLotLocId'">
      <el-form-item label="商品 (模糊查询)" prop="likeSku">
        <el-input v-model="query.likeSku"></el-input>
      </el-form-item>
    </template>
    <!--公用查询框-->
    <template v-for="item in publicQueries">
      <el-form-item v-if="!item.showByType || item.showByType.includes(type)" :key="item.cfgKey" :label="item.label" :prop="item.valueField">
        <PublicQuery
          :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="item in datePickers">
      <el-form-item :key="item.prop" :label="item.label" :prop="item.prop">
        <el-date-picker
          v-model="query[item.prop]"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        ></el-date-picker>
      </el-form-item>
    </template>

    <!--筛选框-->
    <template v-for="selector in selectors">
      <el-form-item
        v-if="!selector.showByType || selector.showByType.includes(type)"
        :key="selector.prop"
        :label="selector.label"
        :prop="selector.prop"
      >
        <el-select v-model="query[selector.prop]">
          <el-option
            v-for="item in $keys.inventoryQuery.queryByTerms[selector.prop]"
            :key="item.id"
            :label="item.name"
            :value="item.key"
          ></el-option>
        </el-select>
      </el-form-item>
    </template>

    <!--输入框-->
    <template v-for="item in inputs">
      <el-form-item
        v-if="!item.showByType || item.showByType.includes(type)"
        :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="50310100103" type="primary" @click="submitForm">查询</el-button>
    <el-button v-auth="50310100104" @click="resetForm('queryForm')">重置</el-button>
  </div>
</el-dialog>
</template>

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

  data () {
    return {
      baseUrl: '/inv_web/invweb', // 多条件基础URL
      inputs: [
        { label: '批次号', prop: 'lotNum' },
        { label: '跟踪号', prop: 'traceId', showByType: 'queryInvLotLocId' },
        { label: '批次属性05', prop: 'LOT_ATT05' },
        { label: '批次属性06', prop: 'LOT_ATT06' },
        { label: '批次属性07', prop: 'LOT_ATT07' },
        { label: '批次属性08', prop: 'LOT_ATT08' },
        { label: '批次属性09', prop: 'LOT_ATT09' },
        { label: '批次属性10', prop: 'LOT_ATT10' },
        { label: '批次属性11', prop: 'LOT_ATT11' },
        { label: '批次属性12', prop: 'LOT_ATT12' },
      ],
      selectors: [
        { label: '品质', prop: 'LOT_ATT04', result: [] },
        { label: '商品温层', prop: 'tempLevel', result: [], showByType: 'queryInvLotLocId' },
      ],
      publicQueries: [
        { label: '货主', valueField: 'ownerCode', cfgKey: 'invWmsCustomer' },
        { label: '商品', valueField: 'skuCode', cfgKey: 'invWmsSku' },
        { label: '库位', valueField: 'locCode', cfgKey: 'invWmsLoc', showByType: 'queryInvLotLocId' },
        { label: '库区', valueField: 'zoneCode', cfgKey: 'invWmsZone', showByType: 'queryInvLotLocId' },
        { label: '区域', valueField: 'areaCode', cfgKey: 'invWmsArea', showByType: 'queryInvLotLocId' },
        { label: '商品组', valueField: 'groupCode', textField: 'ebmgNameCn', cfgKey: 'bdWmsMaterialGroup', showByType: 'queryInvLotLocId' },
      ],
      datePickers: [
        { label: '生产日期', prop: 'LOT_ATT01' },
        { label: '失效日期', prop: 'LOT_ATT02' },
        { label: '入库日期', prop: 'LOT_ATT03' },
      ],
    }
  },
  methods: {
    // 关闭弹窗
    close () {
      this.$emit('close')
    },
    // 提交表单
    submitForm () {
      this.$emit('toGetList', this.query)
      this.close()
    },
    // 重置表单
    resetForm (formName) {
      for (const item of this.selectors) {
        // 因选择框是另外操作的逻辑, 单独重置选择框
        item.result = []
      }
      this.$refs[formName].resetFields()
    },
  },
}
</script>

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