<template>
  <div class="headForm">
    <div class="flex-box query-box">
      <div class="flex-box query-params" :class="flag?'box1':''">
        <div class="flex-box headForm-text">
          <template v-if="flag">
            <img v-if="title" src="@/assets/images/detail/ico_title.png" />
            <span class="drawer-title" v-if="title">{{ title }}</span>
          </template>
          <template v-if="slots">
            <slot name="slot"></slot>
          </template>
          <div  v-if="flag">
            <span class="ability-total" v-if="isTotal">{{ total }}条数据</span>
            <span class="ability-total" v-if="amountTotal">，共计合作总金额：<i>{{ amountTotal }}</i>万元</span>
          </div>
        </div>
        <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" :id="'detailFocus'+i">
                <el-input clearable @clear="changeSelect" @focus="clickFocus('detailFocus'+i)" @blur="clickFocus('detailFocus'+i)" v-model="form.value" :placeholder="form.placeholder" :style="form.width?'width:'+form.width+'px':'width:180px'"></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>
            <!-- 金额 -->
            <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-if="form.type==0">
              <slot name="slot"></slot>
            </template>

          </div>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CustomMoneySelect from './CustomMoneySelect'
export default {
  name: "HeadDetailForm",
  components: {
    CustomMoneySelect
  },
  props: {
    title: {
      type: String,
      default: ''
    },
    flag: {
      type: Boolean,
      default: false
    },
    queryParams: {
      type: Object,
      default: {}
    },
    formData: {
      type: Array,
      default: []
    },
    isTotal: {
      type: Boolean,
      default: true
    },
    total: {
      type: Number,
      default: 0
    },
    amountTotal: {
      type: Number,
      default: 0
    },
    slots: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {

    }
  },
  methods: {
    changeSelect(){
      this.$emit('handle-search')
    },
    clickFocus(e){
      document.getElementById(e).classList.toggle('span-ba')
    }
  }
}
</script>

<style lang="scss" scoped>
.headForm{
  .query-params{
    width: 100%;
    padding: 8px 17px 8px 0;
  }
  .box1{
    padding: 8px 17px 8px 13px;
    justify-content: space-between;
    border-bottom: 1px solid #E1E1E1;
  }
  ::v-deep .el-input__inner{
    border: 0;
    height: 32px;
    line-height: 32px;
  }
  ::v-deep .el-select .el-input__inner{
    border: 1px solid #D9D9D9;
    height: 34px;
    line-height: 34px;
    padding-right: 27px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 4px;
  }
  ::v-deep .custom-money-select{
    .el-input__inner{
      border: 1px solid #D9D9D9;
      
    }
  }
  ::v-deep .el-form-item{
    margin-right: 8px !important;
  }
  ::v-deep .el-input--medium .el-input__icon{
    line-height: 32px;
  }
  .headForm-text{
    .drawer-title{
      font-size: 16px;
      color: #232323;
      font-weight: bold;
      margin-right: 4px;
    }
    img{
      width: 17px;
      height: 17px;
      margin-right: 8px;
    }
    .ability-total{
      font-size: 12px;
      color: rgba(35,35,35,0.8);
      position: relative;
      i{
        color: #FF3C3C;
      }
    }
  }
  .headForm-from {
    display: flex;
    .from-item{
      margin-right: 8px;
      &:last-child{
       margin-right: 0;
      }
      .cooperate-name {
        display: flex;
        border-radius: 2px 0px 0px 2px;
        border: 1px solid #D9D9D9;
        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: 1px solid #0081FF;
          span{
            color: #ffffff;
            background: #0081FF;
            border: 1px solid #0081FF;
          }
        }
        ::v-deep .el-input{
          flex: 1;
        }
        ::v-deep .el-input__inner {
          border-right: 0;
          border-radius: 2px 0 2px 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%;
        }
      }
    }
  }
}
</style>
