<!-- 搜索表单 -->
<template>
  <el-form label-width="80px" class="ele-form-search" @keyup.enter.native="search" @submit.native.prevent>
    <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="计划编号:">
          <el-input clearable v-model="where.code" placeholder="请输入" />
        </el-form-item>
      </el-col>



      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="计划状态:" label-width="80px">
          <el-select v-model="status" placeholder="请选择" class="w100">
            <el-option v-for="item in statusOpt[activeName]" :label="item.label" :value="item.value"
              :key="item.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="创建时间:">
          <el-date-picker class="w100" v-model="where.createTime" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 6 } : { span: 5 }">
        <el-form-item label="组织机构:">
          <auth-selection data-type="Array" v-model="where.deptIds" style="width: 100%"></auth-selection>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 4, md: 12 } : { span: 4 }">
        <div class="ele-form-actions">
          <el-button type="primary" icon="el-icon-search" class="ele-btn-icon" @click="search">
            查询
          </el-button>
          <el-button @click="reset" icon="el-icon-refresh-left" type="primary">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
export default {
  props: ['activeName', 'statusOpt',],
  data() {
    // 默认表单数据
    const defaultWhere = {


      statusList: null,
      code: '',
      releaseTime: [],
      deliveryTime: [],
      createTime: []
    };
    return {
      // 表单数据
      where: { ...defaultWhere },
      treeData: [],

      status: null
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive() {
      return this.$store.state.theme.styleResponsive;
    }
  },
  watch: {
    activeName: {
      handler() {
        if (this.activeName) {
          this.status = this.statusOpt[this.activeName][0].value;
          this.reset();
        }
      },
      immediate: true
    }
  },
  created() { },
  methods: {
    /* 搜索 */
    search() {
      const where = { ...this.where };

      for (const key in where) {
        if (Array.isArray(where[key]) && where[key].length) {
          where[`${key}Start`] = where[key][0];
          where[`${key}End`] = where[key][1];
        }
      }
      delete where.releaseTime;
      delete where.deliveryTime;
      delete where.createTime;

      where.statusList = this.status;

      this.$emit('search', where);
    },
    /*  重置 */
    reset() {
      this.where = { ...this.defaultWhere };
      this.where.statusList = this.statusOpt[this.activeName][0].value;
      this.search();
    }
  }
};
</script>
<style lang="scss" scoped>
.ele-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
