<template>
  <div class="searchForm" @keypress="keypress">
    <div class="labelBox">


      <div class="label" v-if="keys.includes('key')">
        <span class="name">关键词：</span>
        <el-input v-model="form.key" placeholder="请输入" size="small" class="input"></el-input>
      </div>



      <div class="label" v-if="keys.includes('activity')">
        <span class="name">活动主题：</span>
        <el-select v-model="form.activityId" placeholder="请选择"  :clearable="true" class="input" size="small" style="width: 240px;">
          <el-option v-for="item in activityOption" :key="item.id" :value="item.id" :label="item.title"></el-option>

        </el-select>
      </div>

      <div class="label" v-if="keys.includes('type')">
        <span class="name">类型：</span>
        <el-select v-model="form.type" placeholder="请选择"  :clearable="true" class="input" size="small" style="width: 240px;">
          <el-option value="1" label="公告"></el-option>
          <el-option value="2" label="消息"></el-option>

        </el-select>
      </div>


      <div class="label" v-if="keys.includes('state')">
        <span class="name">状态：</span>
        <el-select v-model="form.state" placeholder="请选择"  :clearable="true" class="input" size="small" style="width: 240px;">
          <el-option value="1" label="审核"></el-option>
          <el-option value="2" label="未审核"></el-option>

        </el-select>
      </div>

      <div class="label" v-if="keys.includes('optime')">
        <span class="name">投票时间：</span>
        <el-date-picker
            size="small"
            v-model="time1"
            type="daterange"
            range-separator="至"
            value-format="timestamp"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
      </div>



      <div class="btn-box">
        <el-button type="primary" icon="el-icon-search" size="small" @click="$emit('on-search')">查询</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="reset">重置</el-button>
      </div>
    </div>
    <div class="btn-box">
      <slot></slot>
    </div>
  </div>

</template>

<script>
let defaultForm = {
  key:"",
  activityId:"",
  type:'1',
  state:'1'
}
export default {
  name: "searchForm",
  props: {
    keys: {
      default: () => []
    }
  },
  data() {
    return {
      form: {
        ...defaultForm
      },
      time1: [],
      dictValueOption: [],
      roleOption: [],
      shopOption: [],
      countryOption:[],
      activityOption:[]

    }
  },
  mounted() {

    if(this.keys.includes("activity")){
      this.getActivitys()
    }

  },
  methods: {
    getActivitys(){

      this.$api.voteList({
        key:'',
        pageNum:1,
        pageCapacity: 1000,
      }).then(res => {

        console.log(res)
        this.activityOption = res.content.voteActivityViewDtos;



      })
    },
    getCountryDict(){
      this.$api.countryDict().then(res => {
        console.log(res)
        this.countryOption = res.data;
      })
    },
    keypress() {
      // this.$emit('on-search')
    },
    reset() {
      this.form = {...defaultForm}
      this.$emit('on-search')
    },
  },

}
</script>

<style scoped lang="less">
.input {
  width: 200px;
}

.searchForm {
  display: flex;
  justify-content: space-between;
  padding: 10px 10px 5px 5px;
  align-items: center;
  flex-wrap: wrap;

  .labelBox {
    display: flex;
    flex-wrap: wrap;
  }

  .label {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    margin-right: 10px;

    .name {
      min-width: 80px;
      display: inline-block;
      flex: 0;
      max-width: 100px;
      text-align: right;
      font-size: 12px;
      color: #666666;
    }
  }

  .btn-box {
    margin-left: 10px;
    margin-bottom: 10px;
  }
}
</style>
