<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 clearable @clear="changeSelect" @focus="clickFocus('focus'+i)" @blur="clickFocus('focus'+i)" v-model="form.value" :placeholder="form.placeholder" :style="form.width?'width:'+form.width+'px':'width:180px'"></el-input>
                <span :id="'focus'+i" @click="changeSelect">搜索</span>
              </div>
            </template>
            <!-- 多选 -->
            <template  v-if="form.type==4">
              <el-select
                class="form-content-width"
                :class="form.value.length > 1 ? 'selectTag' : ''"
                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>
            <!-- 时间、自定义 -->
            <template v-else-if="form.type==5">
              <custom-time-select
                v-model="form.value"
                :placeholder="form.placeholder"
                :dateFrom="form.dateFrom ? form.dateFrom : ''"
                :dateTo="form.dateTo ? form.dateTo : ''"
                @handle-search="changeSelect" />
            </template>
            <!-- 金额 -->
            <template v-else-if="form.type==6">
              <custom-money-select
                :moneyList="form.moneyList"
                v-model="form.value"
                :placeholder="form.placeholder"
                @handle-search="changeSelect" />
            </template>
            <!-- 地区选择 -->
            <template v-else-if="form.type==7">
              <el-cascader
                ref="cascader"
                :options="form.options"
                :props="form.props"
                v-model="form.value"
                @change="changeSelect"
                :placeholder="form.placeholder"
                collapse-tags
                style="margin-top: -1px;"
                clearable></el-cascader>
            </template>
            <!-- 自定义 -->
            <template  v-if="form.type==0">
              <slot name="slot"></slot>
            </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>
import CustomTimeSelect from './CustomTimeSelect'
import CustomMoneySelect from './CustomMoneySelect'
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 {

    }
  },
  components: {
    CustomTimeSelect,
    CustomMoneySelect
  },
  methods: {
    changeSelect(){
      this.$emit('handle-search')
    },
    clickEXCEL() {
      this.$message({
        message: '功能正在开发中',
        type: 'warning'
      });
    },
    clickFocus(e){
      document.getElementById(e).classList.toggle('span-ba')
    }
  }
}
</script>

<style lang="scss" scoped>
.headForm{
  margin-bottom: 14px;
  .common-title{
    margin-right: 19px;
  }
  ::v-deep .el-input__inner{
    border: 1px solid #D9D9D9;
    height: 32px;
    line-height: 32px;
    padding-right: 27px;
  }
  ::v-deep .el-form-item{
    margin-right: 8px !important;
  }
  ::v-deep .el-input--medium .el-input__icon{
    line-height: 32px;
  }
  ::v-deep .el-cascader{
    height: 32px;
    line-height: 32px;
    .el-input{
      input{
        height: 32px !important;
      }
    }
    .el-cascader__tags{
      flex-wrap: inherit;
      margin-top: 1px;
      .el-tag{
        max-width: 120px;
      }
    }
  }
  .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;
        }
        .span-ba{
          color: #ffffff;
          background: #0081FF;
          border: 1px solid #0081FF;
        }
        ::v-deep .el-input{
          flex: 1;
        }
        ::v-deep .el-input__inner {
          border-radius: 2px 0 2px 0;
          border: 1px solid #D9D9D9;
          border-right: 0;
        }
      }
      .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;
    }
    ::v-deep .selectTag{
      .el-select__tags{
        .el-tag{
          &:first-child{
            width: 90px;
          }
        }
      }
    }
    ::v-deep .el-select__tags{
      .el-tag{
        &:first-child{
          //width: 100%;
        }
      }
    }
  }
  .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;
    &:hover{
      color: #0081FF;
    }
    img{
      width: 18px;
      height: 18px;
      margin-right: 4px;
    }
  }
}
</style>
