<script setup lang="ts">
import { RDMS_REQ_SOURCE_TYPE_DICT_CODE } from '@/constants/dict';
import DictSelect from '@/components/custom/dict-select.vue';
import TableSearchPanel from '@/components/custom/table-search-panel.vue';
import MemberSelectOption from './member-select-option.vue';

defineOptions({ name: 'RequirementSearch' });

interface MemberUserOption {
  id: string;
  nickname: string;
  roleName?: string;
}

interface Props {
  memberOptions: MemberUserOption[];
  categoryDictCode: string;
  priorityDictCode: string;
}

defineProps<Props>();

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

const emit = defineEmits<Emits>();

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

const requirementStatusOptions = [
  { label: '待确认', value: 'pending_confirm' },
  { label: '待评审', value: 'pending_review' },
  { label: '待分流', value: 'pending_dispatch' },
  { label: '实施中', value: 'implementing' },
  { label: '已验收', value: 'accepted' },
  { label: '已关闭', value: 'closed' },
  { label: '已拒绝', value: 'rejected' },
  { label: '已取消', value: 'cancelled' }
];

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

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

<template>
  <TableSearchPanel :model="model" :action-col-lg="6" @reset="reset" @search="search">
    <ElCol :lg="6" :md="12" :sm="12">
      <ElFormItem label="标题">
        <ElInput v-model="model.title" clearable placeholder="输入需求标题" />
      </ElFormItem>
    </ElCol>
    <ElCol :lg="6" :md="12" :sm="12">
      <ElFormItem label="分类">
        <DictSelect
          v-model="model.category"
          :dict-code="categoryDictCode"
          clearable
          filterable
          placeholder="筛选分类"
        />
      </ElFormItem>
    </ElCol>
    <ElCol :lg="6" :md="12" :sm="12">
      <ElFormItem label="优先级">
        <DictSelect v-model="model.priority" :dict-code="priorityDictCode" clearable placeholder="筛选优先级" />
      </ElFormItem>
    </ElCol>
    <ElCol :lg="6" :md="12" :sm="12">
      <ElFormItem label="状态">
        <ElSelect v-model="model.statusCode" clearable placeholder="筛选状态">
          <ElOption
            v-for="item in requirementStatusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </ElSelect>
      </ElFormItem>
    </ElCol>
    <ElCol :lg="6" :md="12" :sm="12">
      <ElFormItem label="负责人">
        <ElSelect
          v-model="model.currentHandlerUserId"
          clearable
          filterable
          placeholder="筛选负责人"
          :filter-method="(val: string) => val"
        >
          <ElOption v-for="item in memberOptions" :key="item.id" :label="item.nickname" :value="item.id">
            <MemberSelectOption :nickname="item.nickname" :role-name="item.roleName || ''" />
          </ElOption>
        </ElSelect>
      </ElFormItem>
    </ElCol>
    <ElCol :lg="6" :md="12" :sm="12">
      <ElFormItem label="来源类型">
        <DictSelect
          v-model="model.sourceType"
          :dict-code="RDMS_REQ_SOURCE_TYPE_DICT_CODE"
          clearable
          placeholder="筛选来源类型"
        />
      </ElFormItem>
    </ElCol>
  </TableSearchPanel>
</template>

<style scoped></style>
