<!-- 搜索表单 -->
<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="6" :md="8" :sm="12" :xs="24">
          <el-form-item label="账号">
            <el-input
              clearable
              v-model.trim="form.account"
              placeholder="请输入(会员ID/手机号)"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="18" :sm="17" :xs="24">
          <el-form-item label="注册时间">
            <el-date-picker
              unlink-panels
              type="datetimerange"
              v-model="registerTime"
              range-separator="-"
              value-format="YYYY-MM-DD HH:mm:ss"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              class="ele-fluid"
            />
          </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 { MemberParam } from '@/api/xm/member/model';
  import { ref } from 'vue';

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

  /** 表单数据 */
  const [form, resetFields] = useFormData<MemberParam>({
    account: ''
  });
  const registerTime = ref([]);

  /** 搜索 */
  const search = () => {
    let where: any = { ...form };
    if (registerTime.value.length == 2 && registerTime.value[0]) {
      where.registerStartTime = registerTime.value[0];
      where.registerEndTime = registerTime.value[1];
    }
    emit('search', where);
  };

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