<template>
  <div>
    <el-dialog title="高级查询" :visible="moreQueryVisible" @close="close" width="66%">
      <el-form inline ref="queryForm" label-position="top" :model="formData">
        <el-form-item label="加工单号" prop="kitNo">
          <el-input v-model="formData.kitNo"></el-input>
        </el-form-item>
        <el-form-item label="加工任务ID" prop="kitTaskId">
          <el-input v-model="formData.kitTaskId"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select multiple v-model="formData.status">
            <el-option label="完全分配" value="40"></el-option>
            <el-option label="完全拣货" value="60"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="货主编码" prop="ownerCode">
          <PublicQuery
            title="货主编码"
            baseUrl="/kit_web/kitweb"
            cfgKey="kitWmsCustomer"
            :valueField.sync="formData.ownerCode"
            :textField.sync="formData.ownerName"
          ></PublicQuery>
        </el-form-item>
        <el-form-item label="父件" prop="parentSkuCode">
          <PublicQuery
            title="父件"
            baseUrl="/kit_web/kitweb"
            cfgKey="kitWmsKitParentSkuName"
            :valueField.sync="formData.parentSkuCode"
          ></PublicQuery>
        </el-form-item>
        <el-form-item label="子拣" prop="subSkuCode">
          <PublicQuery
            title="子拣"
            baseUrl="/kit_web/kitweb"
            cfgKey="kitWmsSkuName"
            :valueField.sync="formData.subSkuCode"
          ></PublicQuery>
        </el-form-item>
        <el-form-item label="批次号" prop="lotNum">
          <el-input v-model="formData.lotNum"></el-input>
        </el-form-item>
        <el-form-item label="源库位" prop="locCode">
          <PublicQuery
            title="源库位"
            baseUrl="/kit_web/kitweb"
            cfgKey="kitWmsLoc"
            :valueField.sync="formData.locCode"
          ></PublicQuery>
        </el-form-item>
        <el-form-item label="源跟踪号" prop="traceId">
          <el-input v-model="formData.traceId"></el-input>
        </el-form-item>
        <el-form-item label="目标库位" prop="toLoc">
          <PublicQuery
            title="目标库位"
            baseUrl="/kit_web/kitweb"
            cfgKey="kitWmsLoc"
            :valueField.sync="formData.toLoc"
          ></PublicQuery>
        </el-form-item>
        <el-form-item label="目标跟踪号" prop="toId">
          <el-input v-model="formData.toId"></el-input>
        </el-form-item>
        <el-form-item label="拣货人" prop="pickOp">
          <PublicQuery
            title="拣货人"
            baseUrl="/kit_web/kitweb"
            cfgKey="kitWmsOperator"
            :valueField.sync="formData.pickOp"
          ></PublicQuery>
        </el-form-item>
        <el-form-item label="拣货时间">
          <el-date-picker
            v-model="date2"
            type="datetimerange"
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions2"
            @change="getTime2"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="订单时间">
          <el-date-picker
            v-model="date"
            type="datetimerange"
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions2"
            @change="getSTime"
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <div class="more-query-btn">
        <el-button  type="primary" @click="submitForm">查询</el-button>
        <el-button  @click="resetForm('queryForm')">重置</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { time } from 'apec-fe-utils'
import { today, yesterday, week, month, twoMonths, threeMonths } from '@/config/shortcuts'
export default {
  data () {
    return {
      formData: {
        kitType: [],
        status: [],
        auditStatus: [],
        createTimeFm: time.formatTime(new Date(new Date() - 3600 * 1000 * 24 * 7)),
        createTimeTo: time.formatTime(new Date()),
      },
      pickerOptions2: {
        shortcuts: [today, yesterday, week, month, twoMonths, threeMonths]
      },
      date: '',
      date2: ''
    }
  },
  mounted () {
  },
  props: {
    moreQueryVisible: Boolean
  },
  methods: {
    // 获得时间
    getSTime (val) {
      this.formData.createTimeFm = val[0]
      this.formData.createTimeTo = val[1]
    },
    getTime2 (val) {
      this.formData.pickTimeFm = val[0]
      this.formData.pickTimeTo = val[1]
    },

    // 关闭弹窗
    close () {
      this.$emit('close')
    },

    // 提交表单
    submitForm () {
      this.format()
      this.$emit('toGetList', this.formData)
      this.$refs['queryForm'].resetFields()
    },

    // 重置表单
    resetForm () {
      this.$refs['queryForm'].resetFields()
    },

    // 格式化对象数据
    format () {
      for (const key in this.formData) {
        if (this.formData.hasOwnProperty(key)) {
          const element = this.formData[key]
          if (Array.isArray(element)) {
            this.formData[key] = element.join(',')
          }
        }
      }
      return this.formData
    }
  }
}
</script>
