<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> 
 |