<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="组合件类型"
              prop="kitType">
              <el-select v-model="formData.kitType">
                <el-option label="组合加工(A=B+C)" value="COM"></el-option>
                <el-option label="辅料加工(A=A+辅料)" value="ACC"></el-option>
                <el-option label="增值加工(A=A)" value="VA"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="状态"
              prop="status">
              <el-select multiple v-model="formData.status">
                <el-option label="创建" value="00"></el-option>
                <el-option label="部分加工" value="70"></el-option>
                <el-option label="完全加工" value="80"></el-option>
                <el-option label="取消订单" value="90"></el-option>
                <el-option label="关闭订单" value="99"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="审核状态"
              prop="auditStatus">
              <el-select multiple v-model="formData.auditStatus">
                <el-option label="未审核" value="00"></el-option>
                <el-option label="不审核" value="90"></el-option>
                <el-option label="已审核" value="99"></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="logisticNo">
              <el-input v-model="formData.logisticNo"></el-input>
            </el-form-item>
            <el-form-item
              label="计划加工台"
              prop="kitLoc">
              <PublicQuery
              title="计划加工台"
              baseUrl="/kit_web/kitweb"
              cfgKey="kitWmsCustomer"
              :valueField.sync="formData.kitLoc">
              </PublicQuery>
            </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 v-auth="50300030101" type="primary" @click="submitForm">查询</el-button>
            <el-button v-auth="50300030101" @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: ''
    }
  },
  mounted () {
  },
  props: {
    moreQueryVisible: Boolean
  },
  methods: {
    // 获得时间
    getSTime (val) {
      this.formData.createTimeFm = val[0]
      this.formData.createTimeTo = 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>
