<script setup lang="ts">
import { ref } from 'vue';
import SearchForm from '@/components/advanced/search-form.vue';

defineOptions({
  name: 'OperlogSearch',
  inheritAttrs: false
});

const dateRange = ref<[string, string] | null>(null);
const model = defineModel<Api.SystemManage.OperlogSearchParams>('model', { required: true });
withDefaults(
  defineProps<{ typeOptions?: Api.SystemManage.DictInfo[]; statusOptions?: Api.SystemManage.DictInfo[] }>(),
  {
    typeOptions: () => [],
    statusOptions: () => []
  }
);

function handleDate(value: [string, string]) {
  model.value.params =
    value === null
      ? []
      : {
          beginTime: value[0],
          endTime: value[1]
        };
}
</script>

<template>
  <SearchForm v-model:model="model" v-bind="$attrs" @reset-interlayer="dateRange = null">
    <template #formItem>
      <NFormItemGi span="24 s:12 m:6" label="系统模块" class="pr-24px">
        <NInput v-model:value="model.title" placeholder="请输入系统模块" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="操作人员" class="pr-24px">
        <NInput v-model:value="model.operName" placeholder="请输入操作人员" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="类型" class="pr-24px">
        <NSelect
          v-model:value="model.businessType"
          placeholder="类型"
          value-field="dictValue"
          label-field="dictLabel"
          :options="typeOptions"
          clearable
        />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="状态" class="pr-24px">
        <NSelect
          v-model:value="model.status"
          placeholder="状态"
          value-field="dictValue"
          label-field="dictLabel"
          :options="statusOptions"
          clearable
        />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="操作时间" class="pr-24px">
        <NDatePicker
          v-model:formatted-value="dateRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          clearable
          @update:formatted-value="handleDate"
        />
      </NFormItemGi>
    </template>
  </SearchForm>
</template>

<style scoped></style>
