11 小时以前 6b2e46f69c234aa1d18fe8f3a77ede2baa674ce4
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
<script setup lang="ts">
import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue';
 
import { message, Modal } from 'ant-design-vue';
import { IconifyIcon } from '@vben/icons';
import { gsap } from 'gsap';
 
import MdItemSelect from '#/views/mes/md/item/components/select.vue';
 
import {
  submitSeedQuality,
  type MesQcSeedQualityApi,
} from '#/api/mes/qc/seedQuality';
 
interface IndicatorForm {
  code: string;
  label: string;
  unit: string;
  value?: number;
  minValue?: number;
  maxValue?: number;
}
 
const pageRoot = ref<HTMLElement>();
const code = ref('');
const itemId = ref<number>();
const batchCode = ref('');
const reason = ref('');
const loading = ref(false);
const submittedId = ref<number>();
let animationContext: gsap.Context | undefined;
 
const indicators = ref<IndicatorForm[]>([
  { code: 'purity', label: '纯度', unit: '%', minValue: 0, maxValue: 100 },
  { code: 'cleanliness', label: '净度', unit: '%', minValue: 0, maxValue: 100 },
  { code: 'germination_rate', label: '发芽率', unit: '%', minValue: 0, maxValue: 100 },
  { code: 'moisture', label: '水分', unit: '%', minValue: 0, maxValue: 100 },
]);
 
const enteredCount = computed(() => indicators.value.filter((item) => item.value !== undefined && item.value !== null).length);
const passedCount = computed(() => indicators.value.filter(isPassed).length);
const allEntered = computed(() => enteredCount.value === indicators.value.length);
const overallPassed = computed(() => allEntered.value && passedCount.value === indicators.value.length);
 
function isPassed(item: IndicatorForm) {
  return item.value !== undefined && item.value !== null
    && item.minValue !== undefined && item.maxValue !== undefined
    && item.value >= item.minValue && item.value <= item.maxValue;
}
 
function resetForm(clearResult = true) {
  code.value = '';
  itemId.value = undefined;
  batchCode.value = '';
  reason.value = '';
  if (clearResult) submittedId.value = undefined;
  indicators.value.forEach((item) => {
    item.value = undefined;
    item.minValue = 0;
    item.maxValue = 100;
  });
}
 
async function submit() {
  if (!code.value.trim() || !itemId.value) {
    message.warning('请填写袋码并选择物料');
    return;
  }
  if (!allEntered.value) {
    message.warning('请先填写四项指标的实测值');
    return;
  }
  if (indicators.value.some((item) => item.minValue === undefined || item.maxValue === undefined || item.minValue > item.maxValue)) {
    message.warning('指标下限不能大于上限');
    return;
  }
  if (!overallPassed.value && !reason.value.trim()) {
    message.warning('检验不合格时必须填写不合格原因');
    return;
  }
 
  if (!overallPassed.value) {
    const confirmed = await new Promise<boolean>((resolve) => {
      Modal.confirm({
        title: '确认提交不合格结果?',
        content: '不合格品将由后端从暂存库存中清除,并保留不合格原因用于质量分析。',
        okText: '确认提交',
        cancelText: '返回修改',
        okButtonProps: { danger: true },
        onOk: () => resolve(true),
        onCancel: () => resolve(false),
      });
    });
    if (!confirmed) return;
  }
 
  loading.value = true;
  try {
    submittedId.value = await submitSeedQuality({
      code: code.value.trim(),
      itemId: itemId.value,
      batchCode: batchCode.value.trim() || undefined,
      indicators: indicators.value.map(({ code: indicatorCode, value, minValue, maxValue }) => ({
        code: indicatorCode,
        value: value as number,
        minValue: minValue as number,
        maxValue: maxValue as number,
      })),
      reason: reason.value.trim() || undefined,
    });
    message.success(`质检提交成功,质检编号:${submittedId.value}`);
    if (pageRoot.value && !window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
      gsap.fromTo('.result-card', { scale: 0.97, autoAlpha: 0.5 }, { scale: 1, autoAlpha: 1, duration: 0.35, ease: 'power2.out' });
    }
    resetForm(false);
  } catch (error) {
    const response = error as { message?: string; msg?: string };
    message.error(response.message ?? response.msg ?? '质检提交失败,请检查表单后重试');
  } finally {
    loading.value = false;
  }
}
 
onMounted(async () => {
  await nextTick();
  if (!pageRoot.value) return;
  animationContext = gsap.context(() => {
    const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    gsap.from('.page-header, .summary-card, .form-card, .result-card', {
      autoAlpha: reduceMotion ? 1 : 0,
      y: reduceMotion ? 0 : 14,
      duration: reduceMotion ? 0 : 0.4,
      stagger: reduceMotion ? 0 : 0.06,
      ease: 'power2.out',
    });
  }, pageRoot.value);
});
 
onUnmounted(() => animationContext?.revert());
</script>
 
<template>
  <div ref="pageRoot" class="quality-page">
    <header class="page-header">
      <div>
        <div class="eyebrow">MES / 质量管理</div>
        <h1>种子质检</h1>
        <p>录入纯度、净度、发芽率和水分,系统根据标准范围自动判定检验结论</p>
      </div>
      <div class="header-badge"><IconifyIcon icon="ep:checked" /> 四项指标检验</div>
    </header>
 
    <section class="summary-grid" aria-label="质检摘要">
      <div class="summary-card blue"><IconifyIcon icon="ep:document-checked" /><div><span>检验项目</span><strong>4</strong><small>纯度、净度、发芽率、水分</small></div></div>
      <div class="summary-card green"><IconifyIcon icon="ep:success-filled" /><div><span>当前合格项</span><strong>{{ passedCount }} / 4</strong><small>实时依据上下限判断</small></div></div>
      <div class="summary-card" :class="overallPassed ? 'green' : allEntered ? 'red' : 'blue'"><IconifyIcon :icon="overallPassed ? 'ep:circle-check-filled' : allEntered ? 'ep:warning-filled' : 'ep:edit-pen'" /><div><span>总体结论</span><strong>{{ overallPassed ? '合格' : allEntered ? '不合格' : '待录入' }}</strong><small>{{ overallPassed ? '可提交合格结果' : allEntered ? '请填写不合格原因' : `已录入 ${enteredCount} / 4 项` }}</small></div></div>
    </section>
 
    <section class="content-grid">
      <a-card class="form-card" :bordered="false">
        <template #title><div class="card-title"><IconifyIcon icon="ep:edit-pen" />质检信息</div></template>
        <a-form layout="vertical">
          <div class="base-grid">
            <a-form-item label="袋码" required><a-input v-model:value="code" size="large" :disabled="loading" placeholder="请输入或扫描袋码" /></a-form-item>
            <a-form-item label="物料" required>
              <MdItemSelect v-model="itemId" :disabled="loading" size="large" placeholder="请选择物料" />
            </a-form-item>
            <a-form-item label="生产批次"><a-input v-model:value="batchCode" size="large" :disabled="loading" placeholder="请输入批次号(选填)" /></a-form-item>
          </div>
 
          <a-divider orientation="left">指标结果</a-divider>
          <div class="indicator-list">
            <div v-for="item in indicators" :key="item.code" class="indicator-row" :class="{ failed: !isPassed(item) }">
              <div class="indicator-name"><span class="indicator-dot" :class="isPassed(item) ? 'pass' : 'fail'" /><strong>{{ item.label }}</strong><small>{{ item.unit }}</small></div>
              <a-input-number v-model:value="item.value" class="indicator-input" :disabled="loading" :min="0" :precision="3" placeholder="实测值" />
              <span class="range-separator">范围</span>
              <a-input-number v-model:value="item.minValue" class="range-input" :disabled="loading" :min="0" :precision="3" placeholder="下限" />
              <span>—</span>
              <a-input-number v-model:value="item.maxValue" class="range-input" :disabled="loading" :min="0" :precision="3" placeholder="上限" />
              <a-tag :color="isPassed(item) ? 'success' : 'error'">{{ isPassed(item) ? '合格' : '超出范围' }}</a-tag>
            </div>
          </div>
 
          <a-form-item label="不合格原因" :required="!overallPassed" class="reason-item"><a-textarea v-model:value="reason" :disabled="loading" :rows="3" :maxlength="500" show-count :placeholder="overallPassed ? '合格结果无需填写' : '请说明不合格原因'" /></a-form-item>
          <div class="form-actions"><a-button :disabled="loading" @click="resetForm">重置</a-button><a-button type="primary" size="large" :loading="loading" @click="submit"><IconifyIcon icon="ep:upload-filled" />提交质检</a-button></div>
        </a-form>
      </a-card>
 
      <a-card class="result-card" :bordered="false">
        <template #title><div class="card-title"><IconifyIcon icon="ep:data-analysis" />判定说明</div></template>
        <div class="result-hero" :class="overallPassed ? 'passed' : allEntered ? 'failed-result' : 'pending-result'"><IconifyIcon :icon="overallPassed ? 'ep:circle-check-filled' : allEntered ? 'ep:warning-filled' : 'ep:edit-pen'" /><strong>{{ overallPassed ? '当前结果合格' : allEntered ? '当前存在不合格项' : '等待录入指标' }}</strong><span>{{ allEntered ? '实测值需处于最小值与最大值之间' : `已录入 ${enteredCount} / 4 项实测值` }}</span></div>
        <div class="rule-list"><div><IconifyIcon icon="ep:check" /><span>四项指标必须全部提交</span></div><div><IconifyIcon icon="ep:check" /><span>边界值按合格处理</span></div><div><IconifyIcon icon="ep:check" /><span>不合格结果需保留原因</span></div><div><IconifyIcon icon="ep:check" /><span>质检员与检验时间由服务端记录</span></div></div>
        <a-alert message="库存流转由后端处理" description="合格品将从暂存库转入正式库存;不合格品将直接清除暂存库存并保留不合格原因。质检员和检验时间由服务端记录,本页面不选择仓库、库区或库位。" type="info" show-icon />
        <div v-if="submittedId" class="success-note"><IconifyIcon icon="ep:success-filled" /><span>最近提交质检编号:<strong>{{ submittedId }}</strong></span></div>
      </a-card>
    </section>
  </div>
</template>
 
<style scoped>
.quality-page { min-height: 100%; padding: 24px; background: #f4f7fb; color: #172033; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }.eyebrow { color: #1677ff; font-size: 12px; font-weight: 700; letter-spacing: .08em; }.page-header h1 { margin: 6px 0; font-size: 28px; }.page-header p { margin: 0; color: #718096; }.header-badge { display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid #cfe0fb; border-radius: 7px; color: #1677ff; background: #f0f6ff; font-size: 13px; font-weight: 600; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }.summary-card { display: flex; align-items: flex-start; gap: 14px; padding: 17px 19px; border: 1px solid #e8edf5; border-radius: 10px; background: #fff; box-shadow: 0 3px 12px #243b5310; }.summary-card > .iconify { flex: 0 0 38px; width: 38px; height: 38px; padding: 9px; border-radius: 8px; font-size: 20px; }.summary-card.blue > .iconify { color: #1677ff; background: #eaf3ff; }.summary-card.green > .iconify { color: #17a673; background: #e6f8f0; }.summary-card.red > .iconify { color: #e05252; background: #fff0f0; }.summary-card span, .summary-card small { display: block; color: #7b8799; font-size: 12px; }.summary-card strong { display: block; margin: 4px 0; font-size: 23px; }.content-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(310px, .75fr); gap: 18px; }.form-card, .result-card { border-radius: 10px; box-shadow: 0 3px 12px #243b5310; }.card-title { display: flex; align-items: center; gap: 9px; font-weight: 700; }.card-title :deep(.iconify) { color: #1677ff; }.base-grid { display: grid; grid-template-columns: 1.3fr 1fr 1.2fr; gap: 16px; }.full-width { width: 100%; }
.indicator-list { display: flex; flex-direction: column; gap: 10px; }.indicator-row { display: flex; align-items: center; gap: 9px; padding: 11px 12px; border: 1px solid #e8edf5; border-radius: 7px; background: #fbfcfe; }.indicator-row.failed { border-color: #ffd6d6; background: #fffafa; }.indicator-name { display: flex; align-items: center; gap: 8px; min-width: 82px; }.indicator-name small { color: #8793a5; font-size: 12px; }.indicator-dot { width: 8px; height: 8px; border-radius: 50%; }.indicator-dot.pass { background: #20b878; }.indicator-dot.fail { background: #e05252; }.indicator-input { width: 105px; }.range-input { width: 88px; }.range-separator { margin-left: auto; color: #8793a5; font-size: 12px; }.reason-item { margin-top: 18px; }.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 5px; }.form-actions :deep(.iconify) { margin-right: 5px; }
.result-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 8px 0 22px; padding: 25px 15px; border-radius: 8px; text-align: center; }.result-hero :deep(.iconify) { font-size: 35px; }.result-hero strong { font-size: 18px; }.result-hero span { color: #718096; font-size: 12px; }.result-hero.passed { color: #16835b; background: #effaf5; }.result-hero.failed-result { color: #c53e3e; background: #fff3f3; }.result-hero.pending-result { color: #1677ff; background: #f0f6ff; }.rule-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }.rule-list div { display: flex; align-items: center; gap: 9px; color: #59677b; font-size: 13px; }.rule-list :deep(.iconify) { color: #20b878; }.success-note { display: flex; align-items: center; gap: 8px; margin-top: 16px; padding: 11px 12px; border-radius: 7px; color: #16835b; background: #effaf5; font-size: 13px; }
@media (max-width: 1050px) { .content-grid { grid-template-columns: 1fr; }.base-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) { .quality-page { padding: 14px; }.page-header { display: block; }.header-badge { margin-top: 14px; }.summary-grid, .base-grid { grid-template-columns: 1fr; }.indicator-row { flex-wrap: wrap; }.range-separator { margin-left: 0; }.indicator-input { flex: 1; min-width: 105px; }.range-input { flex: 1; min-width: 75px; } }
</style>