<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form
      label-width="82px"
      @keyup.enter.prevent="search"
      @submit.prevent=""
    >
      <el-row :gutter="8">
        <el-col :lg="4" :md="8" :sm="12" :xs="24">
          <el-form-item label="关键字查询">
            <el-input
              clearable
              v-model.trim="form.keyword"
              placeholder="请输入关键字(渠道名称/标识/备注)检索"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="4" :md="8" :sm="12" :xs="24">
          <el-form-item label="渠道名称">
            <el-input
              clearable
              v-model.trim="form.name"
              placeholder="请输入渠道(渠道ID/渠道代码/渠道标识)"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="12" :md="8" :sm="24" :xs="24">
          <el-form-item label-width="16px">
            <el-button type="primary" @click="search">查询</el-button>
            <el-button @click="reset">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </ele-card>
</template>

<script lang="ts" setup>
  import { useFormData } from '@/utils/use-form-data';
  import type { ChannelParam } from '@/api/xm/channel/model';

  const emit = defineEmits<{
    (e: 'search', where?: ChannelParam): void;
  }>();

  /** 表单数据 */
  const [form, resetFields] = useFormData<ChannelParam>({
    name: '',
    keyword: ''
  });
  /** 搜索 */
  const search = () => {
    let where: any = { ...form };
    emit('search', where);
  };

  /**  重置 */
  const reset = () => {
    resetFields();
    search();
  };
</script>
