<template>
  <div>
    <div class="headForm">
      <div class="flex-box query-box" v-if="title" style="margin-bottom: 12px;">
        <div class="flex-box query-params">
          <span class="common-title" v-if="title">{{ title }}</span>
        </div>
      </div>
      <div class="flex-box query-box" v-if="formData.length > 0">
        <div class="flex-box query-params">
          <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="form.width?'width:'+form.width+'px':'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" :disabled="item.disabled"/>
                </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" :id="'focus'+i">
                  <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:200px'">
                    <i slot="prefix" class="el-input__icon"><img src="@/assets/images/project/sousuo.png" width="16px" @click="changeSelect"></i>
                  </el-input>
                </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="form.width?'width:'+form.width+'px':'max-width: 150px'"
                  :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
                  :timeList="form.timeList"
                  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
                  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-hasPermi="['combine:info:export:win:bid','combine:info:export:bid']" v-if="isExcel" @click="clickEXCEL"><img src="@/assets/images/ability_excel.png">导出EXCEL</span>
          <span class="flex-box ability-excel" v-else @click="clickEXCEL"><img src="@/assets/images/ability_excel.png">导出EXCEL</span>
        </div>
      </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 {

    }
  },
  created() {

  },
  components: {
    CustomTimeSelect,
    CustomMoneySelect
  },
  methods: {
    changeSelect(){
      this.$emit('handle-search')
    },
    clickEXCEL() {
      if(this.title==='集团业绩'){
        this.$emit('handle-excel')
      }else {
        this.$message({
          message: '功能正在开发中',
          type: 'warning'
        });
      }
    },
    clickFocus(e){
      document.getElementById(e).classList.toggle('span-ba')
    }
  }
}
</script>
<style lang="scss">
  .el-popper[x-placement^=bottom] {
    margin-top: 5px !important;
  }
</style>
<style lang="scss" scoped>
  ::v-deep .el-popper[x-placement^=bottom] {
    margin-top: 5px;
  }
.headForm{
  margin-bottom: 14px;
  .common-title{
    margin-right: 24px;
  }
  ::v-deep .el-input__inner{
    border: 0;
    height: 32px;
    line-height: 32px;
    /*padding-right: 27px;*/
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 4px;
    padding: 0 8px;
  }
  ::v-deep .el-form-item{
    margin-right: 8px !important;
  }
  ::v-deep .el-input--medium .el-input__icon{
    line-height: 34px;
  }
  ::v-deep .el-cascader{
    height: 34px;
    line-height: 34px;
    width: 150px;
    .is-focus{
      .el-input{
        input{
          background: #F4F6F9;
        }
      }
    }
    .el-input{
      input{
        height: 34px !important;
      }
    }
    .el-cascader__tags{
      flex-wrap: inherit;
      margin-top: 1px;
      .el-tag{
        max-width: 70px;
      }
      .el-tag:nth-child(2){
        padding: 0 3px;
      }
    }
    .el-input__suffix{
      top: 1px;
    }
  }
  .headForm-from {
    display: flex;
    .from-item{
      margin-right: 8px;
      &:last-child{
       margin-right: 0;
      }
      .cooperate-name {
        display: flex;
        border-radius: 4px;
        border: 0;
        line-height: 32px;
        height: 32px;
        width: 238px;
        .el-input__icon{
          >img{
            position: absolute;
            top: 7px;
            left: 5px;
          }
        }
        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{
          border-color: #0081FF;
          span{
            color: #ffffff;
            background: #0081FF;
            border: 1px solid #0081FF;
          }
        }
        ::v-deep .el-input{
          width: 100%;
        }
        ::v-deep .el-input__inner {
          border: 0;
          line-height: 32px;
          height: 32px;
          position: absolute;
          top: 0;
          padding-left: 36px;
          padding-right: 25px;
        }
      }
      .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;
      }
      .el-select{
        .el-input__suffix{
          right: 10px;
        }
      }
    }
    ::v-deep .form-content-width{
      width: 150px;
      .el_input{
        background: #fff;
      }
      .el-input__inner{
        border-color: #fff;
        padding:5px 28px 5px 8px;
        border-radius: 4px !important;
      }
      .el-input__suffix{
        height: 32px;
        .el-input__icon{
          line-height: 32px;
        }
      }
      .is-focus{
        .el-input__inner{
          background: #F4F6F9;
        }
      }
    }
    ::v-deep .selectTag{
      .el-select__tags{
        .el-tag{
          &:first-child{
            width: 70px;
          }
        }
      }
    }
    ::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>
