Mr.Shi
2023-08-11 6e19ef63c0a87588abd76c04ab228a73e3060ea4
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
<template>
    <div class="details">
        <V-WorkOrderInfo :info="info"></V-WorkOrderInfo>
        <div class="details_h"></div>
        <div class="details_dj">
            <div class="details_dj_title">
                <div class="details_x"></div>
                <span>产出信息</span>
                <span>{{total}}<template v-if="info.umodel">{{info.umodel.name}}</template></span>
            </div>
        </div>
        <van-swipe-cell v-for="(item, index) in produceData" :key="index">
            <div class="details_num">
                <div class="details_num_item">
                    <span>报工类型</span>
                    <span class="green" v-if="item.smodelLabel === Attribute.HG">{{item.type}}</span>
                    <span class="yellow" v-else-if="item.smodelLabel === Attribute.BL">{{item.type}}</span>
                    <span class="red" v-else-if="item.smodelLabel === Attribute.BF">{{item.type}}</span>
                    <span class="black" v-else-if="item.smodelLabel === Attribute.HH">{{item.type}}</span>
                </div>
                <div class="details_num_item">
                    <span>{{item.code}}</span>
                    <div class="details_num_item_sr">
                        <input v-model="item.num" @blur="changeNumber(item.num, index)" type="text" />
                        <span v-if="info.umodel">{{info.umodel.name}}</span>
                    </div>
                </div>
            </div>
            <template #right>
                <van-button style="height: 100%;" square type="danger" text="删除" @click="dele(index)" />
            </template>
        </van-swipe-cell>
        <div class="details_zw"></div>
        <div class="details_footer">
            <div class="details_footer_buttona" @click="continueScanning">继续扫码</div>
            <div class="details_footer_buttonb" @click="submit">提交</div>
        </div>
        <!--  扫码组件  -->
        <v-ScanCode
            :openCode="openCode"
            :infos="['请扫描工装码']"
            @closePopup="closePopup"
            @onDecode="onDecode" />
    </div>
</template>
 
<script setup lang="ts">
    import { ref, onMounted, nextTick, watch } from 'vue'
    import { Toast } from 'vant'
    import { REGULAR } from '@/utils/utils'
    import { Attribute } from '@/enum'
    import { createProduce, getBarcodeContent, queryById, toolingQueryById } from '@/apis/WorkOrderAPI'
    import { useRouter, useRoute } from "vue-router"
    import VWorkOrderInfo from '@/components/common/WorkOrderInfo.vue'
 
    const router = useRouter()
    let total = ref<number>(0)
    const route = useRoute()
 
    const info: any = ref({})
 
    // 控制扫码显示隐藏
    const openCode = ref<boolean>(false)
 
    // 关闭扫码组件
    const closePopup = (): void => {
        openCode.value = false
    }
 
    // 产出数据
    let produceData: any = ref([])
 
    // 失去焦点验证整数小数
    const changeNumber = (num: any, index: number): void => {
        if (info.value.umodel.attributeData === 0 && num !== '') {  // 整数
            if(!REGULAR.positiveInteger.test(num)) {
                Toast({ message: '只能输入正整数' })
                produceData.value[index].num = ''
            }
        } else if (info.value.umodel.attributeData === 1 && num !== '') {  // 小数(只支持四位小数)
            if(!REGULAR.number.test(num)) {
                Toast({ message: '只能输入正整数或小数(最多四位)' })
                produceData.value[index].num = ''
            }
        }
    }
 
    // 查询工单详情
    const queryByIds = () => {
        queryById(route.query.id).then(res => {
            if (res.code === 200) {
                info.value = res.data
            }
        })
    }
 
    // 根据id查询工装器具详情
    const toolingQueryByIds = (id: any) => {
        toolingQueryById({ id }).then(res => {
            if (res.code === 200) {
                let isOpen = true
                produceData.value.forEach((item: any) => {
                    if (item.id === res.data[0].id) {
                        isOpen = false
                    }
                })
                if (isOpen) {
                    produceData.value.push({ id: res.data[0].id, code: res.data[0].code, total: res.data[0].num, num: produceData.value.length === 0 ? res.data[0].num : produceData.value[produceData.value.length - 1].num, type: res.data[0].smodelCode, smodelLabel: res.data[0].smodelLabel, dw: res.data[0].umodelName })
                } else {
                    Toast({ message: '工装已存在', duration: 2000 })
                }
            }
        })
    }
 
    // 删除产出信息
    const dele = (index: number) => {
        if (produceData.value.length === 1) {
            Toast({
                message: '至少需要投一个篮筐',
                duration: 2000
            })
            return
        }
        produceData.value.splice(index, 1)
    }
 
    // 打开扫码弹框
    const continueScanning = () => {
        openCode.value = true
    }
 
    // 获取扫码值
    const onDecode = (data: string[]): void => {
        getBarcodeContent({
            barcode: data[0]
        }).then(res => {
            if (res.code === 200) {
                if (res.data.barcodeType === 4) {
                    toolingQueryByIds(res.data.id)
                } else {
                    Toast({
                        message: '请扫描正确的篮筐码',
                        duration: 2000
                    })
                }
            }
        })
        nextTick(() => {
            openCode.value = false
        })
    }
 
    // 提交产出
    const submit = () => {
        let isOpen: any = true
        produceData.value.forEach((item: any) => {
            if (item.num === '') {
                isOpen = false
            }
        })
        if (isOpen) {
            let recordList: any = []
            produceData.value.forEach((item: any) => {
                recordList.push({ applianceId: item.id, num: item.num })
            })
            createProduce({
                id: route.query.id,
                recordList: recordList
            }).then(res => {
                if (res.code === 200) {
                    Toast.success({ message: '产出成功', duration: 2000, forbidClick: true })
                    setTimeout(() => {
                        router.go(-1)
                    }, 2000)
                }
            })
        } else {
            Toast.fail({ message: '请完善产出信息' })
        }
    }
 
    watch(() => produceData.value, (news) => {
        total.value = 0
        news.forEach((element: any) => {
            total.value = total.value + Number(element.num)
        })
    }, { deep: true })
 
    onMounted(() => {
        queryByIds()
        toolingQueryByIds(route.query.gzId)
    })
</script>
 
<style lang="scss" scoped>
    .details {
        width: 100%;
        height: 100%;
        position: absolute;
        background: #F7F7F7;
        .details_h {
            height: 20px;
        }
        .details_dj {
            display: flex;
            flex-direction: column;
            .details_dj_title {
                width: 100%;
                display: flex;
                align-items: center;
                padding: 30px;
                box-sizing: border-box;
                .details_x {
                    width: 8px;
                    height: 30px;
                    background: #4275FC;
                    border-radius: 2px;
                    margin-right: 12px;
                }
                span {
                    font-size: 32px;
                    font-weight: 500;
                    color: #222222;
                    &:nth-child(3) {
                        font-size: 28px;
                        font-weight: 500;
                        color: $nav-color;
                        margin-left: 10px;
                    }
                }
            }
        }
        .details_num {
            padding: 0 30px;
            background: white;
            margin-bottom: 20px;
            .details_num_item {
                height: 90px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-bottom: 1px solid #E5E5E5;
                &:last-child {
                    border: none;
                }
                .details_num_item_sr {
                    display: flex;
                    align-items: center;
                    input {
                        width: 180px;
                        height: 60px;
                        border-radius: 8px;
                        border: 1PX solid #E5E5E5;
                        text-align: right;
                        padding: 0 30px;
                        margin-right: 20px;
                        font-size: 28px;
                        font-weight: 400;
                        color: #333333;
                    }
                    span {
                        font-size: 28px;
                        font-weight: 400;
                        color: #666666 !important;
                    }
                }
                span {
                    &:nth-child(1) {
                        font-size: 30px;
                        font-weight: 400;
                        color: #222222;
                    }
                    &:nth-child(2) {
                        font-size: 28px;
                        font-weight: 400;
                        color: $nav-stateColor2;
                    }
                }
            }
        }
        .details_zw {
            height: 160px;
        }
        .details_footer {
            width: 100%;
            position: fixed;
            bottom: 0;
            left: 0;
            padding-bottom: 68px;
            padding-left: 30px;
            padding-right: 30px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-sizing: border-box;
            .details_footer_buttona {
                width: 334px;
                height: 88px;
                background: #FFFFFF;
                box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.08);
                border-radius: 8px;
                font-size: 30px;
                font-weight: 500;
                color: $nav-color;
                display: flex;
                align-items: center;
                justify-content: center;
            }
            .details_footer_buttonb {
                width: 334px;
                height: 88px;
                background: $nav-color;
                box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.08);
                border-radius: 8px;
                font-size: 30px;
                font-weight: 500;
                color: #FFFFFF;
                display: flex;
                align-items: center;
                justify-content: center;
            }
        }
    }
</style>