<script setup lang="ts">
|
import { onMounted, ref, toRaw, watch } from 'vue';
|
import { jsonClone } from '@sa/utils';
|
import { fetchGetMatList } from '@/service/api/md/mat';
|
import { useNaiveForm } from '@/hooks/common/form';
|
import { $t } from '@/locales';
|
|
defineOptions({
|
name: 'JudgeSearch'
|
});
|
|
interface Emits {
|
(e: 'search'): void;
|
}
|
|
const emit = defineEmits<Emits>();
|
|
const { formRef, validate, restoreValidation } = useNaiveForm();
|
|
const model = defineModel<Api.Qm.JudgeSearchParams>('model', { required: true });
|
|
const defaultModel = jsonClone(toRaw(model.value));
|
|
const matOptions = ref<CommonType.Option[]>([]);
|
|
async function getMatOptions() {
|
if (model.value.category !== 0) {
|
matOptions.value = [];
|
model.value.matName = null;
|
model.value.matCode = null;
|
return;
|
}
|
const { data } = await fetchGetMatList({ tid: 1, pageSize: 1000 });
|
if (data) {
|
matOptions.value = data.rows.map(item => ({
|
label: item.name,
|
value: item.code
|
}));
|
}
|
}
|
|
watch(
|
() => model.value.category,
|
newVal => {
|
if (newVal === 0) {
|
getMatOptions();
|
} else {
|
matOptions.value = [];
|
model.value.matName = null;
|
model.value.matCode = null;
|
}
|
}
|
);
|
|
onMounted(() => {
|
if (model.value.category === 0) {
|
getMatOptions();
|
}
|
});
|
|
function resetModel() {
|
Object.assign(model.value, defaultModel);
|
}
|
|
async function reset() {
|
await restoreValidation();
|
resetModel();
|
emit('search');
|
}
|
|
async function search() {
|
await validate();
|
emit('search');
|
}
|
</script>
|
|
<template>
|
<NCard :bordered="false" size="small" class="card-wrapper">
|
<NCollapse>
|
<NCollapseItem :title="$t('common.search')" name="qm-judge-search">
|
<NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
|
<NGrid responsive="screen" item-responsive>
|
<NFormItemGi span="24 s:12 m:6" label="物料类型" label-width="auto" path="category" class="pr-24px">
|
<NSelect
|
v-model:value="model.category"
|
:options="[
|
{ label: '成品', value: 0 },
|
{ label: '辅料', value: 1 }
|
]"
|
placeholder="请选择物料类型"
|
/>
|
</NFormItemGi>
|
|
<NFormItemGi span="24 s:12 m:6" label="物料牌号" label-width="auto" path="matCode" class="pr-24px">
|
<NSelect
|
v-model:value="model.matCode"
|
:options="matOptions"
|
placeholder="请选择物料牌号"
|
:disabled="model.category !== 0"
|
clearable
|
filterable
|
/>
|
</NFormItemGi>
|
<NFormItemGi span="24 s:12 m:6" label="判定名称" label-width="auto" path="judgeName" class="pr-24px">
|
<NInput v-model:value="model.judgeName" placeholder="请输入判定名称" />
|
</NFormItemGi>
|
<NFormItemGi span="24 s:12 m:6" label="是否启用" label-width="auto" path="status" class="pr-24px">
|
<NSelect
|
v-model:value="model.status"
|
:options="[
|
{ label: '全部', value: -1 },
|
{ label: '启用', value: 1 },
|
{ label: '归档', value: 0 }
|
]"
|
/>
|
</NFormItemGi>
|
<NFormItemGi :show-feedback="false" span="24" class="pr-24px">
|
<NSpace class="w-full" justify="end">
|
<NButton @click="reset">
|
<template #icon>
|
<icon-ic-round-refresh class="text-icon" />
|
</template>
|
{{ $t('common.reset') }}
|
</NButton>
|
<NButton type="primary" ghost @click="search">
|
<template #icon>
|
<icon-ic-round-search class="text-icon" />
|
</template>
|
{{ $t('common.search') }}
|
</NButton>
|
</NSpace>
|
</NFormItemGi>
|
</NGrid>
|
</NForm>
|
</NCollapseItem>
|
</NCollapse>
|
</NCard>
|
</template>
|
|
<style scoped></style>
|