jiangping
2023-10-16 d7fe8ae3888c8e2b1eea3c1e3769be0d42a21cc9
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
<template>
    <div class="zk">
        <div class="zk_list">
            <div class="zk_list_item" @click="open('r')">
                <span>转入车间/仓库</span>
                <div class="zk_list_item_n">
                    <span :style="data.warehouseName ? 'color: black;' : ''">{{data.warehouseName ? data.warehouseName : '请选择'}}</span>
                    <van-icon name="arrow" color="#999999" size="20" />
                </div>
            </div>
            <div class="zk_list_item" @click="open('h')" v-if="isShow">
                <span>货位</span>
                <div class="zk_list_item_n">
                    <span :style="data.locationName ? 'color: black;' : ''">{{data.locationName ? data.locationName : '请选择'}}</span>
                    <van-icon name="arrow" color="#999999" size="20" />
                </div>
            </div>
        </div>
        <div class="zk_title">
            <div class="zk_title_left">
                <div class="zk_title_i"></div>
                <span>转出工装列表({{list.length}})</span>
            </div>
            <div class="zk_title_right">
                <span>总计:{{total}}</span>
            </div>
        </div>
        <div class="zk_wl">
            <template v-if="list.length > 0">
                <van-swipe-cell v-for="(item, i) in list" :key="i">
                    <div class="zk_wl_item">
                        <span>{{item.code}} {{item.num}}{{item.umodelName}}</span>
                        <span>物料信息:{{item.mmodelName}} | {{item.mmodelCode}}</span>
                        <span>批次号:{{item.batch}}</span>
                        <span>生产工序:{{item.pmodelName}}</span>
                    </div>
                    <template #right>
                        <van-button square type="danger" style="height: 100%;" text="删除" @click="dele(i)" />
                    </template>
                </van-swipe-cell>
            </template>
            <div class="zk_wl_w" v-else>
                <span>暂无数据</span>
            </div>
        </div>
        <div class="zk_z"></div>
        <div class="zk_footer">
            <div class="zk_footer_wl" @click="open('code')">继续扫码</div>
            <div style="width: 20px"></div>
            <div class="zk_footer_submit" @click="submit">提交</div>
        </div>
    </div>
    <!--  货位  -->
    <van-popup v-model:show="view.type" position="bottom" round :style="{ height: '50%' }">
        <van-picker
            title="请选择货位"
            :columns="locationData"
            @confirm="onConfirm"
            @cancel="onCancel"
            :columns-field-names="customFieldName"
        />
    </van-popup>
    <!--  选择仓库  -->
    <Warehouse :show="view.Warehouse" @close="view.Warehouse = false" @value="getValue" />
    <!--  扫码  -->
    <v-ScanCode :openCode="openCodea" :infos="['请扫描工装码']" @closePopup="closePopupa" @onDecode="onDecodea" />
</template>
 
<script setup lang="ts">
    import { reactive, ref, onMounted, watch } from 'vue'
    import { Toast } from 'vant'
    import { useRouter, useRoute } from "vue-router"
    import { getListByCondition, getListByWarehouseId, getBarcodeContent, scanTransfer } from '@/apis/WorkOrderAPI'
    import { QRCodeType, Attribute } from "@/enum"
    import Warehouse from '@/components/common/Warehouse.vue'
 
    const router = useRouter()
    const route = useRoute()
 
    const openCodea = ref<boolean>(false)  // 控制扫码显示隐藏
    let list: any = ref([])  // 转出工装列表
    let locationData: any = ref([])  // 货位数据
    let isShow = ref(false) // 控制货位选择显示隐藏
    let total = ref(0)  // 总计数量
    let customFieldName = {  // 自定义下拉选项显示文字
        text: 'area'
    }
 
    let data = reactive({
        type: '',
 
        warehouseName: '',
        warehouseId: '',
        locationName: '',
        locationId: ''
    })
 
    let view = reactive({
        type: false,
        Warehouse: false
    })
 
    // 创建转库单
    const submit = () => {
        if (!data.warehouseId) return Toast.fail({ message: '入库车间/仓库不能为空' })
        if (isShow.value && !data.locationId) return Toast.fail({ message: '货位不能为空' })
        let idList = list.value.map((item: any) => {
            return item.id
        })
        scanTransfer({
            idList,
            inLocationId: data.locationId,
            inWarehouseId: data.warehouseId,
            outWarehouseId: list.value[0].warehouseId
        }).then(res => {
            if (res.code === 200) {
                Toast.success({ message: '转库成功', duration: 2000, forbidClick: true })
                setTimeout(() => {
                    router.go(-1)
                }, 2000)
            }
        })
    }
 
    // 扫码回调
    const onDecodea = async (datav: string[]): Promise<void> => {
        getBarcodeContent({
            barcode: datav[0]
        }).then(res => {
            if (res.code === 200) {
                if (res.data.barcodeType === QRCodeType.GZ) {   // 判断是否是工装码
                    getListByCondition({ id: res.data.id })
                        .then(res => {
                            if (res.code === 200) {
                                if (res.data && res.data.length > 0) {    // 判断是否查询到工装
                                    let next: boolean = true
                                    list.value.forEach((element: any) => {  // 判断是否有重复的工装
                                        if (element.id === res.data[0].id) {
                                            next = false
                                        }
                                    })
                                    if (!next) {
                                        Toast.fail({ message: '不能重复添加相同的工装' })
                                        return
                                    }
                                    if (res.data[0].status !== 1) {    // 判断工装是否为空
                                        if (res.data[0].warehouseId) {  // 判断工装是否在仓库下
                                            if (res.data[0].warehouseId === list.value[0].warehouseId) {    // 判断仓库是否一致
                                                if (res.data[0].smodelLabel === list.value[0].smodelLabel) {    // 属性是否一致
                                                    if (res.data[0].locationId !== data.locationId) {
                                                        list.value.push(res.data[0])
                                                    } else {
                                                        Toast.fail({ message: '货位不能一致', duration: 2000 })
                                                    }
                                                } else {
                                                    Toast.fail({ message: '属性不一致', duration: 2000 })
                                                }
                                            } else {
                                                Toast.fail({ message: '工装仓库不一致', duration: 2000 })
                                            }
                                        } else {
                                            Toast.fail({ message: '该工装不在仓库', duration: 2000 })
                                        }
                                    } else {
                                        Toast.fail({ message: '该工装状态为空', duration: 2000 })
                                    }
                                } else {
                                    Toast.fail({ message: '未查询到工装', duration: 2000 })
                                }
                            }
                        })
                } else {
                    Toast.fail({ message: '请扫描正确的工装码', duration: 2000 })
                }
            }
        }).finally(() => {
            openCodea.value = false
        })
    }
 
    // 关闭扫码组件
    const closePopupa = (): void => {
        openCodea.value = false
    }
 
    // 删除物料
    const dele = (i: number): void => {
        if (list.value.length === 1) {
            Toast.fail({ message: '至少保留一项工装' })
            return
        }
        list.value.splice(i, 1)
    }
 
    // 仓库回调
    const getValue = async (val: any): Promise<void> => {
        if (val.id === list.value[0].warehouseId) {
            data.warehouseId = val.id;
            data.warehouseName = val.name;
            if (val.useLocation === 1) {
                await getLocation(val.id)
                isShow.value = true
            } else {
                isShow.value = false
            }
        } else {
            locationData.value = []
            data.locationName = ''
            data.locationId = ''
            if (list.value[0].smodelLabel === Attribute.HH || val.tmodel.label === Attribute.HH) {   // 混合 可以选择任意仓库
                data.warehouseId = val.id;
                data.warehouseName = val.name;
            } else if (list.value[0].smodelLabel === val.tmodel.label) {    // 判断属性是否一致
                data.warehouseId = val.id;
                data.warehouseName = val.name;
            } else {
                Toast.fail({ message: '工装的质量属性和仓库属性不相符' })
            }
            isShow.value = false
        }
        view.Warehouse = false;
    }
 
    // 打开选择弹框
    const open = (type: string): void => {
        if (type === 'r') {
            view.Warehouse = true
        } else if (type === 'h') {
            view.type = true
        } else if (type === 'code') {
            if (!data.warehouseId) {
                Toast.fail({ message: '仓库不能为空' })
                return
            }
            if (isShow.value && !data.locationId) {
                Toast.fail({ message: '货位不能为空' })
                return
            }
            openCodea.value = true
        }
    }
 
    // 确认货位
    const onConfirm = (val: any): void => {
        if (list.value[0].smodelLabel === Attribute.HH || val.label === Attribute.HH) {   // 混合 可以选择任意仓库
            if (list.value[0].locationId === val.id) {
                Toast.fail({ message: '货位不能一致' })
                return
            }
            data.locationId = val.id
            data.locationName = val.area
        } else if (list.value[0].smodelLabel === val.label) {    // 判断属性是否一致
            if (list.value[0].locationId === val.id) {
                Toast.fail({ message: '货位不能一致' })
                return
            }
            data.locationId = val.id
            data.locationName = val.area
        } else {
            Toast.fail({ message: '工装和货位属性不一致' })
        }
        view.type = false
    }
 
    // 关闭货位弹框
    const onCancel = (): void => {
        view.type = false
    }
 
    // 获取工装信息
    const getGZInfo = (id: string): void => {
        getListByCondition({ id })
            .then(res => {
                if (res.code === 200 && res.data.length > 0) {
                    list.value.push(res.data[0] as never)
                }
            })
    }
 
    // 根据仓库获取货位信息
    const getLocation = (id: string): void => {
        getListByWarehouseId({
            wareHouseId: id
        }).then(res => {
            if (res.code === 200) {
                if (res.data && res.data.length > 0) {
                    locationData.value = res.data
                }
            }
        })
    }
 
    // 监听工装数组,计算总数
    watch(() => list.value, () => {
        if (list.value.length > 0) {
            total.value = 0
            list.value.forEach((element: any) => {
                total.value = total.value + element.num
            })
        }
    }, { deep: true, immediate: true })
 
    onMounted(() => {
        getGZInfo(route.query.id as string)
    })
</script>
 
<style lang="scss" scoped>
    .zk {
        position: absolute;
        width: 100%;
        .zk_list {
            padding: 0 30px;
            background: white;
            margin-top: 20px;
            .zk_list_item {
                height: 98px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-bottom: 1PX solid #E5E5E5;
                &:last-child {
                    border: none !important;
                }
                span {
                    font-size: 30px;
                    font-weight: 400;
                    color: #222222;
                }
                .zk_list_item_n {
                    display: flex;
                    align-items: center;
                    span {
                        font-size: 28px;
                        font-weight: 400;
                        color: #999999;
                        margin-right: 10px;
                    }
                }
            }
        }
        .zk_title {
            padding: 40px 30px 30px 30px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .zk_title_left {
                display: flex;
                align-items: center;
                .zk_title_i {
                    width: 8px;
                    height: 30px;
                    background: #4275FC;
                    border-radius: 2px;
                    margin-right: 12px;
                }
                span {
                    font-size: 32px;
                    font-weight: 500;
                    color: #222222;
                }
            }
            .zk_title_right {
                span {
                    font-size: 28px;
                    color: $nav-color;
                }
            }
        }
        .zk_wl {
            background: white;
            .zk_wl_w {
                width: 100%;
                height: 200px;
                background: white;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 26px;
                color: black;
            }
            .zk_wl_item {
                display: flex;
                flex-direction: column;
                padding: 30px;
                border-bottom: 1PX solid #e2e2e2;
                span {
                    font-size: 26px;
                    font-weight: 500;
                    color: #3d3d3d;
                    margin-bottom: 24px;
                    &:first-child {
                        color: #000000;
                        font-size: 30px;
                    }
                    &:last-child {
                        margin-bottom: 0;
                        border-bottom: 1PX solid #ffffff;
                    }
                }
            }
        }
        .zk_z {
            height: 168px;
        }
        .zk_footer {
            width: 100%;
            box-sizing: border-box;
            padding: 0 30px;
            position: fixed;
            bottom: 0;
            left: 0;
            padding-bottom: 68px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .zk_footer_wl {
                flex: 1;
                height: 88px;
                background: #FFFFFF;
                box-shadow: 0 0 12px 0 rgba(0,0,0,0.08);
                border-radius: 8px;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 30px;
                font-weight: 500;
                color: $nav-color;
            }
            .zk_footer_submit {
                flex: 1;
                height: 88px;
                background: $nav-color;
                box-shadow: 0 0 12px 0 rgba(0,0,0,0.08);
                border-radius: 8px;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 30px;
                font-weight: 500;
                color: #FFFFFF;
            }
        }
    }
</style>