spring
5 天以前 755e7038caf74126eb4d696ef88f11f0871ff0ee
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<template>
  <view class="form-container">
    <view class="dialog-header">
      <text class="dialog-title">{{ isEdit ? "编辑自检" : "新增自检" }}</text>
      <wd-icon name="close" class="close-icon" @click="handleClose"></wd-icon>
    </view>
    <view class="dialog-content">
      <wd-form ref="formRef" :model="formData">
        <!-- 基本信息 -->
        <view class="section-title">基本信息</view>
        <wd-cell-group border>
          <wd-input
            v-model="formData.fixedInfo.firstNo"
            label="首检单号"
            label-width="120px"
            placeholder="请输入首检单号"
          />
          <wd-input
            v-model="formData.fixedInfo.lastSlot"
            label="定径模具"
            label-width="120px"
            placeholder="请输入定径模具"
          />
        </wd-cell-group>
 
        <!-- 单丝直径 -->
        <view class="section-title">单丝直径(mm)</view>
        <wd-cell-group border>
          <wd-cell title="最大值" label-width="120px">
            <wd-input-number
              v-model="formData.inspectionResult.maxDia"
              :min="0"
              :precision="3"
              :step="0.01"
              placeholder="请输入最大值"
              :max="
                formData.inspectionResult.minDia !== null &&
                formData.inspectionResult.minDia !== undefined
                  ? undefined
                  : 999999
              "
            />
          </wd-cell>
          <wd-cell title="最小值" label-width="120px">
            <wd-input-number
              v-model="formData.inspectionResult.minDia"
              :min="0"
              :precision="3"
              :step="0.01"
              placeholder="请输入最小值"
              :max="
                formData.inspectionResult.maxDia !== null &&
                formData.inspectionResult.maxDia !== undefined
                  ? formData.inspectionResult.maxDia
                  : 999999
              "
            />
          </wd-cell>
        </wd-cell-group>
 
        <!-- 外观 -->
        <view class="section-title">外观</view>
        <wd-cell-group border>
          <wd-cell title="外观质量" label-width="120px">
            <view class="checkbox-group">
              <wd-checkbox
                v-for="option in appearanceOptions"
                :key="option.value"
                :modelValue="
                  Array.isArray(formData.inspectionResult.appearance)
                    ? formData.inspectionResult.appearance.includes(String(option.value))
                    : false
                "
                shape="square"
                @change="(val) => handleAppearanceChange(String(option.value), val)"
              >
                {{ option.label }}
              </wd-checkbox>
            </view>
          </wd-cell>
        </wd-cell-group>
 
        <!-- 成盘质量 -->
        <view class="section-title">成盘质量</view>
        <wd-cell-group border>
          <wd-cell title="卷绕紧密" label-width="120px">
            <wd-radio-group v-model="formData.inspectionResult.windingTightness" size="small">
              <wd-radio value="是">是</wd-radio>
              <wd-radio value="否">否</wd-radio>
            </wd-radio-group>
          </wd-cell>
          <wd-cell title="排列整齐" label-width="120px">
            <wd-radio-group v-model="formData.inspectionResult.arrangementNeatness" size="small">
              <wd-radio value="是">是</wd-radio>
              <wd-radio value="否">否</wd-radio>
            </wd-radio-group>
          </wd-cell>
          <wd-cell title="外层铝线离侧板边缘距离(mm)" label-width="200px">
            <wd-input-number
              v-model="formData.inspectionResult.aluminumWireDistance"
              :min="0"
              :precision="0"
              placeholder="请输入距离"
              :class="{ 'text-danger': formData.inspectionResult.aluminumWireDistance < 25 }"
            />
          </wd-cell>
        </wd-cell-group>
 
        <!-- 其他信息 -->
        <view class="section-title">其他信息</view>
        <wd-cell-group border>
          <wd-cell title="成品模后接头情况" label-width="120px">
            <wd-radio-group v-model="formData.inspectionResult.jointCondition" size="small">
              <wd-radio value="有">有</wd-radio>
              <wd-radio value="无">无</wd-radio>
            </wd-radio-group>
          </wd-cell>
          <wd-cell title="结论" label-width="120px">
            <wd-radio-group v-model="formData.inspectionResult.conclusion" size="small">
              <wd-radio value="合格">合格</wd-radio>
              <wd-radio value="不合格">不合格</wd-radio>
            </wd-radio-group>
          </wd-cell>
        </wd-cell-group>
      </wd-form>
    </view>
    <view class="dialog-footer">
      <wd-button plain @click="handleClose" style="margin-right: 10px">取消</wd-button>
      <wd-button type="primary" class="ml-2" @click="handleSubmit">保存</wd-button>
    </view>
  </view>
</template>
 
<script setup lang="ts">
import { ref, watch, computed } from "vue";
import { dayjs } from "wot-design-uni";
 
const props = defineProps<{
  visible: boolean;
  formData: any;
  appearanceOptions: Array<{ label: string; value: string | number }>;
  previousAppearanceValue?: string[];
}>();
 
const emit = defineEmits<{
  (e: "update:visible", value: boolean): void;
  (e: "submit", data: any): void;
  (e: "close"): void;
}>();
 
const formRef = ref();
const isEdit = computed(() => !!props.formData?.id && !props.formData?.isNew);
 
// 存储前一个外观质量值
const previousAppearanceValue = ref<string[]>(props.previousAppearanceValue || []);
 
// 处理外观质量互斥逻辑
const handleAppearanceQualityChange = (
  selectedValues: string[],
  previousValues: string[],
  allOptions: Array<{ label: string; value: string | number }>
): string[] => {
  if (!allOptions || allOptions.length === 0) {
    return selectedValues;
  }
 
  const noIssueOption = allOptions.find(
    (item) => item.label === "无外观问题" || item.value === "无外观问题"
  );
 
  if (!noIssueOption) {
    return selectedValues;
  }
 
  const noIssueValue = String(noIssueOption.value);
  const hasNoIssue = selectedValues.includes(noIssueValue);
  const hadNoIssue = previousValues.includes(noIssueValue);
  const isNewlySelectedNoIssue = !hadNoIssue && hasNoIssue;
  const isSelectingOtherWithNoIssue =
    hadNoIssue && hasNoIssue && selectedValues.length > previousValues.length;
 
  let result: string[];
  if (isNewlySelectedNoIssue) {
    result = [noIssueValue];
  } else if (isSelectingOtherWithNoIssue) {
    result = selectedValues.filter((val) => val !== noIssueValue);
  } else {
    result = selectedValues;
  }
 
  return result;
};
 
// 处理外观选择变化
const handleAppearanceChange = (optionValue: string, checked: boolean) => {
  const currentValues = Array.isArray(props.formData.inspectionResult.appearance)
    ? props.formData.inspectionResult.appearance
    : [];
 
  let newValues: string[];
  if (checked) {
    newValues = [...currentValues, optionValue];
  } else {
    newValues = currentValues.filter((v: string) => v !== optionValue);
  }
 
  const processedValues = handleAppearanceQualityChange(
    newValues,
    previousAppearanceValue.value,
    props.appearanceOptions
  );
 
  props.formData.inspectionResult.appearance = JSON.parse(JSON.stringify(processedValues));
  previousAppearanceValue.value = JSON.parse(JSON.stringify(processedValues));
};
 
const handleClose = () => {
  emit("update:visible", false);
  emit("close");
};
 
const handleSubmit = () => {
  // 验证单丝直径:最大值应该大于或等于最小值
  const maxDia = props.formData.inspectionResult.maxDia;
  const minDia = props.formData.inspectionResult.minDia;
 
  if (maxDia !== null && minDia !== null && maxDia < minDia) {
    uni.showToast({
      title: "单丝直径最大值不能小于最小值",
      icon: "none",
    });
    return;
  }
 
  // 验证外层铝线离侧板边缘距离
  const aluminumWireDistance = props.formData.inspectionResult.aluminumWireDistance;
  if (aluminumWireDistance < 25) {
    uni.showToast({
      title: "外层铝线离侧板边缘距离不能低于25mm",
      icon: "none",
    });
    return;
  }
 
  emit("submit", props.formData);
};
 
// 监听 visible 变化,初始化 previousAppearanceValue
watch(
  () => props.visible,
  (newVal) => {
    if (newVal && props.formData?.inspectionResult?.appearance) {
      previousAppearanceValue.value = JSON.parse(
        JSON.stringify(props.formData.inspectionResult.appearance || [])
      );
    }
  }
);
</script>
 
<style lang="scss" scoped>
.form-container {
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px 12px 0 0;
}
 
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #e6e6e6;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
}
 
.dialog-title {
  font-size: 16px;
  color: #333;
  font-weight: 500;
}
 
.close-icon {
  font-size: 20px;
  color: #999;
  padding: 4px;
}
 
.dialog-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
 
.section-title {
  font-size: 14px;
  font-weight: 700;
  color: #252525;
  margin: 16px 0 8px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid #e6e6e6;
}
 
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
 
:deep(.wd-checkbox) {
  margin-right: 0;
}
 
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  padding: 16px;
  border-top: 1px solid #e6e6e6;
  gap: 8px;
}
 
.text-danger {
  :deep(.wd-input-number__input) {
    color: #f56c6c;
    border-color: #f56c6c;
  }
}
</style>