<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="asnNo">
      <el-input v-model="query.asnNo"></el-input>
    </el-form-item>
    <el-form-item label="入库单类型" prop="asnType">
      <el-select multiple v-model="asnTypeResults" @change="asnTypeChange">
        <template v-for="item in $keys.stockIn.asnType">
          <el-option :key="item.id" :value="item.key" :label="item.name"></el-option>
        </template>
      </el-select>
    </el-form-item>
    <el-form-item label="状态" prop="status">
      <el-select multiple v-model="statusResults" @change="statusChange">
        <el-option value="00" label="创建"></el-option>
        <el-option value="10" label="部分收货"></el-option>
      </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 }
      },
      asnTypeResults: [], // 入库单类型的多选value
      statusResults: [], // 状态的多选value
    }
  },
  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.fmOrderTime = this.dateTime[0]
      this.query.toOrderTime = this.dateTime[1]
    },
    // 关闭弹窗
    close () {
      this.$emit('close')
    },
    // 提交表单
    submitForm () {
      this.$emit('toGetList', this.query)
      this.close()
    },
    // 重置表单
    reset () {
      this.dateTime = []
      this.query.fmOrderTime = ''
      this.query.toOrderTime = ''
      this.asnTypeResults = []
      this.statusResults = []
      this.$refs.queryForm.resetFields()
    },
    // 时间变化
    dateTimeChange (val) {
      this.query.fmOrderTime = val ? val[0] : ''
      this.query.toOrderTime = val ? val[1] : ''
    },
    // 入库单多选变化
    asnTypeChange (val) {
      this.query.asnType = val.join(',')
    },
    // 入库单多选变化
    statusChange (val) {
      this.query.status = val.join(',')
    },
  },
}
</script>

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