<template>
  <div class="headForm">
    <div class="flex-box query-box">
      <div class="flex-box query-params">
        <span class="common-title" v-if="title">{{ title }}</span>
        <div class="headForm-from">
          <div class="from-item" :key="i" v-for="(form, i) in formData">
            <!-- 单选 -->
            <template v-if="form.type==1">
                <el-select
                  v-model="form.value"
                  clearable
                  class="form-content-width"
                  style="max-width: 110px"
                  :placeholder="form.placeholder"
                  @change="changeSelect">
                  <el-option v-for="(item, index) in form.options" :key="index" :label="item.name" :value="item.value" />
                </el-select>
            </template>
            <!-- 年月日 -->
            <template v-if="form.type==2">
              <el-date-picker
                @change="changeSelect"
                class="fromTime"
                style="width: 210px"
                v-model="form.value"
                type="daterange"
                prefix-icon="fromTime-icon"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始月份"
                end-placeholder="结束月份">
              </el-date-picker>
            </template>
            <!-- 输入框 -->
            <template v-if="form.type==3">
              <div class="cooperate-name">
                <el-input v-model="form.value" :placeholder="form.placeholder"></el-input>
                <span @click="changeSelect">搜索</span>
              </div>
            </template>
            <!-- 多选 -->
            <template  v-if="form.type==4">
              <el-select
                class="form-content-width"
                v-model="form.value"
                multiple
                collapse-tags
                clearable
                style="max-width: 170px"
                :placeholder="form.placeholder"
                @change="changeSelect">
                <el-option v-for="(item, index) in form.options" :key="index" :label="item.name" :value="item.value" />
              </el-select>
            </template>

          </div>

        </div>
      </div>
      <template v-if="slots">
        <slot name="slot"></slot>
      </template>
      <div v-else class="flex-box">
        <span class="flex-box ability-total" v-if="isTotal">共{{ total }}条</span>
        <span class="flex-box ability-excel" v-if="isExcel" @click="clickEXCEL"><img src="@/assets/images/ability_excel.png">导出EXCEL</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "HeadForm",
  props: {
    title: {
      type: String,
      default: ''
    },
    queryParams: {
      type: Object,
      default: {}
    },
    formData: {
      type: Array,
      default: []
    },
    isTotal: {
      type: Boolean,
      default: true
    },
    total: {
      type: Number,
      default: 0
    },
    isExcel: {
      type: Boolean,
      default: false
    },
    slots: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {

    }
  },
  methods: {
    changeSelect(){
      console.log(this.formData)
      this.$emit('handle-search')
    },
    clickEXCEL() {
      this.$message({
        message: '功能正在开发中',
        type: 'warning'
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.headForm{
  margin-bottom: 14px;
  .common-title{
    margin-right: 19px;
  }
  ::v-deep .el-input__inner{
    border: 1px solid #EFEFEF;
    height: 32px;
    line-height: 32px;
  }
  ::v-deep .el-form-item{
    margin-right: 8px !important;
  }
  ::v-deep .el-input--medium .el-input__icon{
    line-height: 32px;
  }
  .headForm-from {
    display: flex;
    .from-item{
      margin-right: 8px;
      &:last-child{
       margin-right: 0;
      }
      .cooperate-name {
        display: flex;
        span {
          width: 60px;
          height: 32px;
          line-height: 32px;
          font-size: 14px;
          background: #F5F5F5;
          text-align: center;
          color: #0081FF;
          border: 1px solid #EFEFEF;
          border-left: 0;
          cursor: pointer;
        }
        ::v-deep .el-input{
          flex: 1;
        }
        ::v-deep .el-input__inner {
          border-right: 0;
          border-radius: 2px 0 2px 0;
          width: 259px;
        }
      }
      .fromTime{
        ::v-deep .el-range-input{
          width: 100%;
        }
        ::v-deep .el-range-separator, ::v-deep .el-range__close-icon{
          line-height: 24px;
          width: 20px;
        }
      }
      .fromTime-icon {
        display: none;
      }
    }
    ::v-deep .form-content-width{
      width: 170px;
    }
  }
  .ability-total{
    font-size: 12px;
    color: #3D3D3D;
    position: relative;
    &:before{
      content: '';
      display: inline-block;
      width: 2px;
      height: 2px;
      background: rgba(35,35,35,0.4);
      margin-right: 4px;
    }
  }
  .ability-excel{
    font-size: 14px;
    color: rgba(35,35,35,0.8);
    margin-left: 16px;
    cursor: pointer;
    img{
      width: 18px;
      height: 18px;
      margin-right: 4px;
    }
  }
}
</style>
