<template>
  <div class="Search">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="名称">
        <el-input v-model="formInline.keywords" placeholder="请输入名称" clearable />
      </el-form-item>
      <el-form-item label="领取方式">
        <el-select v-model="formInline.pickupMethod" placeholder="请选择领取方式" clearable>
          <el-option label="自取" value="self" />
          <el-option label="邮寄" value="post" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="formInline.status" placeholder="请选择状态" clearable>
          <el-option label="待支付" value="unpaid" />
          <el-option label="待自取" value="waiting" />
          <el-option label="已完成" value="done" />
          <el-option label="已取消" value="cancel" />
        </el-select>
      </el-form-item>
      <el-form-item label="日期">
        <el-date-picker v-model="formInline.date" type="daterange" range-separator="-" start-placeholder="开始日期"
          value-format="YYYY-MM-DD" @change="dateChange" end-placeholder="结束日期" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="onSubmit">搜索</el-button>
        <el-button icon="Refresh" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import eventBus from '@/utils/eventBus'
const formInline = reactive({
  keywords: '',
  pickupMethod: '',
  date: '',
  status: ""
})
const onSubmit = () => {
  eventBus.emit('search', formInline)
}
const reset = () => {
  for (let key in formInline) {
    formInline[key] = ''
  }
  eventBus.emit('search', formInline)
}
function dateChange(d) {
  formInline.endDate = d[1]
  formInline.beginDate = d[0]
}
</script>

<style scoped lang="scss">
.Search {
  padding: 20px;
  background-color: #fff;
  border: 1px solid #e4e7ed;
  border-radius: 4px;
}

.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.demo-form-inline .el-select {
  --el-select-width: 220px;
}
</style>
