快乐的昕的电脑
2025-10-22 ce68dfc0281f848edb71042f001e69a0e1c79ed4
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<template>
    <view class="page">
        <!--调机送检-->
        <!-- 右上角刷新按钮 -->
        <view class="top-right">
            <button class="refresh-btn" @click="refresh">刷新</button>
        </view>
 
        <!-- 中间状态部分,上下结构,包含调机流程的三个步骤 -->
        <view class="middle-section">
            <view class="item" style="height: 100px;">
                <h4>说明:先调机,再送检</h4>
            </view>
            <view class="item">
                <!-- 调机开始按钮,maStartTime有值时禁用 -->
                <button :class="maStartTime ? 'btn-disabled' : 'btn-blue'"
                        :disabled="!!maStartTime"
                        @click="handleMaStartTime">
                    调机开始
                </button>
                <!-- 显示调机开始时间 -->
                <input class="txt-inp" v-model="maStartTime" placeholder="点击按钮带出时间" disabled="true" />
            </view>
            <view class="item">
                <!-- 送检呼叫按钮,maShoutTime有值时禁用 -->
                <!-- 新增逻辑: 只有已填写调机开始时间且送检呼叫时间为空时才允许点击 -->
                <button :class="canShout ? 'btn-blue' : 'btn-disabled'"
                        :disabled="!canShout"
                        @click="handleMaShoutTime">
                    送检呼叫
                </button>
                <!-- 显示送检呼叫时间 -->
                <input class="txt-inp" v-model="maShoutTime" placeholder="点击按钮带出时间" disabled="true" />
            </view>
            <!--<view class="item">-->
            <!-- 调机完成按钮,maEndTime有值时禁用 -->
            <!--<button :class="maEndTime ? 'btn-disabled' : 'btn-blue'"
                    :disabled="!!maEndTime"
                    @click="handleMaEndTime">
                调机完成(=检验通过)
            </button>-->
            <!-- 显示调机完成时间 -->
            <!--<input class="txt-inp" v-model="maEndTime" placeholder="首次首检确认通过写入" disabled="true" />
            </view>-->
            <view class="item">
                <button class="btn-disabled" disabled>
                    调机完成(=检验通过=开工)
                </button>
                <input class="txt-inp" v-model="maEndTime" placeholder="首次首检确认通过写入" disabled="true" />
            </view>
 
            <!-- 新增: 首检结果与提示区域(不删除原有注释,仅新增) -->
            <view class="item" style="flex-direction: column;">
                <label>当前首检结果: {{ latestFirstResult || '未判定' }}</label>
                <label v-if="statusForm.remark" style="color:#00A2E9">{{ statusForm.remark }}</label>
                <label v-if="showForceRebuild" style="color:#d9534f">首检不合格,系统已按后端策略可能自动重建,新单待检。</label>
            </view>
 
            <!-- 新增: 强制重建按钮(可选,传 ForceRebuild=true) -->
            <view class="item" v-if="showForceRebuild">
                <button :class="forceRebuilding ? 'btn-disabled':'btn-blue'"
                        :disabled="forceRebuilding"
                        @click="handleForceRebuild">
                    {{ forceRebuilding ? '重建中...' : '强制重建首检单' }}
                </button>
            </view>
        </view>
 
        <!-- 底部保存/取消按钮 -->
        <view class="bottom-section">
            <!-- 只有调机完成未填写时才可保存 -->
            <button class="save-btn" v-if="!maEndTime" @click="save">保存并生效</button>
            <!-- 已完成时保存按钮禁用 -->
            <button class="btn-disabled" v-else>保存并生效</button>
            <button class="cancel-btn" @click="cancel">取消</button>
        </view>
 
    </view>
</template>
 
<script>
    export default {
        props: {
            orderNo: String,    // 工单号
            orderId: Number,    // 工单ID
            machineNo: String   // 机台号
        },
        data() {
            return {
                maShoutTime: '',   // 送检呼叫时间
                maStartTime: '',   // 调机开始时间
                maEndTime: '',     // 调机完成时间
                statusForm: {},    // 工单状态表单数据
                flag: -1,          // 操作标记
                // 新增: 记录原始数据库时间用于对比避免无变化重复提交
                origMaStartTime: '',
                origMaShoutTime: '',
                origMaEndTime: '',
                // 新增: 最新首检结果(后端需在 FindByOrderNo 返回)
                latestFirstResult: '',
                // 新增: 强制重建状态
                forceRebuilding: false
            }
        },
        computed: {
            // 只有调机开始时间已填写且送检呼叫时间为空时允许呼叫
            canShout() {
                return !!this.maStartTime && !this.maShoutTime;
            },
            // 新增: 是否显示强制重建按钮
            showForceRebuild() {
                return this.latestFirstResult === '不合格';
            }
        },
        created() {
            // 组件创建时自动加载工单数据
            if (!this.orderId && !this.orderNo) {
                return;
            }
            this.findByOrderId();
        },
        methods: {
            // 处理调机开始按钮点击
            handleMaStartTime() {
                if (!this.maStartTime) {
                    this.setMaStartTime();
                    this.flag = -1; // 调机开始按钮按下时回传的flag=-1
                    // 新增: 调机开始后立即提交写入(仅当与原值不同)
                    this.autoSubmitIfChanged();
                }
            },
            // 处理送检呼叫按钮点击
            handleMaShoutTime() {
                // 增加前置校验:必须先有调机开始时间
                if (!this.maStartTime) {
                    this.$showMessage("请先点击调机开始");
                    return;
                }
                if (!this.maShoutTime) {
                    this.stateCheck(1);
                    // 新增: 送检呼叫生成时间后立即提交(不合格会触发后端重建)
                    this.autoSubmitIfChanged();
                }
            },
            // 处理调机完成按钮点击
            handleMaEndTime() {
                if (!this.maEndTime) {
                    this.setMaEndTime();
                    // 新增: 完成时间写入后提交
                    this.autoSubmitIfChanged();
                }
            },
            // 设置调机开始时间为当前时间
            setMaStartTime() {
                this.maStartTime = this.$getDate('yyyy-mm-dd hh24:mi:ss');
            },
            // 设置调机完成时间为当前时间
            setMaEndTime() {
                console.log('调机完成按钮被点击');
                this.maEndTime = this.$getDate('yyyy-mm-dd hh24:mi:ss');
            },
            // 刷新工单数据
            refresh() {
                this.findByOrderId();
            },
            // 全界面刷新:清空本地状态后重新拉取(不删除任何原有注释)
            fullReload() {
                // 清空当前显示数据,避免旧数据短暂闪烁
                this.maShoutTime = '';
                this.maStartTime = '';
                this.maEndTime = '';
                this.statusForm = {};
                this.flag = -1;
                // 下一帧重新获取
                this.$nextTick(() => {
                    this.findByOrderId();
                });
            },
            // 保存并生效,将时间等信息提交到后端
            save() {
                if (!this.statusForm.id) {
                    this.$showMessage("id为空,不允许推送");
                    return;
                }
                // 新增: 若无变化则不调用后端,避免重复重建
                if (!this.hasTimeChanged()) {
                    this.$showMessage("无时间变化,未提交");
                    return;
                }
                this.postChangeMachineTime().then(ok => {
                    if (ok) {
                        this.$showMessage("保存成功");
                        this.syncOriginalTimes();
                        this.findByOrderId(); // 刷新显示
                    } else {
                        this.$showMessage("呼叫失败");
                        this.cancel();
                    }
                });
            },
            // 取消操作,恢复为上次保存的数据
            cancel() {
                this.maShoutTime = this.origMaShoutTime;
                this.maStartTime = this.origMaStartTime;
                this.maEndTime = this.origMaEndTime;
            },
            // 送检呼叫,item=1时设置送检呼叫时间
            stateCheck(item) {
                switch (item) {
                    case 0:
                        break;
                    case 1:
                        this.maShoutTime = this.$getDate('yyyy-mm-dd hh24:mi:ss');
                        this.flag = -1; // 送检呼叫有值后,flag始终为-1
                        break;
                    case 2:
                        break;
                }
                this.flag = item;
            },
            // 新增: 判断时间是否有变化
            hasTimeChanged() {
                return this.maStartTime !== this.origMaStartTime ||
                    this.maShoutTime !== this.origMaShoutTime ||
                    this.maEndTime !== this.origMaEndTime;
            },
            // 新增: 自动提交(按钮生成时间后调用)仅在有变化时
            autoSubmitIfChanged() {
                if (!this.statusForm.id) return;
                if (!this.hasTimeChanged()) return;
                this.postChangeMachineTime().then(ok => {
                    if (ok) {
                        this.$showMessage("提交成功");
                        this.syncOriginalTimes();
                        this.findByOrderId();
                    }
                });
            },
            // 新增: 同步原始时间快照
            syncOriginalTimes() {
                this.origMaStartTime = this.maStartTime;
                this.origMaShoutTime = this.maShoutTime;
                this.origMaEndTime = this.maEndTime;
            },
            // 新增: 强制重建触发
            handleForceRebuild() {
                if (!this.statusForm.id) {
                    this.$showMessage("id为空,不允许重建");
                    return;
                }
                this.forceRebuilding = true;
                // 强制重建前可以重新生成送检时间(确保首检单新快照)
                this.maShoutTime = this.$getDate('yyyy-mm-dd hh24:mi:ss');
                this.postChangeMachineTime(true).then(ok => {
                    this.forceRebuilding = false;
                    if (ok) {
                        this.$showMessage("强制重建成功");
                        this.syncOriginalTimes();
                        this.findByOrderId();
                    } else {
                        this.$showMessage("强制重建失败");
                    }
                });
            },
            // 新增: 封装后端请求(支持 ForceRebuild)
            postChangeMachineTime(forceRebuild = false) {
                return this.$post({
                    url: "/MesOrderSta/ChangeMachineTime",
                    data: {
                        maStartTime: this.maStartTime,
                        maShoutTime: this.maShoutTime,
                        maEndTime: this.maEndTime,
                        id: this.statusForm.id,
                        orderId: this.orderId,
                        orderNo: this.orderNo,
                        machineNo: this.machineNo,
                        flag: this.flag,
                        // 可选扩展字段(后端方法中动态接收)
                        //ForceRebuild: forceRebuild
                    }
                }).then(res => {
                    // 后端返回结构假设:{ success:true/false, tbBillList: {...}, latestFirstResult:'合格/不合格' }
                    if (res.data) {
                        if (res.data.tbBillList) {
                            this.statusForm = res.data.tbBillList;
                            this.latestFirstResult = res.data.latestFirstResult || '';
                        }
                        return res.data.success !== false; // 默认成功
                    }
                    return false;
                }).catch(() => false);
            },
            // 根据工单号/ID获取工单状态数据
            findByOrderId() {
                this.$post({
                    url: "/MesOrderSta/FindByOrderNo",
                    data: {
                        orderId: this.orderId,
                        orderNo: this.orderNo
                    }
                }).then(res => {
                    this.statusForm = res.data.tbBillList;
                    this.maShoutTime = res.data.tbBillList.maShoutTime;
                    this.maStartTime = res.data.tbBillList.maStartTime;
                    this.maEndTime = res.data.tbBillList.maEndTime;
                    // 新增: 同步首检结果、原始时间快照
                    this.latestFirstResult = res.data.tbBillList.latestFirstResult || res.data.latestFirstResult || '';
                    this.syncOriginalTimes();
                })
            }
        }
    };
</script>
 
<style scoped>
    /* 页面整体布局 */
    .page {
        padding: 2vh;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        box-sizing: border-box;
        height: 100%;
    }
 
    /* 右上角刷新按钮 */
    .top-right {
        position: absolute;
        top: 10px;
        right: 50px;
        z-index: 1000;
    }
 
    .refresh-btn {
        padding: 10px;
        background-color: #00A2E9;
        color: white;
        border: none;
        font-size: 1.5vw;
        border-radius: 5px;
    }
 
    label {
        margin-right: 1vw;
        font-size: 1.6vw;
    }
 
    input {
        padding: 1vh;
        font-size: 1.5vw;
        border: 1px solid #ccc;
        width: 100%;
        margin-top: 1vh;
        box-sizing: border-box;
    }
 
    /* 中间状态部分布局 */
    .middle-section {
        display: flex;
        flex-direction: column;
        margin-bottom: 4vh;
    }
 
    .item {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        margin-bottom: 2vh;
    }
 
    button {
        width: 100%;
        padding: 1.5vh;
        font-size: 1.5vw;
        border: none;
        text-align: center;
    }
 
    .btn-disabled {
        background-color: #ccc;
        color: white;
    }
 
    .btn-blue {
        background-color: #00A2E9;
        color: white;
    }
 
    input {
        margin-top: 10px;
        padding: 10px;
        font-size: 14px;
        border: 1px solid #ccc;
        width: 100%;
    }
 
    /* 底部保存/取消按钮布局 */
    .bottom-section {
        display: flex;
        justify-content: space-between;
        margin-top: 4vh;
    }
 
    .save-btn,
    .cancel-btn {
        width: 48%;
        padding: 1.5vh;
        background-color: #00A2E9;
        color: white;
        font-size: 1.6vw;
        border: none;
        text-align: center;
    }
 
    .txt-inp {
        height: 8vh;
        padding: 1vh;
        font-size: 1.5vw;
        width: 100%;
        box-sizing: border-box;
    }
</style>