<template>
  <div class="app-container">
    <el-card class="box-card" shadow="always">
      <div :style="classCardbody">
        <div v-if="searchExecuting">
          <el-row>
            <el-col :span="12" :offset="6">
              <el-input placeholder="请输入内容" v-model="keyword">
                <el-select v-model="type" slot="prepend" placeholder="请选择" style="width: 100px;">
                  <el-option label="数据库" value="1"></el-option>
                  <el-option label="数据表" value="2"></el-option>
                  <el-option label="数据元" value="3"></el-option>
                </el-select>
                <el-button slot="append" :disabled="btnEnable" icon="el-icon-search"></el-button>
              </el-input>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              6
            </el-col>
            <el-col :span="18">
              18
            </el-col>
          </el-row>
        </div>
        <div v-else>
          <div class="search-container">
            <el-input placeholder="请输入内容" v-model="keyword">
              <el-select v-model="type" slot="prepend" placeholder="请选择" style="width: 100px;">
                <el-option label="数据库" value="1"></el-option>
                <el-option label="数据表" value="2"></el-option>
                <el-option label="数据元" value="3"></el-option>
              </el-select>
              <el-button slot="append" icon="el-icon-search" :disabled="btnEnable" @click="search"></el-button>
            </el-input>
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'DataSearch',
  data () {
    return {
      classCardbody: {
        overflow: 'auto',
        height: document.body.offsetHeight - 170 + 'px'
      },
      searchExecuting: false,
      type: '',
      keyword: '',
      btnEnable: true
    }
  },
  methods: {
    search () {
      this.searchExecuting = true
    }
  },
  computed: {
    listenChange () {
      const { type, keyword } = this
      return { type, keyword }
    }
  },
  watch: {
    listenChange (val) {
      if (val.type && val.keyword) {
        this.btnEnable = false
      } else {
        this.btnEnable = true
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.search-container {
  min-height: 100%;
  width: 100%;
  text-align: center;
  margin-top: 15%;
  .el-input {
    position: relative;
    width: 520px;
    max-width: 100%;
    margin: 0 auto;
  }
}
</style>
