<template>
<el-row class="query">
  <el-row>
    <el-col :span="21">
      <el-button type="primary" @click="toAdd">新增</el-button>
    <el-button type="primary" @click="handleDel" needconfirm>删除</el-button>
    </el-col>
    <el-col :span="3">
      <el-button class="query__item" type="primary" @click="moreQuery">更多</el-button>
     <el-button icon="el-icon-refresh" class="query__item" type="primary" @click="handleRefresh" plain circle></el-button>
     <el-button v-auth="50100030101" icon="el-icon-download" v-if="false" 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="vehicleNo">
        <el-input v-model="query.vehicleNo" @keyup.enter.native="handleSearch" placeholder="快捷查询(车牌号)"></el-input>
      </el-form-item>
      <el-form-item label="车辆类型" prop="businessType">
        <el-select multiple v-model="businessType" @change="selectChange">
        <el-option
          v-for="item in $keys.warehouseBasic.vehicle.businessType"
          :key="item.id"
          :label="item.name"
          :value="item.key"
        ></el-option>
      </el-select>
      </el-form-item>
      <el-form-item label="驾驶员" prop="driver">
        <el-input v-model="query.driver" @keyup.enter.native="handleSearch" ></el-input>
      </el-form-item>
      <el-form-item label="车型" prop="vehicleType">
        <el-input v-model="query.vehicleType" @keyup.enter.native="handleSearch" ></el-input>
      </el-form-item>
    </el-form>
  </div>
    <MoreQuery
      :showMore="showMore"
      @close="showMore = false"
      @toGetList="getQueryList"
    ></MoreQuery>

</el-row>
</template>

<script>
import MoreQuery from './MoreQuery'
export default {
  components: { MoreQuery },
  props: ['selectedIds', 'queryParams'],
  created () {
  },
  mounted () {
  },

  data () {
    return {
      showMore: false, // 显示更多查询
      query: {}, // 查询条件
      businessType: [],
      moreData: {}
    }
  },
  methods: {
    // 检查是否有勾选
    checkSelections () {
      if (!this.selectedIds) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },
    toAdd () {
      this.$emit('toShowCreator')
    },
    handleDel () {
      const url = this.$API.warehouseBasic.vehicle.delete
      const param = {
        vehicleNos: JSON.stringify(this.selectedIds)
      }
      this.$https.post(url, param).then(res => {
        this.$emit('getList')
      })
    },
    // 对当前列表进行批量操作, 更多按钮也在这里
    operateConfirm (type) {
      const url = this.$API.warehouseBasic.vehicle[type]
      const param = {
        vehicleNos: JSON.stringify(this.selectedIds)
      }
      this.$https.post(url, param)
        .then(data => {
          console.log('操作成功', data)

          this.toGetList()
        })
    },
    selectChange (val) {
      this.query.businessType = val.join(',')
      this.handleSearch()
    },
    handleRefresh () {
      this.businessType = []
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query, vehicleNo: `%${this.query.vehicleNo || ''}%` }
      this.$emit('getList', query)
    },
    // 更多查询数据
    getQueryList (query) {
      this.showMore = false
      this.moreData = query
      this.$emit('getList', query)
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
    handleExcel () {
      const url = this.$API.warehouseBasic.vehicle.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>
