spring
4 天以前 f26f29d84e0a68831a6af14dab3eec5500496d2e
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<template>
    <view class="body">
        <view class="top_code">
            <u-icon class="product-number-icon"></u-icon>编号:
            <text selectable>{{ dutyNo }}</text>
            <view class="top_code_edit">
                <u-icon class="product-edit-icon" @click="edit" v-show="true"></u-icon>
            </view>
        </view>
        <view class="main_view">
            <h3 class="main_top_title">工作台</h3>
            <view class="main_item" @click="goPage(0)">
                <span style="color:#4F4F4F">工作站</span>
                <view>
                    <span style="color:#333333;margin-right: 20rpx;">{{ query.workstationName }}</span>
                    <u-icon v-if="isShowButton" name="arrow-right" color="#687792" size="28"></u-icon>
                </view>
            </view>
            <view class="main_item" @click="goPage(1)">
                <span style="color:#4F4F4F">工序</span>
                <view>
                    <span style="color:#333333;margin-right: 20rpx;">{{ query.operationName }}</span>
                    <u-icon v-if="isShowButton" name="arrow-right" color="#687792" size="28"></u-icon>
                </view>
            </view>
            <view class="main_item" @click="goPage(2)">
                <span style="color:#4F4F4F">日期</span>
                <view>
                    <span style="color:#333333;margin-right: 20rpx;">{{ query.updateTime }}</span>
                    <u-icon v-if="isShowButton" name="arrow-right" color="#687792" size="28"></u-icon>
                </view>
            </view>
            <view class="main_item" @click="goPage(3)">
                <span style="color:#4F4F4F">班次</span>
                <view>
                    <span style="color:#333333;margin-right: 20rpx;">{{ query.clazzType }}</span>
                    <u-icon v-if="isShowButton" name="arrow-right" color="#687792" size="28"></u-icon>
                </view>
            </view>
            <view class="main_item" @click="goPage(4)">
                <span style="color:#4F4F4F;width: 118rpx;">生产人员</span>
                <view class="value2">
                    <span style="color:#333333;margin-right: 20rpx;">{{ staffNameJoin }}</span>
                </view>
                <u-icon v-if="isShowButton" name="arrow-right" color="#687792" size="28"></u-icon>
            </view>
            <view class="main_item">
                <span style="color:#4F4F4F">创建人</span>
                <view>
                    <span style="color:#333333;">{{ query.createUser }}</span>
                </view>
            </view>
            <view class="btns">
                <u-button :custom-style="customStyle" @click="goPage(9)">杂工</u-button>
                <u-button :custom-style="customStyle" style="width: 150rpx;" @click="goPage(6)">
                    <u-icon class="icon_history" size="26rpx" />
                    <span style="line-height: 40rpx;">历史</span>
                </u-button>
                <u-button v-if="isShowButton" @click="submit" :custom-style="customStyle"
                    style="background: #30AFFF;color: #fff;border: 0;width: 150rpx;">
                    <u-icon class="icon_save" size="26rpx" />
                    <span style="line-height: 40rpx;">保存</span>
                </u-button>
                <u-button :custom-style="customStyle" style="background: #214DED;color: #fff;border: 0;width: 150rpx;"
                    @click="goPage(8)">
                    <u-icon class="icon_right" size="26rpx" />
                    <span style="line-height: 40rpx;">报工</span></u-button>
            </view>
        </view>
        <u-calendar v-model="calendarShow" :mode="mode" @change="changeCalendar"></u-calendar>
        <!--工序下拉框-->
        <u-select :default-value="[operationIndex]" v-model="selectShowOperation" :list="operationList"
            @confirm="confirmOperation"></u-select>
        <u-select v-model="selectShowClazzType" :list="clazzTypeList" @confirm="confirmClazzType"></u-select>
        <u-toast ref="uToast" />
    </view>
</template>
 
<script>
import {
    dateFormat
} from "@/utils/date.js";
import UIcon from "../../../uview-ui/components/u-icon/u-icon.vue";
export default {
    components: {
        UIcon
    },
    data() {
        return {
            customStyle: {
                'background': '#FFFFFF',
                'border-radius': '8rpx',
                'border': '1px solid #D2D2D2',
                'width': '121rpx',
                'height': '65rpx',
                'font-weight': 500,
                'font-size': '28rpx',
                'color': '#333333',
                'pading': '0 30rpx'
            },
            calendarShow: false,
            selectShowOperation: false,
            selectShowClazzType: false,
            mode: 'date',
            id: '',
            dutyNo: '', // 编号
            query: {
                updateTime: dateFormat(
                    new Date(), 'yyyy-MM-dd'),
                workstationName: '', // 工作站名称
                workstationId: '', // 工作站id
                clazzType: '', // 班次
                productionUser: '',
                operationId: '', // 工序id
                operationName: '', // 工序名称
                userList: [],
                createUser: ''
            },
            toId: '',
            operationList: [],
            clazzTypeList: [{
                label: '白班'
            },
            {
                label: '晚班'
            },
            ],
            workstation: '',
            staffNameJoin: '',
            operationIndex: '',
            isEdit: false, // 是否修改
            isShowButton: false,
            workCenter: '',
            addOrEdit: '',
            info: {},
            firstOperationId: null,
            lastOperationId: null,
        }
    },
    onShow() {
        // this.getLastDutyRecordFun()
    },
    onLoad() {
        uni.$on('dailyListInfo', (info) => {
            this.dutyNo = info.dutyNo
            this.id = info.id
            this.query.createUser = this.vuex_username
            this.query.clazzType = info.clazzType
            this.query.workstationId = info.workstationId
            this.query.workstationName = info.workstationName
            this.query.productionUser = info.productionUser.split(',').reverse()
            this.query.userList = info.productionUserList.split(',')
            this.query.operationId = info.operationId
            this.getOperation()
        })
 
        uni.$on('returnData', (data) => {
            // 临时存储工作站的数据
            this.workstation = data
            // 给页面工作站赋值
            this.query.workstationName = '(' + data.workCenter + ')' + data.name
            this.query.workstationId = data.id
            // 清空工序选项
            this.query.operationName = ''
            this.query.operationId = ''
            this.operationIndex = 0
            this.getOperationTaskFun(data.workCenter)
        })
        uni.$on('checkedList', (data) => {
            let staffNameList = []
            let staffNoList = []
            data.forEach(i => {
                staffNameList.push(i.staffName)
                staffNoList.push(i.staffNo)
            })
            this.query.productionUser = staffNameList
            this.query.userList = staffNoList
        });
    },
    onReady() {
        // 首次进入页面获取当前登录人最后一次提交的日报
        this.getLastDutyRecordFun()
    },
    methods: {
        isNotOperationName(workCenter, operationName, workCenterTwo) {
            // 判断是否为该工作站
            if (workCenter.includes(workCenterTwo)) {
                // 判断是否包含工序名称
                if (!operationName.includes(this.query.operationName)) {
                    return true
                } else {
                    return false
                }
            } else {
                return false
            }
        },
        // 判断工单是否等于,同时判断是否为第一道工序
        isFirstOperationId(workCenter, workCenterTwo) {
            if (workCenter.includes(workCenterTwo)) {
                // 判断是否不为第一道工序
                if (this.query.operationId !== this.firstOperationId) {
                    return true
                } else {
                    return false
                }
            } else {
                return false
            }
        },
        // 首次进入页面获取当前登录人最后一次提交的日报
        getLastDutyRecordFun() {
            this.$u.api.dailyPaper.getLastDutyRecord().then(res => {
                if (res.code === 0) {
                    this.dutyNo = res.data.dutyNo
                    this.id = res.data.id
                    this.query.createUser = this.vuex_username
                    this.query.clazzType = res.data.clazzType
                    this.query.workstationId = res.data.workstationId
                    this.query.workstationName = res.data.workstationName
                    this.query.productionUser = res.data.productionUser.split(',').reverse()
                    this.query.userList = res.data.productionUserList.split(',')
                    this.query.operationId = res.data.operationId
                    this.getOperation()
                } else {
                    this.$u.toast(res.msg)
                }
            })
        },
        // 清空逻辑
        onNavigationBarButtonTap(e) {
            this.isEdit = true
            this.isShowButton = true
            this.addOrEdit = 'add'
            this.query.productionUser = ''
            this.query.productionUserList = []
            this.staffNameJoin = ''
            this.query.updateTime = ''
        },
        edit() {
            this.isEdit = !this.isEdit
            this.isShowButton = this.isEdit
            this.addOrEdit = 'edit'
        },
        goPage(index) {
            switch (index) {
                // 跳转到历史页面
                case 6:
                    uni.navigateTo({
                        url: '/pages/daily/daily/daily-list'
                    })
                    break;
                // 跳转到报工页面
                case 8:
                    if (this.isEdit) {
                        this.$refs.uToast.show({
                            title: '请先保存修改',
                            type: 'warning '
                        })
                        return
                    }
 
                    let workCenter = this.query.workstationName.split(')')[0].substring(1)
                    let operation = this.query.workstationName.split(')')[1]
                    console.log(workCenter, operation, this.firstOperationId, this.query.operationId, this.query)
                    if (workCenter == "TM-01" || workCenter == "JG-01" || workCenter == "YB-04" || this.isFirstOperationId('DY-01,GY-01,YB-01,YB-02', workCenter) || this.isNotOperationName('ZZ-02', '二装,注油', workCenter)) {
                        let item = {
                            workstationId: this.query.workstationId,
                            clazzType: this.query.clazzType,
                            dutyNo: this.dutyNo,
                            userStaffNo: this.query.userList,
                            workstationName: this.query.workstationName,
                            staffNameJoin: this.staffNameJoin,
                            workCenter: workCenter,
                            operationId: this.query.operationId,
                            firstOperationId: this.firstOperationId,
                            lastOperationId: this.lastOperationId
                        }
                        uni.navigateTo({
                            url: '/pages/daily/common/work-reporting?info=' + encodeURIComponent(JSON
                                .stringify(item))
                        })
                    } else if (this.query.workstationName.includes("TX-02") && !this.query.operationName.includes("叠装")) {
                        let item = {
                            workstationId: this.query.workstationId,
                            clazzType: this.query.clazzType,
                            dutyNo: this.dutyNo,
                            userStaffNo: this.query.userList,
                            workstationName: this.query.workstationName,
                            staffNameJoin: this.staffNameJoin,
                            workCenter: "TX-02",
                            operationId: this.query.operationId,
                            firstOperationId: this.firstOperationId,
                            lastOperationId: this.lastOperationId
                        }
                        uni.navigateTo({
                            url: '/pages/daily/common/work-reporting?info=' + encodeURIComponent(JSON
                                .stringify(item))
                        })
                    } else {
                        uni.navigateTo({
                            url: `/pages/daily/common/work-order-list?workstationId=${this.query.workstationId}&toId=${this.toId}&clazzType=${this.query.clazzType}&dutyNo=${this.dutyNo}&userStaffNo=${this.query.userList}&workstationName=${this.query.workstationName}&staffNameJoin=${this.staffNameJoin}`
                        })
                    }
                    break;
                // 跳转到杂工页面
                case 9:
                    if (this.isEdit) {
                        this.$refs.uToast.show({
                            title: '请先保存修改',
                            type: 'warning '
                        })
                        return
                    }
                    uni.navigateTo({
                        url: `/pages/daily/handyman/handyman?dutyNo=${this.query.dutyNo}&updateTime=${this.query.updateTime}&userList=${this.query.productionUser}&staffList=${this.query.userList}`
                    })
                    break;
            }
            if (!this.isEdit) {
                return
            } else {
                switch (index) {
                    case 0:
                        uni.navigateTo({
                            url: '/pages/daily/workstation/index'
                        })
                        break;
                    case 1:
                        if (!this.query.workstationName) {
                            this.$refs.uToast.show({
                                title: '请先选择工作站',
                                type: 'warning '
                            })
                        } else {
                            this.selectShowOperation = true;
                        }
                        break;
                    case 2:
                        this.calendarShow = true;
                        break;
                    case 3:
                        this.selectShowClazzType = true;
                        break;
                    case 4:
                        let staffList = this.query.productionUser
                        let staffNoList = this.query.userList
                        const list = []
                        for (const i in staffList) {
                            const obj = {
                                staffName: staffList[i],
                                staffNo: staffNoList[i]
                            }
                            list.push(obj)
                        }
                        uni.navigateTo({
                            url: '/pages/daily/production-person/production-person?list=' + encodeURIComponent(
                                JSON.stringify(list))
                        })
                        break;
                }
            }
        },
        // 提交日报修改
        submit() {
            if (!this.query.workstationId) {
                this.$u.toast('请选择工作站')
                return
            } else if (!this.query.operationId) {
                this.$u.toast('请选择工序')
                return
            } else if (!this.query.clazzType) {
                this.$u.toast('请选择班次')
                return
            } else if (!this.query.productionUser) {
                this.$u.toast('请选择生产人员')
                return
            } else if (!this.query.updateTime) {
                this.$u.toast('请选择时间')
                return
            }
 
            let params = JSON.parse(JSON.stringify(this.query))
            this.$delete(params, 'productionUser')
            this.$delete(params, 'productionUserList')
            params.updateTime = params.updateTime + ' 00:00:00'
            params.id = null
            if (this.addOrEdit === 'add') {
                this.$u.api.dailyPaper.addDailyPaper(params).then(res => {
                    if (res.code === 0) {
                        // this.getLastDutyRecordFun()
                        this.query.createUser = this.vuex_username
                        this.$u.toast('保存成功')
                        this.isShowButton = false
                        this.getLastDutyRecordFun()
                    }
                })
            } else {
                params.id = this.id
                this.$u.api.dailyPaper.editDailyPaper(params).then(res => {
                    if (res.code === 0) {
                        // this.getLastDutyRecordFun()
                        this.$u.toast('修改成功')
                        this.isShowButton = false
                    }
                })
            }
            this.isEdit = false
        },
        changeCalendar(e) {
            this.query.updateTime = e.result;
        },
        confirmOperation(e) {
            this.query.operationName = e[0].label
            this.query.operationId = e[0].value
            const index = this.operationList.findIndex(item => item.value === this.query.operationId)
            if (index > -1) {
                this.operationIndex = index
                this.toId = this.operationList[index].value
            }
        },
        confirmClazzType(e) {
            this.query.clazzType = e[0].label
        },
        // 查询工作站
        getOperation() {
            this.$u.api.dailyPaper.getWorkstation().then(res => {
                if (res.code === 0) {
                    const index = res.data.findIndex(item => item.name === this.query.workstationName)
                    if (index > -1) {
                        this.workCenter = res.data[index].workCenter
                    }
                    this.query.workstationName = '(' + this.workCenter + ')' + this.query.workstationName
                    this.getOperationTaskFun(this.workCenter, this.query.operationId)
                }
            })
        },
        getOperationTaskFun(id, operationId) {
            this.operationList = []
            const params = {
                workCenter: id,
                current: 1,
                size: -1
            }
            // 查询工序列表
            this.$u.api.dailyPaper.getOperation(params).then(res => {
                if (res.code === 0) {
                    if (res.data.records.length > 0) {
                        res.data.records.forEach(i => {
                            const obj = Object.assign({
                                label: i.name,
                                value: i.id,
                            })
                            this.operationList.push(obj)
                        })
                        if (operationId) {
                            const index = this.operationList.findIndex(item => item.value === operationId)
                            if (index > -1) {
                                this.operationIndex = index
                                this.query.operationName = this.operationList[index].label
                                this.toId = this.operationList[index].value
                            }
                        }
                        this.firstOperationId = this.operationList[0].value
                        this.lastOperationId = this.operationList[this.operationList.length - 1].value
                    }
                }
            })
        }
    },
    watch: {
        'query.productionUser': {
            handler(newName, oldName) {
                if (this.query.productionUser.length > 0) {
                    this.staffNameJoin = this.query.productionUser.join()
                } else {
                    this.staffNameJoin = ''
                }
            },
            immediate: true,
            deep: true
        }
    }
}
</script>
 
<style lang="scss">
@import 'index.scss';
</style>