<template>
  <div>
    <div class="mrg-b">
      <el-row>
        <el-col :span="21">
          <el-button v-auth="50700010110" type="primary" @click="handleAdd">新增</el-button>
          <el-button v-auth="50700010108" type="primary" @click="handleDeleteRows">删除</el-button>
        </el-col>
        <el-col :span="3">
          <el-col :span="24" >
            <el-button v-auth="50700010102" type="primary" @click="handleMoreSearch">更多</el-button>
            <el-button
              v-auth="50700010101"
              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-col>
      </el-row>
    </div>
    <div class="inputBox">
      <el-form inline :model="query" ref="query" label-position="left">
        <el-form-item label="月台编码" prop="dockCode">
          <el-input v-model="query.dockCode"  @keyup.enter.native="handleSearch"></el-input>
        </el-form-item>
        <el-form-item label="月台名称" prop="dockName">
          <el-input v-model="query.dockName"  @keyup.enter.native="handleSearch"></el-input>
        </el-form-item>
        <el-form-item label="使用类型" prop="dockUseType">
          <el-select multiple v-model="dockUseType" @change="handleType1">
            <el-option label="装" value="LOAD"></el-option>
            <el-option label="卸" value="UNLOAD"></el-option>
            <el-option label="装+卸" value="LU"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="使用车型" prop="vehicleType">
          <el-select multiple v-model="vehicleType" @change="handleType2">
            <el-option label="牵引车" value="TR"></el-option>
            <el-option label="大型车辆" value="VE"></el-option>
            <el-option label="小型车辆" value="HI"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <more-query
      :moreQueryVisible="moreQueryVisible"
      @close="moreQueryVisible=false"
      @toGetList="getQueryList"
    ></more-query>
  </div>
</template>
<script>
import { today, yesterday, week, month, twoMonths, threeMonths } from '@/config/shortcuts'
import MoreQuery from './more-query'
export default {
  components: {
    MoreQuery
  },
  data () {
    return {
      query: {},
      moreQueryVisible: false,
      dockUseType: [],
      vehicleType: [],
      moreData: {}
    }
  },
  props: {
    selectedIds: Array
  },
  methods: {

    // 检查是否选中行
    checkSelections () {
      if (!this.selectedIds.length) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },

    handleType1 (val) {
      this.query.dockUseType = val.join(',')
      this.handleSearch()
    },
    handleType2 (val) {
      this.query.vehicleType = val.join(',')
      this.handleSearch()
    },

    handleRefresh () {
      this.dockUseType = []
      this.vehicleType = []
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query, dockCode: `%${this.query.dockCode || ''}%`, dockName: `%${this.query.dockName || ''}%` }
      this.moreData = query
      this.$emit('getList', query)
    },

    // 更多查询数据
    getQueryList (query) {
      this.moreQueryVisible = false
      this.moreData = query
      this.$emit('getList', query)
    },

    // 更多搜索查询
    handleMoreSearch () {
      this.moreQueryVisible = true
    },

    // 新增
    handleAdd () {
      this.$emit('handleOpenForm', 'create')
    },

    // 保存成功
    saveOK () {
      this.$emit('getList')
    },

    // 删除
    handleDeleteRows () {
      const url = this.$API.platform.DockBasicdataList.delList
      const dockCodes = JSON.stringify(this.selectedIds)
      const param = { dockCodes }

      if (!this.checkSelections()) return
      this.$confirm(`您已选中${this.selectedIds.length}条数据,是否删除？`, '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$emit('getList')
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleExcel () {
      const url = this.$API.platform.DockBasicdataList.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;
  }
}
.mrg-b {
  margin-bottom: 20px;
}
.mrg-l {
  margin-left: 10px;
}
.query {
  &__operations {
    float: left;
  }
  &__retrieve {
    float: right;
    .el-input {
      max-width: 180px;
    }
  }
  &__item {
    margin-left: 10px;
  }
}
</style>
