<script setup lang="ts">
|
import { computed, ref, watch } from 'vue';
|
import { jsonClone } from '@sa/utils';
|
import { fetchCreateFeedMatch, fetchUpdateFeedMatch } from '@/service/api/analy/feed-match';
|
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
import { $t } from '@/locales';
|
|
defineOptions({
|
name: 'FeedMatchOperateDrawer'
|
});
|
|
interface Props {
|
/** the type of operation */
|
operateType: NaiveUI.TableOperateType;
|
/** the edit row data */
|
rowData?: Api.Analy.FeedMatch | null;
|
}
|
|
const props = defineProps<Props>();
|
|
interface Emits {
|
(e: 'submitted'): void;
|
}
|
|
const emit = defineEmits<Emits>();
|
|
const visible = defineModel<boolean>('visible', {
|
default: false
|
});
|
|
const { formRef, validate, restoreValidation } = useNaiveForm();
|
const { createRequiredRule } = useFormRules();
|
|
const title = computed(() => {
|
const titles: Record<NaiveUI.TableOperateType, string> = {
|
add: '新增喂丝机对应关系',
|
edit: '编辑喂丝机对应关系'
|
};
|
return titles[props.operateType];
|
});
|
|
type Model = Api.Analy.FeedMatchOperateParams;
|
|
const model = ref<Model>(createDefaultModel());
|
|
function createDefaultModel(): Model {
|
return {
|
time: null,
|
key: '',
|
dacUpTime: '',
|
fs11: '',
|
fs12: '',
|
fs21: '',
|
fs22: '',
|
fs31: '',
|
fs32: '',
|
fs41: '',
|
fs42: '',
|
pipe01: null,
|
pipe02: null,
|
pipe03: null,
|
pipe04: null,
|
pipe05: null,
|
pipe06: null,
|
pipe07: null,
|
pipe08: null,
|
pipe09: null,
|
pipe10: null,
|
pipe11: null,
|
pipe12: null,
|
wsjState: null,
|
shift: null,
|
equNo: null,
|
remark: ''
|
};
|
}
|
|
type RuleKey = Extract<keyof Model, 'time' | 'key'>;
|
|
const rules: Record<RuleKey, App.Global.FormRule> = {
|
time: createRequiredRule('时间戳不能为空'),
|
key: createRequiredRule('班次+机台不能为空')
|
};
|
|
function handleUpdateModelWhenEdit() {
|
model.value = createDefaultModel();
|
|
if (props.operateType === 'edit' && props.rowData) {
|
Object.assign(model.value, jsonClone(props.rowData));
|
}
|
}
|
|
function closeDrawer() {
|
visible.value = false;
|
}
|
|
async function handleSubmit() {
|
await validate();
|
|
const {
|
time,
|
key,
|
dacUpTime,
|
fs11,
|
fs12,
|
fs21,
|
fs22,
|
fs31,
|
fs32,
|
fs41,
|
fs42,
|
pipe01,
|
pipe02,
|
pipe03,
|
pipe04,
|
pipe05,
|
pipe06,
|
pipe07,
|
pipe08,
|
pipe09,
|
pipe10,
|
pipe11,
|
pipe12,
|
wsjState,
|
shift,
|
equNo,
|
remark
|
} = model.value;
|
|
// request
|
if (props.operateType === 'add') {
|
const { error } = await fetchCreateFeedMatch({
|
time,
|
key,
|
dacUpTime,
|
fs11,
|
fs12,
|
fs21,
|
fs22,
|
fs31,
|
fs32,
|
fs41,
|
fs42,
|
pipe01,
|
pipe02,
|
pipe03,
|
pipe04,
|
pipe05,
|
pipe06,
|
pipe07,
|
pipe08,
|
pipe09,
|
pipe10,
|
pipe11,
|
pipe12,
|
wsjState,
|
shift,
|
equNo,
|
remark
|
});
|
if (error) return;
|
}
|
|
if (props.operateType === 'edit') {
|
const { error } = await fetchUpdateFeedMatch({
|
time,
|
key,
|
dacUpTime,
|
fs11,
|
fs12,
|
fs21,
|
fs22,
|
fs31,
|
fs32,
|
fs41,
|
fs42,
|
pipe01,
|
pipe02,
|
pipe03,
|
pipe04,
|
pipe05,
|
pipe06,
|
pipe07,
|
pipe08,
|
pipe09,
|
pipe10,
|
pipe11,
|
pipe12,
|
wsjState,
|
shift,
|
equNo,
|
remark
|
});
|
if (error) return;
|
}
|
|
window.$message?.success($t('common.updateSuccess'));
|
closeDrawer();
|
emit('submitted');
|
}
|
|
watch(visible, () => {
|
if (visible.value) {
|
handleUpdateModelWhenEdit();
|
restoreValidation();
|
}
|
});
|
</script>
|
|
<template>
|
<NDrawer v-model:show="visible" :title="title" display-directive="show" :width="800" class="max-w-90%">
|
<NDrawerContent :title="title" :native-scrollbar="false" closable>
|
<NForm ref="formRef" :model="model" :rules="rules">
|
<NFormItem label="时间戳" path="time">
|
<NDatePicker
|
v-model:formatted-value="model.time"
|
type="datetime"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
clearable
|
/>
|
</NFormItem>
|
<NFormItem label="班次+机台" path="key">
|
<NInput v-model:value="model.key" :rows="3" type="textarea" placeholder="请输入班次+机台" />
|
</NFormItem>
|
<NFormItem label="数据更新时间" path="dacUpTime">
|
<NInput v-model:value="model.dacUpTime" :rows="3" type="textarea" placeholder="请输入数据更新时间" />
|
</NFormItem>
|
<NFormItem label="1#喂丝机对应的第一个储丝柜" path="fs11">
|
<NInput v-model:value="model.fs11" :rows="3" type="textarea" placeholder="请输入1#喂丝机对应的第一个储丝柜" />
|
</NFormItem>
|
<NFormItem label="1#喂丝机对应的第二个储丝柜" path="fs12">
|
<NInput v-model:value="model.fs12" :rows="3" type="textarea" placeholder="请输入1#喂丝机对应的第二个储丝柜" />
|
</NFormItem>
|
<NFormItem label="2#喂丝机对应的第一个储丝柜" path="fs21">
|
<NInput v-model:value="model.fs21" :rows="3" type="textarea" placeholder="请输入2#喂丝机对应的第一个储丝柜" />
|
</NFormItem>
|
<NFormItem label="2#喂丝机对应的第二个储丝柜" path="fs22">
|
<NInput v-model:value="model.fs22" :rows="3" type="textarea" placeholder="请输入2#喂丝机对应的第二个储丝柜" />
|
</NFormItem>
|
<NFormItem label="3#喂丝机对应的第一个储丝柜" path="fs31">
|
<NInput v-model:value="model.fs31" :rows="3" type="textarea" placeholder="请输入3#喂丝机对应的第一个储丝柜" />
|
</NFormItem>
|
<NFormItem label="3#喂丝机对应的第二个储丝柜" path="fs32">
|
<NInput v-model:value="model.fs32" :rows="3" type="textarea" placeholder="请输入3#喂丝机对应的第二个储丝柜" />
|
</NFormItem>
|
<NFormItem label="4#喂丝机对应的第一个储丝柜" path="fs41">
|
<NInput v-model:value="model.fs41" :rows="3" type="textarea" placeholder="请输入4#喂丝机对应的第一个储丝柜" />
|
</NFormItem>
|
<NFormItem label="4#喂丝机对应的第二个储丝柜" path="fs42">
|
<NInput v-model:value="model.fs42" :rows="3" type="textarea" placeholder="请输入4#喂丝机对应的第二个储丝柜" />
|
</NFormItem>
|
<NFormItem label="1#机组对应的喂丝机和管道" path="pipe01">
|
<NInputNumber v-model:value="model.pipe01" placeholder="请输入1#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="2#机组对应的喂丝机和管道" path="pipe02">
|
<NInputNumber v-model:value="model.pipe02" placeholder="请输入2#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="3#机组对应的喂丝机和管道" path="pipe03">
|
<NInputNumber v-model:value="model.pipe03" placeholder="请输入3#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="4#机组对应的喂丝机和管道" path="pipe04">
|
<NInputNumber v-model:value="model.pipe04" placeholder="请输入4#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="5#机组对应的喂丝机和管道" path="pipe05">
|
<NInputNumber v-model:value="model.pipe05" placeholder="请输入5#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="6#机组对应的喂丝机和管道" path="pipe06">
|
<NInputNumber v-model:value="model.pipe06" placeholder="请输入6#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="7#机组对应的喂丝机和管道" path="pipe07">
|
<NInputNumber v-model:value="model.pipe07" placeholder="请输入7#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="8#机组对应的喂丝机和管道" path="pipe08">
|
<NInputNumber v-model:value="model.pipe08" placeholder="请输入8#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="9#机组对应的喂丝机和管道" path="pipe09">
|
<NInputNumber v-model:value="model.pipe09" placeholder="请输入9#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="10#机组对应的喂丝机和管道" path="pipe10">
|
<NInputNumber v-model:value="model.pipe10" placeholder="请输入10#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="11#机组对应的喂丝机和管道" path="pipe11">
|
<NInputNumber v-model:value="model.pipe11" placeholder="请输入11#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="12#机组对应的喂丝机和管道" path="pipe12">
|
<NInputNumber v-model:value="model.pipe12" placeholder="请输入12#机组对应的喂丝机和管道" class="w-full" />
|
</NFormItem>
|
<NFormItem label="喂丝机状态 1-连接 0-断开" path="wsjState">
|
<NInputNumber v-model:value="model.wsjState" placeholder="请输入喂丝机状态 1-连接 0-断开" class="w-full" />
|
</NFormItem>
|
<NFormItem label="班次" path="shift">
|
<NInputNumber v-model:value="model.shift" placeholder="请输入班次" class="w-full" />
|
</NFormItem>
|
<NFormItem label="机台" path="equNo">
|
<NInputNumber v-model:value="model.equNo" placeholder="请输入机台" class="w-full" />
|
</NFormItem>
|
<NFormItem label="备注" path="remark">
|
<NInput v-model:value="model.remark" placeholder="请输入备注" />
|
</NFormItem>
|
</NForm>
|
<template #footer>
|
<NSpace :size="16">
|
<NButton @click="closeDrawer">{{ $t('common.cancel') }}</NButton>
|
<NButton type="primary" @click="handleSubmit">{{ $t('common.confirm') }}</NButton>
|
</NSpace>
|
</template>
|
</NDrawerContent>
|
</NDrawer>
|
</template>
|
|
<style scoped></style>
|