广丰卷烟厂数采质量分析系统
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<template>
  <n-modal
    :show="visible"
    @update:show="(value) => emit('update:visible', value)"
    title="🔧 一键批量校准"
    preset="card"
    size="large"
    :style="bodyStyle"
  >
    <n-grid :cols="2" :x-gap="12" :y-gap="12">
      <n-form-item-gi label="校准日期" required>
        <n-date-picker v-model:value="form.calibDate" type="date" />
      </n-form-item-gi>
      <n-form-item-gi label="统一备注">
        <n-input v-model:value="form.note" placeholder="批量校准备注(可选)" />
      </n-form-item-gi>
    </n-grid>
    <div>
      <div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;">
        <label class="form-label">选择的盒子</label>
        <n-checkbox v-model:checked="form.useStandardWeight">
          全部填入标准重量
        </n-checkbox>
      </div>
      <div class="batch-cali-list">
        <div v-for="box in selectedRows" :key="box.id" class="batch-cali-item">
          <div class="box-info">
            <div class="box-name">{{ box.location }} · {{ box.name }} · {{ box.code }}</div>
          </div>
          <div style="display: flex; align-items: center;">
            <n-input 
              v-model:value="box.actualWeight" 
              type="number" 
              placeholder="输入实际重量"
              style="width: 120px;"
            />
            <span style="margin-left: 8px; color: #666;">{{ box.unit || 'g' }}</span>
          </div>
        </div>
      </div>
      <div class="batch-cali-summary">
        <span>共 <strong>{{ selectedRows.length }}</strong> 个盒子</span>
      </div>
    </div>
    <template #footer>
      <div class="modal-footer">
        <span class="modal-hint">校准后自动更新下次校准日期</span>
        <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
  },
  selectedRows: {
    type: Array,
    default: () => []
  }
});
 
const emit = defineEmits(['update:visible', 'submitted']);
 
const message = useMessage();
 
const form = reactive({
  calibDate: null,
  note: '',
  useStandardWeight: false
});
 
const bodyStyle = {
  width: '700px'
};
 
watch(() => props.visible, (newValue) => {
  if (newValue) {
    form.calibDate = new Date();
    form.note = '';
    form.useStandardWeight = false;
    // 为每个选中的盒子添加 actualWeight 属性
    props.selectedRows.forEach(box => {
      box.actualWeight = '';
    });
  }
});
 
// 监听 useStandardWeight 变化
watch(() => form.useStandardWeight, (value) => {
  if (value) {
    props.selectedRows.forEach(box => {
      box.actualWeight = box.weight;
    });
  }
});
 
const handleCancel = () => {
  emit('update:visible', false);
};
 
const handleSubmit = async () => {
  try {
    const items = props.selectedRows.map(row => ({
      boxId: row.id,
      actualWeight: row.actualWeight
    }));
    
    const response = await weighingBoxApi.batchCalibrate({
      boxIds: props.selectedRows.map(row => row.id),
      calibDate: form.calibDate,
      note: form.note,
      items: items
    });
    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>
/* 表单样式 */
.form-label {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-bottom: 8px;
}
 
/* 批量校准列表 */
.batch-cali-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin: 12px 0;
}
 
.batch-cali-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
}
 
.batch-cali-item:last-child {
  border-bottom: none;
}
 
.batch-cali-item .box-info {
  flex: 1;
}
 
.batch-cali-item .box-name {
  color: #333;
  margin-bottom: 4px;
}
 
.batch-cali-item .box-meta {
  font-size: 12px;
  color: #666;
}
 
.batch-cali-summary {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 14px;
  color: #666;
}
 
/* 模态框底部 */
.modal-footer {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.modal-hint {
  font-size: 12px;
  color: #999;
}
 
.modal-footer-right {
  display: flex;
  gap: 10px;
}
</style>