<template> 
 | 
    <div class="details"> 
 | 
        <V-WorkOrderInfo :info="info"></V-WorkOrderInfo> 
 | 
        <!--  投料信息  --> 
 | 
        <div class="details_dj"> 
 | 
            <div class="details_dj_title"> 
 | 
                <div class="details_x"></div> 
 | 
                <span>投料信息</span> 
 | 
                <span>{{total == 0 ? '' : total}}<template v-if="listData.length > 0">{{listData[listData.length - 1].dw ? listData[listData.length - 1].dw : ''}}</template></span> 
 | 
            </div> 
 | 
            <van-swipe-cell v-for="(item, index) in listData" :key="index"> 
 | 
                <div class="details_dj_list"> 
 | 
                    <div class="details_dj_list_item"> 
 | 
                        <div class="details_dj_list_item_top"> 
 | 
                            <span>{{item.code}}</span> 
 | 
                            <span v-if="info.umodel">{{item.total}}{{item.dw}}</span> 
 | 
                        </div> 
 | 
                        <div class="details_dj_list_item_bottom"> 
 | 
                            <span v-if="info.umodel">投料数量({{item.dw}}):</span> 
 | 
                            <input v-model="item.num" @blur="changeNumber(item.num, index, item.umodelData)" type="text" /> 
 | 
                        </div> 
 | 
                    </div> 
 | 
                </div> 
 | 
                <template #right> 
 | 
                    <van-button style="height: 100%;" square type="danger" text="删除" @click="dele(index)" /> 
 | 
                </template> 
 | 
            </van-swipe-cell> 
 | 
        </div> 
 | 
        <div class="details_zw"></div> 
 | 
        <!--  底部功能按钮  --> 
 | 
        <div class="details_footer"> 
 | 
            <div class="details_footer_buttona" @click="continueScanning">继续扫码</div> 
 | 
            <button v-preventReClick class="details_footer_buttonb" @click="submit">提交</button> 
 | 
        </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 { useRouter, useRoute } from "vue-router" 
 | 
    import { getBarcodeContent, queryById, toolingQueryById, createMaterial } from '@/apis/WorkOrderAPI' 
 | 
    import vScanCode from '@/components/common/ScanCode.vue' 
 | 
    import VWorkOrderInfo from '@/components/common/WorkOrderInfo.vue' 
 | 
  
 | 
    const info: any = ref({}) 
 | 
  
 | 
    const router = useRouter() 
 | 
    let total = ref<number>(0) 
 | 
    const route = useRoute() 
 | 
  
 | 
    // 投料信息 
 | 
    let listData: any = ref([]) 
 | 
  
 | 
    // 失去焦点验证整数小数 
 | 
    const changeNumber = (num: any, index: number, umodelData: number): void => { 
 | 
        if (umodelData === 0 && num !== '') {  // 整数 
 | 
            if(!REGULAR.positiveInteger.test(num)){ 
 | 
                Toast({ message: '只能输入正整数' }) 
 | 
                listData.value[index].num = '' 
 | 
            } 
 | 
        } else if (umodelData === 1 && num !== '') {  // 小数(只支持四位小数) 
 | 
            if(!REGULAR.number.test(num)){ 
 | 
                Toast({ message: '只能输入正整数或小数(最多四位)' }) 
 | 
                listData.value[index].num = '' 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
  
 | 
    // 删除一条投料信息 
 | 
    const dele = (index: any): void => { 
 | 
        if (listData.value.length === 1) { 
 | 
            Toast({ 
 | 
                message: '至少添加一条投料信息', 
 | 
                duration: 2000 
 | 
            }) 
 | 
            return 
 | 
        } 
 | 
        listData.value.splice(index, 1) 
 | 
    } 
 | 
  
 | 
    // 控制扫码显示隐藏 
 | 
    const openCode = ref<boolean>(false) 
 | 
  
 | 
    // 关闭扫码组件 
 | 
    const closePopup = (): void => { 
 | 
        openCode.value = false 
 | 
    } 
 | 
  
 | 
    // 继续扫码 
 | 
    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 queryByIds = () => { 
 | 
        queryById(route.query.id).then(res => { 
 | 
            if (res.code === 200) { 
 | 
                info.value = res.data 
 | 
            } 
 | 
        }) 
 | 
    } 
 | 
  
 | 
    // 根据工装器具id获取详情 
 | 
    const toolingQueryByIds = (id: any): void => { 
 | 
        toolingQueryById({ id }) 
 | 
            .then(res => { 
 | 
                if (res.code === 200) { 
 | 
                    if (res.data[0].status === 0) { 
 | 
                        Toast({ message: '该工装已报废' }) 
 | 
                    } else if (res.data[0].status === 1) { 
 | 
                        Toast({ message: '该工装为空' }) 
 | 
                    } 
 | 
                    let isOpen = true 
 | 
                    listData.value.forEach((item: any) => { 
 | 
                        if (item.id === res.data[0].id) { 
 | 
                            isOpen = false 
 | 
                        } 
 | 
                    }) 
 | 
                    if (isOpen) { 
 | 
                        listData.value.push({ id: res.data[0].id, code: res.data[0].code + ' - ' + res.data[0].mmodelName, total: res.data[0].num, num: res.data[0].num, dw: res.data[0].umodelName, umodelData: res.data[0].umodelData }) 
 | 
                    } else { 
 | 
                        Toast({ message: '工装已存在', duration: 2000 }) 
 | 
                    } 
 | 
                } 
 | 
            }) 
 | 
    } 
 | 
  
 | 
    // 提交投料 
 | 
    const submit = () => { 
 | 
        let isOpen = true 
 | 
        listData.value.forEach((item: any) => { 
 | 
            if (item.num === '') { 
 | 
                isOpen = false 
 | 
                Toast({ message: `[${item.code}]投料数量不能为空`, duration: 2000 }) 
 | 
            } 
 | 
            if (item.num > item.total) { 
 | 
                isOpen = false 
 | 
                Toast({ message: `[${item.code}]投料数量不能大于生产数量`, duration: 2000 }) 
 | 
                return 
 | 
            } 
 | 
        }) 
 | 
  
 | 
        if (isOpen) { 
 | 
            let recordList: any = [] 
 | 
            listData.value.forEach((item: any) => { 
 | 
                recordList.push({ applianceId: item.id, num: item.num }) 
 | 
            }) 
 | 
            createMaterial({ 
 | 
                id: route.query.id, 
 | 
                recordList: recordList 
 | 
            }).then(res => { 
 | 
                if (res.code === 200) { 
 | 
                    Toast.success({ message: '投料成功', duration: 2000, forbidClick: true }) 
 | 
                    setTimeout(() => { 
 | 
                        router.go(-1) 
 | 
                    }, 2000) 
 | 
                } 
 | 
            }) 
 | 
        } 
 | 
    } 
 | 
  
 | 
    watch(() => listData.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_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_dj_list { 
 | 
                width: 100%; 
 | 
                padding: 30px; 
 | 
                margin-bottom: 20px; 
 | 
                box-sizing: border-box; 
 | 
                background: #ffffff; 
 | 
                display: flex; 
 | 
                flex-direction: column; 
 | 
                .details_dj_list_item { 
 | 
                    display: flex; 
 | 
                    flex-direction: column; 
 | 
                    border-bottom: 1px solid #E5E5E5; 
 | 
                    padding-bottom: 30px; 
 | 
                    margin-top: 30px; 
 | 
                    &:first-child { 
 | 
                        margin-top: 0; 
 | 
                    } 
 | 
                    &:last-child { 
 | 
                        padding-bottom: 0; 
 | 
                        border: none; 
 | 
                    } 
 | 
                    .details_dj_list_item_top { 
 | 
                        display: flex; 
 | 
                        align-items: center; 
 | 
                        justify-content: space-between; 
 | 
                        span { 
 | 
                            &:first-child { 
 | 
                                font-size: 30px; 
 | 
                                font-weight: 500; 
 | 
                                color: #222222; 
 | 
                            } 
 | 
                            &:last-child { 
 | 
                                font-size: 28px; 
 | 
                                font-weight: 500; 
 | 
                                color: #4275FC; 
 | 
                            } 
 | 
                        } 
 | 
                    } 
 | 
                    .details_dj_list_item_bottom { 
 | 
                        display: flex; 
 | 
                        align-items: center; 
 | 
                        justify-content: space-between; 
 | 
                        margin-top: 30px; 
 | 
                        span { 
 | 
                            font-size: 28px; 
 | 
                            font-weight: 400; 
 | 
                            color: #222222; 
 | 
                        } 
 | 
                        input { 
 | 
                            text-align: right; 
 | 
                            width: 280px; 
 | 
                            height: 60px; 
 | 
                            padding: 0 30px; 
 | 
                            box-sizing: border-box; 
 | 
                            /*background: #F7F7F7;*/ 
 | 
                            border-radius: 8px; 
 | 
                            border: 1PX solid #E5E5E5; 
 | 
                            font-size: 28px; 
 | 
                            font-weight: 500; 
 | 
                            color: #333333; 
 | 
                        } 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
        .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; 
 | 
                border: none; 
 | 
                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> 
 |