快乐的昕的电脑
2025-10-22 3ffca8a163d8783896a2422ea03b746bc4b754db
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
<template>
    <div class="page">
        <div class="top-right">
            <button class="refresh-btn" @click="refresh">刷新</button>
        </div>
 
        <div class="middle-section">
            <div class="item" style="height:100px;">
                <h4>说明:先调机,再送检</h4>
            </div>
 
            <!-- 调机开始 -->
            <div class="item">
                <button :class="canStart ? 'btn-blue' : 'btn-disabled'"
                        :disabled="!canStart"
                        @click="onStartClick">
                    调机开始
                </button>
                <input class="txt-inp" v-model="maStartTime" placeholder="点击按钮带出时间" disabled />
            </div>
 
            <!-- 送检呼叫 -->
            <div class="item">
                <button :class="canShout ? 'btn-blue' : 'btn-disabled'"
                        :disabled="!canShout"
                        @click="onShoutClick">
                    送检呼叫
                </button>
                <input class="txt-inp" v-model="maShoutTime" placeholder="点击按钮带出时间" disabled />
            </div>
 
            <!-- 调机完成(后端合格自动写) -->
            <div class="item">
                <button class="btn-disabled" disabled>调机完成(=检验通过=开工)</button>
                <input class="txt-inp" v-model="maEndTime" placeholder="首次首检合格后写入" disabled />
            </div>
 
            <!-- 首检结果与提示 -->
            <div class="item" style="flex-direction:column;">
                <label>当前首检结果: {{ latestFirstResult || '未判定' }}</label>
                <label v-if="remark" style="color:#00A2E9">{{ remark }}</label>
            </div>
        </div>
 
        <!-- 底部操作 -->
        <div class="bottom-section">
            <button :class="hasUnsaved ? 'save-btn':'btn-disabled'"
                    :disabled="!hasUnsaved"
                    @click="save">
                保存并生效
            </button>
            <button class="cancel-btn" @click="cancel">取消</button>
        </div>
    </div>
</template>
 
<script>
    export default {
        props: {
            orderNo: String,
            orderId: Number,
            machineNo: String
        },
        data() {
            return {
                statusForm: {},
                maStartTime: '',
                maShoutTime: '',
                maEndTime: '',
                remark: '',
                latestFirstResult: '',
                // 原始快照
                origStart: '',
                origShout: '',
                origEnd: '',
                submitting: false
            };
        },
        computed: {
            canStart() {
                // 只在还没有开始时间时可点击
                return !this.maStartTime;
            },
            canShout() {
                // 有开始且目前没有送检时间时可呼叫
                return !!this.maStartTime && !this.maShoutTime;
            },
            hasUnsaved() {
                return (this.maStartTime !== this.origStart ||
                    this.maShoutTime !== this.origShout);
            }
        },
        created() {
            this.refresh();
        },
        methods: {
            getNow() {
                // 简易本地时间格式化,保持与后端需要的 yyyy-MM-dd HH:mm:ss 一致
                const pad = n => (n < 10 ? '0' + n : '' + n);
                const d = new Date();
                return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
            },
            onStartClick() {
                if (!this.canStart) return;
                this.maStartTime = this.getNow();
            },
            onShoutClick() {
                if (!this.canShout) return;
                this.maShoutTime = this.getNow();
            },
            refresh() {
                if (!this.orderId) return;
                this.$post({
                    url: "/MesOrderSta/FindByOrderNo",
                    data: { orderId: this.orderId, orderNo: this.orderNo }
                }).then(res => {
                    const d = res.data;
                    if (!d) return;
                    const sta = d.tbBillList || {};
                    this.statusForm = sta;
                    this.maStartTime = sta.maStartTime || '';
                    this.maShoutTime = sta.maShoutTime || '';
                    this.maEndTime = sta.maEndTime || '';
                    this.remark = sta.remark || d.remark || '';
                    this.latestFirstResult = sta.latestFirstResult || d.latestFirstResult || '';
                    this.syncOrig();
                    // 若后端因不合格清空送检时间,送检按钮会重新可用
                });
            },
            syncOrig() {
                this.origStart = this.maStartTime;
                this.origShout = this.maShoutTime;
                this.origEnd = this.maEndTime;
            },
            cancel() {
                this.maStartTime = this.origStart;
                this.maShoutTime = this.origShout;
                this.maEndTime = this.origEnd;
            },
            save() {
                if (!this.statusForm.id) {
                    this.$showMessage("状态ID为空,不能保存");
                    return;
                }
                if (!this.hasUnsaved) {
                    this.$showMessage("无变更");
                    return;
                }
                if (this.submitting) return;
                this.submitting = true;
                this.$post({
                    url: "/MesOrderSta/ChangeMachineTime",
                    data: {
                        id: this.statusForm.id,
                        // 按当前逻辑直接传已有时间,后端自行判定是开始还是送检
                        maStartTime: this.maStartTime || null,
                        maShoutTime: this.maShoutTime || null,
                        maEndTime: null, // 前端不主动写完成
                        orderId: this.orderId,
                        orderNo: this.orderNo,
                        machineNo: this.machineNo
                    }
                }).then(res => {
                    this.submitting = false;
                    if (res.data) {
                        const sta = res.data.tbBillList || {};
                        // 取回可能被后端清空或补写的字段
                        this.maStartTime = sta.maStartTime || '';
                        this.maShoutTime = sta.maShoutTime || '';
                        this.maEndTime = sta.maEndTime || '';
                        this.remark = sta.remark || res.data.remark || '';
                        this.latestFirstResult = sta.latestFirstResult || res.data.latestFirstResult || '';
                        this.syncOrig();
                        this.$showMessage("保存成功");
                    } else {
                        this.$showMessage("保存失败");
                    }
                }).catch(() => {
                    this.submitting = false;
                    this.$showMessage("网络异常");
                });
            }
        }
    };
</script>
 
<style scoped>
    .page {
        padding: 2vh;
        display: flex;
        flex-direction: column;
        height: 100%;
        box-sizing: border-box;
    }
 
    .top-right {
        position: absolute;
        top: 10px;
        right: 50px;
    }
 
    .refresh-btn {
        padding: 10px;
        background: #00A2E9;
        color: #fff;
        border: none;
        font-size: 1.5vw;
        border-radius: 5px;
    }
 
    .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-blue {
        background: #00A2E9;
        color: #fff;
    }
 
    .btn-disabled {
        background: #ccc;
        color: #fff;
    }
 
    .txt-inp {
        height: 8vh;
        padding: 1vh;
        font-size: 1.5vw;
        width: 100%;
        box-sizing: border-box;
        margin-left: 1vw;
    }
 
    .bottom-section {
        display: flex;
        justify-content: space-between;
        margin-top: 4vh;
    }
 
    .save-btn, .cancel-btn {
        width: 48%;
        padding: 1.5vh;
        background: #00A2E9;
        color: #fff;
        font-size: 1.6vw;
        border: none;
    }
 
    .cancel-btn {
        background: #0077A6;
    }
</style>