wbc
6 天以前 3897a86d1a714cca8087d589f55b00446679e48e
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<template>
    <view class="content">
        <!-- 头部标题 -->
        
 
        <!-- 表单区域 -->
        <view class="form-container">
            <!-- 查询工单 -->
            <view class="form-item">
                <text class="label">查询工单</text>
                <input class="input" type="text" v-model="formData.queryWorkOrder" placeholder="请输入查询工单" @input="onQueryWorkOrderChange" />
            </view>
 
            <!-- 生产工单 -->
            <view class="form-item">
                <text class="label">生产工单</text>
                <picker class="picker" :range="productionWorkOrderOptions" range-key="text" :value="productionWorkOrderIndex" @change="onProductionWorkOrderChange">
                    <view class="picker-content">
                        {{ productionWorkOrderOptions[productionWorkOrderIndex] ? productionWorkOrderOptions[productionWorkOrderIndex].text : '请选择/扫描生产工单' }}
                    </view>
                </picker>
                <view class="scan-icon" @click="scanProductionWorkOrder">
                    <uni-icons type="scan" size="24" color="#28a745"></uni-icons>
                </view>
            </view>
 
            <!-- 产品编码 -->
            <view class="form-item">
                <text class="label">产品编码</text>
                <view class="value">{{ formData.productCode }}</view>
            </view>
 
            <!-- 产品名称 -->
            <view class="form-item">
                <text class="label">产品名称</text>
                <view class="value">{{ formData.productName }}</view>
            </view>
 
            <!-- 工序 -->
            <view class="form-item">
                <text class="label">工序</text>
                <picker class="picker" :range="processOptions" range-key="text" :value="processIndex" @change="onProcessChange">
                    <view class="picker-content">
                        {{ processOptions[processIndex] ? processOptions[processIndex].text : '请选择/扫描工序' }}
                    </view>
                </picker>
                <view class="scan-icon" @click="scanProcess">
                    <uni-icons type="scan" size="24" color="#28a745"></uni-icons>
                </view>
            </view>
 
            <!-- 不良类型 -->
            <view class="form-item">
                <text class="label">不良类型</text>
                <picker class="picker" :range="defectTypeOptions" range-key="text" :value="defectTypeIndex" @change="onDefectTypeChange">
                    <view class="picker-content">
                        {{ defectTypeOptions[defectTypeIndex] ? defectTypeOptions[defectTypeIndex].text : '请选择/扫描不良类型' }}
                    </view>
                </picker>
                <view class="scan-icon" @click="scanDefectType">
                    <uni-icons type="scan" size="24" color="#28a745"></uni-icons>
                </view>
            </view>
 
            <!-- 不良项目 -->
            <view class="form-item">
                <text class="label">不良项目</text>
                <picker class="picker" :range="defectItemOptions" range-key="text" :value="defectItemIndex" @change="onDefectItemChange">
                    <view class="picker-content">
                        {{ defectItemOptions[defectItemIndex] ? defectItemOptions[defectItemIndex].text : '请选择/扫描不良项目' }}
                    </view>
                </picker>
                 <view class="scan-icon" @click="scanDefectItem">
                    <uni-icons type="scan" size="24" color="#28a745"></uni-icons>
                </view>
            </view>
 
            <!-- 不良条码 -->
            <view class="form-item">
                <text class="label">不良条码</text>
                <input class="input" type="text" v-model="formData.defectBarcode" placeholder="请输入不良条码" />
            </view>
 
            <!-- 条码数量 -->
            <view class="form-item">
                <text class="label">条码数量</text>
                <input class="input" type="number" v-model="formData.barcodeQuantity" placeholder="请输入条码数量" />
            </view>
 
            <!-- 提示信息 -->
            <view class="form-item">
                <text class="label">提示信息</text>
                <view class="value hint">{{ formData.hintInfo }}</view>
            </view>
        </view>
 
        <!-- 提交按钮 -->
        <view class="footer">
            <button class="submit-btn" @click="submitForm">登记提交</button>
        </view>
    </view>
</template>
 
<script>
import uniIcons from "@/components/uni-icons/uni-icons.vue"
 
export default {
    components: {uniIcons},
    data() {
        return {
            formData: {
                queryWorkOrder: '',
                productionWorkOrder: '',
                productCode: '',
                productName: '',
                process: '',
                defectType: '',
                defectItem: '',
                defectBarcode: '',
                barcodeQuantity: '',
                hintInfo: ''
            },
            productionWorkOrderOptions: [],
            productionWorkOrderIndex: -1,
            processOptions: [],
            processIndex: -1,
            defectTypeOptions: [],
            defectTypeIndex: -1,
            defectItemOptions: [],
            defectItemIndex: -1
        };
    },
    onLoad() {
        this.initData();
    },
    methods: {
        goBack() {
            uni.navigateBack();
        },
        initData() {
            // 预留API调用位置
            this.loadProductionWorkOrders();
            this.loadProcesses();
            this.loadDefectTypes();
            this.loadDefectItems();
        },
        loadProductionWorkOrders() {
            // 模拟API获取生产工单列表
            // this.$post({url: '/api/getWorkOrders'}).then(...)
            this.productionWorkOrderOptions = [
                {text: 'MO-20231201001', value: 'WO001'}, 
                {text: 'MO-20231201002', value: 'WO002'}
            ];
        },
        loadProcesses() {
            // 模拟API获取工序列表
             this.processOptions = [
                 {text: 'SMT贴片', value: 'P001'}, 
                 {text: 'DIP插件', value: 'P002'},
                 {text: '组装', value: 'P003'}
             ];
        },
        loadDefectTypes() {
             // 模拟API获取不良类型列表
             this.defectTypeOptions = [
                 {text: '物料不良', value: 'DT001'}, 
                 {text: '制程不良', value: 'DT002'}
             ];
        },
        loadDefectItems() {
             // 模拟API获取不良项目列表
             this.defectItemOptions = [
                 {text: '虚焊', value: 'DI001'}, 
                 {text: '短路', value: 'DI002'},
                 {text: '缺件', value: 'DI003'}
             ];
        },
        onQueryWorkOrderChange(e) {
            // 实时查询工单对应下拉框发生变化
            const query = this.formData.queryWorkOrder;
            console.log('Querying work orders with:', query);
            
            // 这里应该调用接口根据输入内容筛选生产工单
            // this.$post({url: '/api/searchWorkOrders', data: {keyword: query}}).then(...)
            
            // 模拟筛选
            if(query) {
                this.productionWorkOrderOptions = this.productionWorkOrderOptions.filter(item => item.text.includes(query));
            } else {
                this.loadProductionWorkOrders(); // 恢复默认列表
            }
        },
        onProductionWorkOrderChange(e) {
            this.productionWorkOrderIndex = e.target.value;
            const selected = this.productionWorkOrderOptions[this.productionWorkOrderIndex];
            if (selected) {
                this.formData.productionWorkOrder = selected.value;
                // 模拟根据工单带出产品信息
                this.formData.productCode = 'PROD-' + selected.value;
                this.formData.productName = '产品 ' + selected.text;
            }
        },
        onProcessChange(e) {
            this.processIndex = e.target.value;
            if (this.processOptions[this.processIndex]) {
                this.formData.process = this.processOptions[this.processIndex].value;
            }
        },
        onDefectTypeChange(e) {
            this.defectTypeIndex = e.target.value;
            if (this.defectTypeOptions[this.defectTypeIndex]) {
                this.formData.defectType = this.defectTypeOptions[this.defectTypeIndex].value;
            }
        },
        onDefectItemChange(e) {
            this.defectItemIndex = e.target.value;
            if (this.defectItemOptions[this.defectItemIndex]) {
                this.formData.defectItem = this.defectItemOptions[this.defectItemIndex].value;
            }
        },
        scanProductionWorkOrder() {
            uni.scanCode({
                success: (res) => {
                    console.log('Scanned:', res.result);
                    // 处理扫描结果,自动选中对应工单
                    uni.showToast({title: '扫描成功: ' + res.result, icon: 'none'});
                }
            });
        },
        scanProcess() {
             uni.scanCode({
                 success: (res) => {
                     console.log('Scanned Process:', res.result);
                     uni.showToast({title: '扫描成功: ' + res.result, icon: 'none'});
                 }
             });
        },
        scanDefectType() {
             uni.scanCode({
                 success: (res) => {
                     console.log('Scanned DefectType:', res.result);
                     uni.showToast({title: '扫描成功: ' + res.result, icon: 'none'});
                 }
             });
        },
        scanDefectItem() {
             uni.scanCode({
                 success: (res) => {
                     console.log('Scanned DefectItem:', res.result);
                     uni.showToast({title: '扫描成功: ' + res.result, icon: 'none'});
                 }
             });
        },
        submitForm() {
            console.log('Submitting:', this.formData);
            if (!this.formData.productionWorkOrder) {
                uni.showToast({title: '请选择生产工单', icon: 'none'});
                return;
            }
            // 提交逻辑
            // this.$post({url: '/api/submitDefect', data: this.formData}).then(...)
            
            uni.showToast({
                title: '登记提交成功',
                icon: 'success'
            });
        }
    }
};
</script>
 
<style>
.content {
    background-color: #f5f5f5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.page-header {
    background-color: #90CAF9; /* Light Blue */
    padding: 44px 15px 10px 15px; /* Status bar padding */
}
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.page-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
}
.header-right {
    color: #fff;
    font-size: 14px;
}
.form-container {
    background-color: #fff;
    margin-top: 0;
    flex: 1;
}
.form-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
}
.label {
    width: 90px;
    font-size: 15px;
    color: #333;
}
.input {
    flex: 1;
    font-size: 15px;
}
.value {
    flex: 1;
    font-size: 15px;
    color: #666;
}
.picker {
    flex: 1;
}
.picker-content {
    font-size: 15px;
    color: #333;
}
.scan-icon {
    width: 30px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: 10px;
    background-color: #4CD964; /* Green background for icon */
    border-radius: 4px;
}
.scan-icon uni-icons {
    /* Make icon white if background is green, but uni-icons color prop handles it */
}
/* Override uni-icons color to white since background is green */
.scan-icon ::v-deep span {
    color: #fff !important; 
}
 
.footer {
    padding: 20px;
}
.submit-btn {
    background-color: #7B68EE; /* Purple */
    color: #fff;
    border-radius: 5px;
    font-size: 16px;
    height: 44px;
    line-height: 44px;
}
.hint {
    color: #999;
}
</style>