广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-06 b12c9e77a6b6a7b410ac421c5a3d68da88823460
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { jsonClone } from '@sa/utils';
import { fetchCreateStoreSilk, fetchUpdateStoreSilk } from '@/service/api/analy/store-silk';
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';
 
defineOptions({
  name: 'StoreSilkOperateDrawer'
});
 
interface Props {
  /** the type of operation */
  operateType: NaiveUI.TableOperateType;
  /** the edit row data */
  rowData?: Api.Analy.StoreSilk | 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.StoreSilkOperateParams;
 
const model = ref<Model>(createDefaultModel());
 
function createDefaultModel(): Model {
  return {
    id: null,
    materialname: '',
    batchcode: '',
    actualstarttime: null,
    jobinput: null,
    weightloss: null,
    slkrate: null,
    weight: null,
    distimebegin: null,
    distimeend: null,
    siloid: ''
  };
}
 
type RuleKey = Extract<keyof Model, 'id' | 'materialname' | 'batchcode'>;
 
const rules: Record<RuleKey, App.Global.FormRule> = {
  id: createRequiredRule('id不能为空'),
  materialname: createRequiredRule('牌号不能为空'),
  batchcode: 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 {
    id,
    materialname,
    batchcode,
    actualstarttime,
    jobinput,
    weightloss,
    slkrate,
    weight,
    distimebegin,
    distimeend,
    siloid
  } = model.value;
 
  // request
  if (props.operateType === 'add') {
    const { error } = await fetchCreateStoreSilk({
      materialname,
      batchcode,
      actualstarttime,
      jobinput,
      weightloss,
      slkrate,
      weight,
      distimebegin,
      distimeend,
      siloid
    });
    if (error) return;
  }
 
  if (props.operateType === 'edit') {
    const { error } = await fetchUpdateStoreSilk({
      id,
      materialname,
      batchcode,
      actualstarttime,
      jobinput,
      weightloss,
      slkrate,
      weight,
      distimebegin,
      distimeend,
      siloid
    });
    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="materialname">
          <NInput v-model:value="model.materialname" placeholder="请输入牌号" />
        </NFormItem>
        <NFormItem label="批次号" path="batchcode">
          <NInput v-model:value="model.batchcode" placeholder="请输入批次号" />
        </NFormItem>
        <NFormItem label="投料日期" path="actualstarttime">
          <NDatePicker
            v-model:formatted-value="model.actualstarttime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            clearable
          />
        </NFormItem>
        <NFormItem label="投料重量" path="jobinput">
          <NInputNumber v-model:value="model.jobinput" placeholder="请输入投料重量" class="w-full" />
        </NFormItem>
        <NFormItem label="损耗重量" path="weightloss">
          <NInputNumber v-model:value="model.weightloss" placeholder="请输入损耗重量" class="w-full" />
        </NFormItem>
        <NFormItem label="出叶丝率" path="slkrate">
          <NInputNumber v-model:value="model.slkrate" placeholder="请输入出叶丝率" class="w-full" />
        </NFormItem>
        <NFormItem label="储丝柜重量" path="weight">
          <NInputNumber v-model:value="model.weight" placeholder="请输入储丝柜重量" class="w-full" />
        </NFormItem>
        <NFormItem label="储丝柜出料开始时间" path="distimebegin">
          <NDatePicker
            v-model:formatted-value="model.distimebegin"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            clearable
          />
        </NFormItem>
        <NFormItem label="储丝柜出料结束时间" path="distimeend">
          <NDatePicker
            v-model:formatted-value="model.distimeend"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            clearable
          />
        </NFormItem>
        <NFormItem label="柜子号(末位)" path="siloid">
          <NInput v-model:value="model.siloid" 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>