<script setup lang="ts">
import { computed } from 'vue';
import { RDMS_OBJECT_DIRECTION_DICT_CODE, RDMS_PROJECT_TYPE_DICT_CODE } from '@/constants/dict';
import TableSearchFields, { type SearchField } from '@/components/custom/table-search-fields.vue';

defineOptions({ name: 'ProjectSearch' });

interface Props {
  managerOptions: Api.SystemManage.UserSimple[];
}

const props = defineProps<Props>();

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const model = defineModel<Api.Project.ProjectSearchParams>('model', { required: true });

const fields = computed<SearchField[]>(() => [
  {
    key: 'keyword',
    label: '关键词',
    type: 'input',
    placeholder: '项目编码 / 名称'
  },
  {
    key: 'directionCode',
    label: '项目方向',
    type: 'dict',
    dictCode: RDMS_OBJECT_DIRECTION_DICT_CODE,
    placeholder: '筛选项目方向'
  },
  {
    key: 'projectType',
    label: '项目类型',
    type: 'dict',
    dictCode: RDMS_PROJECT_TYPE_DICT_CODE,
    placeholder: '筛选项目类型'
  },
  {
    key: 'managerUserId',
    label: '项目经理',
    type: 'select',
    options: props.managerOptions.map(item => ({
      label: item.nickname,
      value: item.id
    })),
    placeholder: '筛选项目经理'
  }
]);

function reset() {
  emit('reset');
}

function search() {
  emit('search');
}
</script>

<template>
  <TableSearchFields v-model="model" :fields="fields" :columns="4" @reset="reset" @search="search" />
</template>

<style scoped></style>
