chenhaozhe
2026-01-19 0f6129b8c60607ddf4571f00a6e1fff5bc82fafd
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<template>
    <view class="content">
        <view class="list" v-for="(item,index) in listData" :key="index">
            <uni-card :title="'工单号:'+item.HICMOBillNo" :extra="'日期:'+item.计划日期" style="margin: 10px;" @tap="edit(item)">
                <view class="card-detail">
                    <view class="detail" v-if="item.HMaterName" style="width: 100%;">
                        <text>产品名称:</text>{{item.HMaterName}}
                    </view>
                    <view class="detail" v-if="item.HModel" style="width: 100%;">
                        <text>产品型号:</text>{{item.HModel}}
                    </view>
                    <view class="detail">
                        <text>计划数量:</text>{{item.HDatePlanQty?item.HDatePlanQty:0}}
                    </view>
                    <view class="detail">
                        <text>汇报总数:</text>{{item.HDateFinishQty?item.HDateFinishQty:0}}
                    </view>
                    <view class="detail" v-if="item.HICMOStatus">
                        <text>当前状态:</text>{{item.HICMOStatus}}
                    </view>
                    <view class="detail" v-if="item.领料状态">
                        <text>领料状态:</text>{{item.领料状态}}
                    </view>
                    <view class="detail" style="width: 100%;display: flex;align-items: center;">
                        <text>生产进度:</text>
                        <zui-progress-bar :value="item.percent" :width="210" type="follow-left"/>
                    </view>
                </view>
            </uni-card>
        </view>
        <uni-popup ref="popup" background-color="#fff">
            <view class="popup-content">
                <view class="tit">异常类型</view>
                <view class="item" v-for="(item,index) in popList" :key="index" @tap="toAbnm(item)">{{item}}</view>
            </view>
        </uni-popup>
        <view class="over" v-if="listData.length == 0">暂无数据</view>
        <view class="over" v-if="listData.length != 0">已到底</view>
    </view>
</template>
 
<script>
    import { getUserInfo } from "@/utils/auth.js";
    export default {
        data() {
            return {
                userInfo:getUserInfo(),
                serverUrl: uni.getStorageSync('serverUrl')||'http://47.96.97.237/API',
                HSourceID:'',
                HSourceName:'',
                number:1,
                listData:[],
                chooseIt:'',
                popList:['人员原因', '设备原因', '材料原因', '工艺原因', '模具原因', '测试原因', '环境原因'],
                // 定义操作映射配置
                actionConfig: {
                    '开工': {
                        apiUrl: '/Sc_MESBeginWorkBill/FastBeginWorkBill',
                        type: '开工',
                        handler: 'handleBegin',
                        checkStatus: true, // 需要检查状态
                        denyMsg: '单据状态不满足开工条件!' // 固定错误提示
                    },
                    '完工': {
                        apiUrl: '/Sc_MESEndWorkBill/FastEndWorkBill',
                        type: '完工',
                        handler: 'handleEnd',
                        checkStatus: true,
                        denyMsg: '单据状态不满足完工条件!' // 固定错误提示
                    },
                    '停工': {
                        apiUrl: '/Sc_MESStopWorkBill/FastStopWorkBill',
                        type: '停工',
                        handler: 'handleStop',
                        checkStatus: true,
                        denyMsg: '单据状态不满足停工条件!' // 固定错误提示
                    },
                    '异常反馈': {
                        apiUrl: '',
                        type: '异常反馈',
                        handler: 'handleAbnormal',
                        checkStatus: true,
                        denyMsg: '单据状态不满足异常反馈条件!' // 固定错误提示
                    }
                }
            }
        },
        onLoad(e) {
            console.log(e)
            uni.showLoading({
                title:'加载中...'
            })
            this.HSourceName=e.HSourceName
            this.HSourceID=e.HSourceID
            this.getList(e.HSourceID)
        },
        onPullDownRefresh: function() {
            this.getList(this.HSourceID)
            setTimeout(()=>{
                uni.stopPullDownRefresh();
            }, 1000);
        },
        methods: {
            getList(e){
                uni.request({
                    url: this.serverUrl + '/ReportPlatForm/SearchGetWorkBillList',
                    data: { "HSourceID": e },
                    success: (res) => {
                        if(res.data.count == 1){
                            console.log(res.data.data.h_p_JIT_GetWorkBillListInfoBySource)
                            this.listData = res.data.data.h_p_JIT_GetWorkBillListInfoBySource
                            for(var i=0;i<this.listData.length;i++){
                                this.listData[i].percent = (this.listData[i].HDateFinishQty / this.listData[i].HDatePlanQty).toFixed(4)
                            }
                            setTimeout(()=>{
                                uni.hideLoading()
                            }, 1000);
                        }else{
                            setTimeout(()=>{
                                uni.hideLoading()
                            }, 1000);
                            uni.showToast({
                                title:'获取列表出错!',
                                icon:'none'
                            })
                        }
                    },
                    fail: (res) => {
                        console.log(res);
                        setTimeout(()=>{
                            uni.hideLoading()
                        }, 1000);
                        uni.showToast({
                            title:'获取列表接口请求失败',
                            icon:'none'
                        })
                    },
                });
            },
            toAbnm(item){
                console.log(item,this.chooseIt)
                this.$refs.popup.close()
                uni.navigateTo({
                    url:'./OA_ErrMsgBackBill?HICMOBillNo=' + this.chooseIt.HICMOBillNo
                         +'&HSourceName=' + this.HSourceName
                         +'&HSourceBillNo=' + this.chooseIt.HSourceBillNo
                         +'&HType=' + item
                         +'&OperationType=4&linterid=&HSouceBillType='
                })
            },
            edit(item){
                console.log(item)
                this.chooseIt = item
                
                // 使用对象映射配置生成可用的操作列表
                const availableActions = Object.keys(this.actionConfig)
                
                uni.showActionSheet({
                    itemList: availableActions,
                    success: (res)=> {
                        const actionKey = availableActions[res.tapIndex]
                        const actionConfig = this.actionConfig[actionKey]
                        
                        // 调用对应的处理方法
                        this[actionConfig.handler](item, actionConfig)
                    },
                    fail: function (res) {
                        console.log(res.errMsg);
                    }
                });
            },
            // 开工处理
            handleBegin(item, config) {
                const upData = this.createUpData(item)
                this.checkAndExecuteWorkStatus(
                    item, 
                    config, 
                    config.apiUrl, 
                    upData
                )
            },
            // 完工处理
            handleEnd(item, config) {
                const upData = this.createUpData(item)
                this.checkAndExecuteWorkStatus(
                    item, 
                    config, 
                    config.apiUrl, 
                    upData
                )
            },
            // 停工处理
            handleStop(item, config) {
                const upData = this.createUpData(item)
                this.checkAndExecuteWorkStatus(
                    item, 
                    config, 
                    config.apiUrl, 
                    upData
                )
            },
            // 异常反馈处理
            handleAbnormal(item, config) {
                const sWhere = { 
                    "HSourceID": this.HSourceID, 
                    "HICMOBillNo": item.HICMOBillNo, 
                    "HInterID": item.HSourceInterID,
                    "type": config.type
                }
                
                uni.request({
                    url: this.serverUrl + '/Sc_MESBeginWorkBill/GetMESBeginWorkBillStaus',
                    type: "GET",
                    data: { "sWhere": JSON.stringify(sWhere) },
                    dataType: "json",
                    async: false,
                    success: (res) => {
                        console.log('异常反馈状态检查:', res.data)
                        // 根据第二个页面的逻辑:如果count>0,表示不允许操作
                        if (res.data.count > 0) {
                            // 不允许操作,显示错误提示
                            const status = item.HICMOStatus || '未知状态'
                            uni.showToast({
                                title: `工单【${item.HICMOBillNo}】当前状态为【${status}】,${config.denyMsg}`,
                                icon:'none',
                                duration: 3000
                            })
                        }
                        else {
                            // count<=0,表示允许操作
                            this.$refs.popup.open('center')
                        }
                    },
                    fail: (res) => {
                        console.log(res)
                        uni.hideLoading()
                        uni.showToast({
                            title:'接口请求失败',
                            icon:'none'
                        })
                    },
                })
            },
            // 创建通用的请求数据
            createUpData(item) {
                return {
                    HBillType: item.HBillType,
                    HSourceInterID: item.HSourceInterID, 
                    HSourceEntryID: item.HSourceEntryID, 
                    HSourceBillNo: item.HSourceBillNo, 
                    HSourceBillType: item.HSourceBillType, 
                    user: uni.getStorageSync('HUserName')
                }
            },
            // 通用的检查和执行方法
            checkAndExecuteWorkStatus(item, config, apiUrl, upData) {
                const sWhere = { 
                    "HSourceID": this.HSourceID, 
                    "HICMOBillNo": item.HICMOBillNo, 
                    "HInterID": item.HSourceInterID,
                    "type": config.type
                }
                
                console.log('状态检查参数:', JSON.stringify(sWhere))
                
                uni.request({
                    url: this.serverUrl + '/Sc_MESBeginWorkBill/GetMESBeginWorkBillStaus',
                    type: "GET",
                    data: { "sWhere": JSON.stringify(sWhere) },
                    dataType: "json",
                    async: false,
                    success: (res) => {
                        console.log('状态检查结果:', res.data)
                        // 根据第二个页面的逻辑:如果data.count>0,表示不允许操作
                        if (res.data.count > 0) {
                            // 不允许操作,显示错误提示
                            const status = item.HICMOStatus || '未知状态'
                            const operationMap = {
                                '开工': '开工',
                                '完工': '完工',
                                '停工': '停工',
                                '异常反馈': '异常反馈'
                            }
                            const operationName = operationMap[config.type] || config.type
                            
                            // 根据操作类型给出不同的建议
                            let suggestion = ''
                            switch(config.type) {
                                case '开工':
                                    suggestion = '开工操作需要工单状态为"待生产"或"挂起"状态,请检查当前状态是否符合要求'
                                    break
                                case '完工':
                                    suggestion = '完工操作需要工单处于"生产中"状态,请检查当前状态是否符合要求'
                                    break
                                case '停工':
                                    suggestion = '停工操作需要工单处于"生产中"状态,请检查当前状态是否符合要求'
                                    break
                                case '异常反馈':
                                    suggestion = '异常反馈需要工单处于"生产中"或"开工"状态,请检查当前状态是否符合要求'
                                    break
                                default:
                                    suggestion = '请检查工单状态是否符合操作要求'
                            }
                            
                            uni.showToast({
                                title: `工单【${item.HICMOBillNo}】当前状态为【${status}】,无法进行【${operationName}】操作。\n${suggestion}`,
                                icon:'none',
                                duration: 4000
                            })
                        }
                        else {
                            // data.count<=0,表示允许操作
                            this.showConfirmDialog(config.type, item, apiUrl, upData)
                        }
                    },
                    fail: (res) => {
                        console.log(res)
                        uni.hideLoading()
                        uni.showToast({
                            title:'状态检查接口请求失败',
                            icon:'none'
                        })
                    },
                })
            },
            // 显示确认对话框
            showConfirmDialog(actionType, item, apiUrl, upData) {
                // 获取当前工单状态显示在确认框中
                const status = item.HICMOStatus || '未知状态'
                
                uni.showModal({
                    title: actionType + '确认',
                    content: `设备:${this.HSourceName}\n工单:${item.HICMOBillNo}\n产品:${item.HMaterName}\n当前状态:${status}\n\n确定要执行【${actionType}】操作吗?`,
                    success: (res) => {
                        if (res.confirm) {
                            console.log('用户点击确定')
                            this.executeWork(apiUrl, upData, item, actionType)
                        } else if (res.cancel) {
                            console.log('用户点击取消')
                        }
                    }
                })
            },
            // 执行工作操作
            executeWork(apiUrl, upData, item, actionType) {
                uni.showLoading({
                    title:`正在${actionType}...`
                })
                
                console.log('执行操作参数:', upData)
                
                uni.request({
                    url: this.serverUrl + apiUrl,
                    data: upData,
                    success: (res) => {
                        console.log('执行操作结果:', res)
                        if(res.data.count == 1){
                            // 操作成功后刷新列表
                            this.getList(this.HSourceID)
                            uni.showToast({
                                title:`${actionType}成功!`,
                                icon:'success'
                            })
                        }else{
                            uni.hideLoading()
                            // 显示更详细的操作失败提示
                            let errorMsg = res.data.Message || `${actionType}失败`
                            uni.showToast({
                                title: `${actionType}失败:${errorMsg}`,
                                icon:'none',
                                duration: 3000
                            })
                        }
                    },
                    fail: (res) => {
                        console.log(res)
                        uni.hideLoading()
                        uni.showToast({
                            title:`${actionType}接口请求失败,请检查网络`,
                            icon:'none'
                        })
                    },
                })
            },
            changeTab(e){
                this.number = e
                if(e==1){
                    this.listData = this.listData1
                }else{
                    this.listData = this.listData2
                }
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .list{
        width: 100%;
        .card-detail{
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            line-height: 120%;
            .detail{
                width: 46%;
                font-size: 26rpx;
                margin-bottom: 12rpx;
                color: #555;
                margin-right: 20rpx;
                text{
                    color: #999;
                    font-size: 26rpx;
                }
            }
        }
        .more{
            color: #888;
            font-size: 24rpx;
            display: flex;
            border-top: 1px solid #eee;
            padding-top: 20rpx;
            .part{
                width: 50%;
                text-align: center;
            }
        }
    }
 
.popup-content{
    width: 500rpx;
    border-radius: 20rpx;
    text-align: center;
    padding-bottom: 20rpx;
    .tit{
        height: 120rpx;
        line-height: 120rpx;
        font-size: 34rpx;
        color: #222;
        font-weight: bold;
    }
    .item{
        height: 88rpx;
        line-height: 88rpx;
        border-top: 1px solid #eee;
        font-size: 32rpx;
        color: #444;
    }
}
</style>