<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="22"></el-col>
      <el-col :span="2">
        <el-button v-auth="50920060102" class="query__item" type="primary" @click="moreQuery">更多</el-button>
        <el-button v-auth="50920060101" 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="owner">
            <PublicQuery
              title="货主"
              cfgKey="repWmsCustomer"
              baseUrl="/rep_web/repweb"
              :valueField.sync="query.owner"
              @change="handleSearch"
            ></PublicQuery>
          </el-form-item>
          <el-form-item label="商品" prop="sku">
            <PublicQuery
              title="商品"
              cfgKey="repWmsSku"
              baseUrl="/rep_web/repweb"
              :valueField.sync="query.sku"
               @change="handleSearch"
            ></PublicQuery>
          </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, // 显示更多查询
      dateTime: [],
      pickerOptions: {
        shortcuts: { ...shortcuts }
      },
      moreData: {}
    }
  },
  methods: {

    // 时间变化
    dateTimeChange (val) {
      this.query.tranTimeFrom = val ? val[0] : ''
      this.query.tranTimeTo = val ? val[1] : ''
      this.handleSearch()
    },
    handleRefresh () {
      this.dateTime = []
      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.rotationRateList
      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;
  }
}
  // .query {
  //   &__retrieve {
  //     float: right;
  //     .el-input {
  //       max-width: 180px;
  //     }
  //   }
  //   &__item {
  //     margin-left: 10px;
  //   }
  // }
</style>
