<template>
<div>
<el-row class="query">
  <div class="query__operations">
    {{queryType}}
  </div>
  <div class="query__retrieve">
    <!-- <el-input
      v-model="query.quickCondition"
      placeholder="快捷查询（单据号）"
      @keyup.enter.native="e => toGetList(query)"
    ></el-input> -->
    <el-button v-auth="50310070102" class="query__item" type="primary" @click="moreQuery">更多</el-button>
    <el-button v-auth="50310070101" icon="el-icon-refresh" class="query__item" type="primary" @click="e => handelGetList(query)" plain circle></el-button>
    <el-button v-auth="50100030101" icon="el-icon-download" v-if="false" type="primary" @click="handleExcel" plain circle></el-button>

    <MoreQuery
      :queryProp="query"
      :showMore="showMore"
      @close="showMore = false"
      @toGetList="toGetList"
    ></MoreQuery>
  </div>
</el-row>
<div class="inputBox">
    <el-form inline :model="formData" ref="formData" label-position="left">
    <el-form-item
        label="交易类型"
        prop="tranType"
      >
      <el-select multiple v-model="tranType" @change="val => handleReasonCode(val)">
        <el-option
          v-for="item in $keys.inventoryQuery.transaction.tranType"
          :key="item.id"
          :label="item.name"
          :value="item.key"
        ></el-option>
      </el-select>
    </el-form-item>
     <el-form-item label="单据号" prop="orderNo">
        <el-input v-model="formData.orderNo"  @keyup.enter.native="toGetList(formData)"></el-input>
      </el-form-item>
      <el-form-item label="交易时间" class="date-item">
        <el-date-picker
          v-model="dateTime"
          type="datetimerange"
          :picker-options="pickerOptions"
          :default-time="['00:00:00', '23:59:59']"
          :clearable="false"
          format="yyyy-MM-dd HH:mm"
          value-format="yyyy-MM-dd HH:mm:ss"
          @change="dateTimeChange"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="货主" prop="fmToOwnerArr">
          <PublicQuery
            title="货主"
            cfgKey="invWmsCustomer"
            baseUrl="/inv_web/invweb"
            :valueField.sync="formData.fmToOwnerArr"
            @change="handelOwner">
          </PublicQuery>
      </el-form-item>
  </el-form>
</div>
</div>
</template>

<script>
import MoreQuery from './MoreQuery'
import * as shortcuts from '@/config/shortcuts'
export default {
  components: { MoreQuery },
  props: ['selectedIds', 'queryParams', 'queryType'],
  created () {
  },
  mounted () {
  },
  computed: {
    query () {
      return { ...this.queryParams } // 路由传递的查询条件, 默认 {}
    }
  },

  data () {
    return {
      pickerOptions: {
        shortcuts: { ...shortcuts } // element的shortcuts同时支持数组和对象格式
      },
      tranType: [],
      formData: {},
      dateTime: '',
      showMore: false, // 显示更多查询
      moreData: {}
    }
  },
  methods: {
    handleReasonCode (val) {
      this.formData.tranType = val.join(',')
      this.$emit('getList', this.formData)
    },
    handelGetList () {
      this.dateTime = ''
      this.tranType = []
      this.$refs.formData.resetFields()
      this.$emit('getList')
    },
    dateTimeChange (val) {
      this.formData.tranTimeFrom = val ? val[0] : ''
      this.formData.tranTimeTo = val ? val[1] : ''
      this.$emit('getList', this.formData)
    },
    handelOwner () {
      this.$emit('getList', this.formData)
    },
    // 检查是否有勾选
    checkSelections () {
      if (!this.selectedIds) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },
    // 查询
    toGetList (query = {}) {
      this.moreData = query
      this.$emit('getList', Object.assign({}, this.query, query))
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
    handleExcel () {
      const url = this.$API.inventoryQuery.blockLog.getList
      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 {
    &__operations {
      float: left;
    }
    &__retrieve {
      float: right;
      .el-input {
        max-width: 180px;
      }
    }
    &__item {
      margin-left: 10px;
    }
  }
</style>
