<template>
  <div class="header_table_top_warp">
    <div class="search_warp" :class="[open ? 'open' : 'close']">
      <el-form v-bind="$attrs" v-on="$listeners" :inline="true" ref="tableTopSearchForm" @submit.native.prevent>
        <slot></slot>
        <el-form-item class="flex_btn_warp" v-show="open">
          <div class="btn_warp" :style="{ marginBottom: open ? '24px' : '0px' }">
            <el-button type="primary" @click="search" :loading="btnLoading" v-if="showBtn">查询</el-button>
            <el-button @click="reset" v-if="showBtn">重置</el-button>
            <div @click="openBtn" class="open_close_btn">
              收起
              <i class="el-icon-arrow-up btn_icon rotateUp"></i>
            </div>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <div class="btn_warp" v-show="!open">
      <el-button type="primary" @click="search" :loading="btnLoading" v-if="showBtn">查询</el-button>
      <el-button @click="reset" v-if="showBtn">重置</el-button>
      <div @click="openBtn" class="open_close_btn">
        展开
        <i class="el-icon-arrow-up btn_icon rotateDown"></i>
      </div>
    </div>
  </div>
</template>

<script>
import EventBus from '../../utils/EventBus';
export default {
  name: 'FireflySearchBar',
  inheritAttrs: false,
  props: {
    form: {
      type: Object,
      default: () => {}
    },
    showBtn: {
      type: Boolean,
      default:false
    },
    customReset: {
      type: Boolean,
      default: false
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      open: false,
      btnLoading:this.loading
    };
  },
  watch: {
    loading: {
      handler(newVal) {
        this.btnLoading = newVal;
      },
      immediate: true,
      deep: true,
    },
  },
  methods: {
    //重置
    reset() {
      if(!this.customReset){
        this.$refs['tableTopSearchForm'].resetFields();
        this.search()
      }else{
        this.$emit('reset',this.$refs['tableTopSearchForm']);
      }
    },
    //查询
    search() {
      this.$emit('search',this.$refs['tableTopSearchForm']);
    },
    //展开收起
    openBtn() {
      this.open = !this.open;
      EventBus.$emit('ChangeOpen', this.open)
    }
  }
};
</script>

<style lang="scss" scoped>
@import '../../../css/fireflySearchBar.scss';
//针对对不起模块进行
:deep(.el-form--inline .el-form-item){
  margin-right: 44px;
  :deep(.el-input){
    width: 300px;
  }
}
:deep(.el-cascader-menu__wrap){
  width: 300px;
}
:deep(.el-form--inline .flex_btn_warp){
  margin-right: 0px;
}
:deep(.el-form-item__content){
  >.el-input,.el-select,.el-date-editor,.el-cascader{
    width: 300px;
  }
}
// :deep(.el-form-item__label){
//   text-align-last:justify;
//   text-align:justify;
//   &::after {
//   content: " ";
//   display: inline-block;
//   width: 100%;
// }
// }
</style>