广丰卷烟厂数采质量分析系统
baoshiwei
14 小时以前 d143af7023cfd4a0ced6f0ecf04ae3b3a06fd1dc
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
<template>
  <n-modal
    :show="visible"
    @update:show="(value) => emit('update:visible', value)"
    title="🔧 完成校准"
    preset="card"
    size="medium"
    :style="bodyStyle"
  >
    <div class="calib-info">
      <div class="info-row">
        <span class="info-label">盒子名称</span>
        <span class="info-value">{{ form.name }}</span>
      </div>
      <div class="info-row">
        <span class="info-label">盒子编号</span>
        <span class="info-value">{{ form.code }}</span>
      </div>
      <div class="info-row">
        <span class="info-label">所在位置</span>
        <span class="info-value">{{ form.location }}</span>
      </div>
    </div>
    <div class="form-group">
      <label class="form-label">本次校准日期 <span class="required">*</span></label>
      <n-date-picker v-model:value="form.calibDate" type="date" />
    </div>
    <div class="form-group">
      <label class="form-label">本次实测重量(可选)</label>
      <div class="form-row">
        <n-input-number v-model:value="form.actualWeight" placeholder="实测重量" />
        <span style="color: #666;">{{ props.rowData.unit || 'g' }}</span>
      </div>
    </div>
    <div class="form-group">
      <label class="form-label">校准备注</label>
      <n-input v-model:value="form.note" type="textarea" placeholder="校准结果、偏差说明等…" />
    </div>
    <template #footer>
      <div class="modal-footer">
        <div class="modal-footer-right">
          <n-button @click="handleCancel">取消</n-button>
          <n-button type="success" @click="handleSubmit">✅ 确认校准完成</n-button>
        </div>
      </div>
    </template>
  </n-modal>
</template>
 
<script setup lang="ts">
import { ref, reactive, watch } from 'vue';
import { weighingBoxApi } from '@/service/api/md/weighing-box';
import { useMessage } from 'naive-ui';
 
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object,
    default: () => ({})
  }
});
 
const emit = defineEmits(['update:visible', 'submitted']);
 
const message = useMessage();
 
const form = reactive({
  id: undefined,
  name: '',
  code: '',
  weight: '',
  calibDate: null,
  actualWeight: null,
  note: ''
});
 
const bodyStyle = {
  width: '500px'
};
 
watch(() => props.visible, (newValue) => {
  if (newValue && props.rowData) {
    form.id = props.rowData.id;
    form.name = props.rowData.name;
    form.code = props.rowData.code;
    form.weight = props.rowData.weight;
    form.calibDate = new Date();
    form.actualWeight = null;
    form.note = '';
  }
});
 
const handleCancel = () => {
  emit('update:visible', false);
};
 
const handleSubmit = async () => {
  try {
    const response = await weighingBoxApi.calibrate({
      boxId: form.id,
      calibDate: form.calibDate,
      actualWeight: form.actualWeight,
      note: form.note
    });
    const res = response.response.data;
 
    if (res.code === 200) {
      message.success('校准成功');
      emit('update:visible', false);
      emit('submitted');
    } else {
      message.error(res.msg || '校准失败');
    }
  } catch (error) {
    message.error('校准失败');
  }
};
</script>
 
<style scoped>
/* 校准信息 */
.calib-info {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid #e5e7eb;
}
 
.calib-info .info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid #e5e7eb;
}
 
.calib-info .info-row:last-child {
  border-bottom: none;
}
 
.calib-info .info-label {
  color: #666;
  font-weight: 500;
}
 
.calib-info .info-value {
  color: #333;
}
 
/* 表单样式 */
.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}
 
.form-label {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-bottom: 8px;
}
 
.form-label .required {
  color: #ff4d4f;
  margin-left: 4px;
}
 
.form-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
 
/* 模态框底部 */
.modal-footer {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
 
.modal-footer-right {
  display: flex;
  gap: 10px;
}
</style>