<template>
  <el-row class="query">
    <div class="query__retrieve">
      <!-- <el-input
      v-model="query.quickCondition"
      placeholder="快捷查询（出库单号）"
      @keyup.enter.native="e => toGetList()"
      ></el-input>-->
      <el-row type="flex" justify="start">
        <el-col :span="21"></el-col>
        <el-col :span="3">
          <el-button v-auth="50920050102" class="query__item" type="primary" @click="moreQuery">更多</el-button>
          <el-button
            v-auth="50920050101"
            icon="el-icon-refresh"
            class="query__item"
            type="primary"
            @click="handleRefresh"
            plain
            circle
          ></el-button>
          <el-button
          v-if="false"
          icon="el-icon-download"
          type="primary"
          @click="handleExcel"
          plain
          circle
        ></el-button>
        </el-col>
      </el-row>

      <div class="inputBox">
        <el-form inline :model="query" ref="query" label-position="left">
          <el-form-item label="出库单号" prop="soNo">
            <el-input v-model="query.soNo" @keyup.enter.native="handleSearch"></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>

      <MoreQuery
        :queryProp="query"
        :showMore="showMore"
        @close="showMore = false"
        @toGetList="toGetList"
      ></MoreQuery>
    </div>
  </el-row>
</template>

<script>
import MoreQuery from './MoreQuery'
import * as shortcuts from '@/config/shortcuts'
export default {
  components: { MoreQuery },
  created () {
  },
  mounted () {
  },

  data () {
    return {
      query: {}, // 查询条件
      showMore: false, // 显示更多查询
      soTypeResults: [], // 类型的多选value
      statusResults: [], // 状态的多选value
      dateTime: [],
      pickerOptions: {
        shortcuts: { ...shortcuts }
      },
      moreData: {}
    }
  },
  methods: {
    // 时间变化
    dateTimeChange (val) {
      this.query.fmOrderTime = val ? val[0] : ''
      this.query.toOrderTime = val ? val[1] : ''
      this.handleSearch()
    },
    // 入库单多选变化
    soTypeChange (val) {
      this.query.asnType = val.join(',')
      this.handleSearch()
    },
    // 入库单多选变化
    statusChange (val) {
      this.query.status = val.join(',')
      this.handleSearch()
    },
    handleRefresh () {
      this.dateTime = []
      this.soTypeResults = []
      this.statusResults = []
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query, soNo: `%${this.query.soNo || ''}%` }
      this.moreData = query
      this.$emit('getList', query)
    },
    // 查询
    toGetList (query) {
      this.moreData = query
      this.$emit('getList', query)
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
    handleExcel () {
      const url = this.$API.summaryReport.noSpSoList
      const options = this.moreData
      this.$exportExcel(url, options)
    },
  },
}
</script>

<style lang="scss" scoped>
.inputBox {
  width: 100%;
  border: 1px solid #d1d5db;
  margin-top: 10px;
  margin-bottom: 10px;
  border-radius: 10px;
  padding-bottom: 10px;
  padding-left: 10px;
  .el-form-item {
    margin-bottom: 0px;
    margin-top: 10px;
  }
}

</style>
