<template>
<el-dialog
  width="70%"
  class="more-query"
  title="高级查询"
  :visible="showMore"
  @close="close"
>
  <el-form
    inline
    label-position="top"
    :model="query"
    ref="queryForm"
  >
    <el-form-item label="物流单号" prop="logisticNo">
      <el-input v-model="query.logisticNo"></el-input>
    </el-form-item>
    <el-form-item label="出库单号" prop="soNo">
      <el-input v-model="query.soNo"></el-input>
    </el-form-item>
    <el-form-item label="出库单类型" prop="soType">
      <el-select multiple @change="soTypeChange" v-model="soTypeResults">
        <template v-for="item in $keys.stockOut.soType">
          <el-option :key="item.id" :value="item.key" :label="item.name"></el-option>
        </template>
      </el-select>
    </el-form-item>
    <el-form-item label="状态" prop="headerStatus">
      <el-select multiple @change="statusChange" v-model="statusResults">
        <template v-for="item in $keys.stockOut.status">
          <el-option :key="item.id" :value="item.key" :label="item.name"></el-option>
        </template>
      </el-select>
    </el-form-item>
    <el-form-item label="订单时间">
      <el-date-picker
        v-model="dateTime"
        type="datetimerange"
        :picker-options="pickerOptions"
        :default-time="['00:00:00', '23:59:59']"
        format="yyyy-MM-dd HH:mm"
        value-format="yyyy-MM-dd HH:mm:ss"
        @change="dateTimeChange"
      ></el-date-picker>
    </el-form-item>
  </el-form>
  <div class="more-query__btn">
    <el-button type="primary" @click="submitForm">查询</el-button>
    <el-button @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 () {
    this.setDefaultTime()
  },

  data () {
    return {
      query: { ...this.queryProp }, // 查询条件
      baseUrl: '/rep_web/repweb',
      dateTime: [],
      pickerOptions: {
        shortcuts: { ...shortcuts }
      },
      soTypeResults: [], // 出库单类型选择结果
      statusResults: [], // 状态选择结果
    }
  },
  methods: {
    setDefaultTime () {
      // 设置默认时间
      const startTime = new Date().getTime() - 29 * 24 * 60 * 60 * 1000
      this.dateTime = [ time.formatDate(new Date(startTime)) + ' 00:00:00', time.formatDate(new Date()) + ' 23:59:59' ]
      this.query.orderTimeFm = this.dateTime[0]
      this.query.orderTimeTo = this.dateTime[1]
    },
    // 关闭弹窗
    close () {
      this.$emit('close')
    },
    // 提交表单
    submitForm () {
      this.$emit('toGetList', this.query)
      this.close()
    },
    // 重置表单
    reset () {
      this.dateTime = []
      this.query.orderTimeFm = ''
      this.query.orderTimeTo = ''
      this.soTypeResults = []
      this.statusResults = []
      this.$refs.queryForm.resetFields()
    },
    // 时间变化
    dateTimeChange (val) {
      this.query.orderTimeFm = val ? val[0] : ''
      this.query.orderTimeTo = val ? val[1] : ''
    },
    soTypeChange (val) {
      this.query.soType = val.join(',')
    },
    statusChange (val) {
      this.query.status = val.join(',')
    }
  },
}
</script>

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