<template> 
 | 
    <div class="rework"> 
 | 
        <div class="rework_list"> 
 | 
            <div class="rework_list_item"> 
 | 
                <span>当前工厂</span> 
 | 
                <div class="rework_list_item_right"> 
 | 
                    <span style="color:#000">{{ tempFactoryName }}</span> 
 | 
                </div> 
 | 
            </div> 
 | 
            <div class="rework_list_item"> 
 | 
                <span>出库仓库</span> 
 | 
                <div class="rework_list_item_right"> 
 | 
                    <span style="color:#000">{{ tempWarhouseName }}</span> 
 | 
                </div> 
 | 
            </div> 
 | 
            <div class="rework_list_item" @click="warehouseShow = true"> 
 | 
                <span>入库仓库</span> 
 | 
                <div class="rework_list_item_right"> 
 | 
                    <span :class="form.warehouseName ? 'black' : ''">{{form.warehouseName ? form.warehouseName : '请点击选择类型'}}</span> 
 | 
                    <van-icon name="arrow" size="20" color="#999999" /> 
 | 
                </div> 
 | 
            </div> 
 | 
            <div class="rework_list_item"> 
 | 
                <span>报废原因</span> 
 | 
                <div class="rework_list_item_right"> 
 | 
                    <input type="text" style="text-align:right" v-model="form.reason" placeholder="请输入报废原因" /> 
 | 
                </div> 
 | 
            </div> 
 | 
        </div> 
 | 
        <div class="rework_qd"> 
 | 
            <div class="rework_qd_title"> 
 | 
                <div class="x"></div> 
 | 
                <span>{{'报废工装清单(' + list.length + ')'}}</span> 
 | 
            </div> 
 | 
            <van-swipe-cell v-for="(item, index) in list" :key="index"> 
 | 
                <div class="rework_qd_item"> 
 | 
                    <div class="rework_qd_item_i"> 
 | 
                        <span class="black">{{ item.code }}:</span><span class="black">{{ item.num + item.umodelName }}</span> 
 | 
                    </div> 
 | 
                    <div class="rework_qd_item_i"> 
 | 
                        <span>物料信息:</span><span>{{ item.mmodelName + ' | ' + item.mmodelCode }}</span> 
 | 
                    </div> 
 | 
                    <div class="rework_qd_item_i"> 
 | 
                        <span>批次号:</span><span>{{ item.batch ?? '-' }}</span> 
 | 
                    </div> 
 | 
                    <div class="rework_qd_item_i"> 
 | 
                      <span>生产工序:</span><span>{{ item.pmodelName }}</span> 
 | 
                    </div> 
 | 
                </div> 
 | 
                <template #right> 
 | 
                    <van-button style="height: 100%;" square type="danger" text="删除" @click="dele(index)" /> 
 | 
                </template> 
 | 
            </van-swipe-cell> 
 | 
        </div> 
 | 
        <div class="rework_zw"></div> 
 | 
        <div class="rework_footer"> 
 | 
            <div class="rework_footer_add" @click="open">扫码添加工装</div> 
 | 
            <div style="width: 22px;"></div> 
 | 
            <button class="rework_footer_submit" @click="onConfirm">提交</button> 
 | 
        </div> 
 | 
        <v-ScanCode 
 | 
            :openCode="openCode" 
 | 
            :infos="['请扫描工装码']" 
 | 
            @closePopup="closePopup" 
 | 
            @onDecode="onDecode"> 
 | 
        </v-ScanCode> 
 | 
      <Warehouse :show="warehouseShow" :systemDicDataId="'6,7'" @close="close" @value="getValue" /> 
 | 
    </div> 
 | 
</template> 
 | 
  
 | 
<script setup lang="ts"> 
 | 
  import { onMounted, ref, reactive } from 'vue' 
 | 
  import { useRoute, useRouter } from "vue-router" 
 | 
  import { Toast } from 'vant' 
 | 
  import { getBarcodeContent, getListByCondition, createSingle } from '@/apis/WorkOrderAPI' 
 | 
  import { QRCodeType } from "@/enum" 
 | 
  import Warehouse from '@/components/common/Warehouse.vue' 
 | 
  
 | 
  
 | 
    const route = useRoute() 
 | 
    const router = useRouter() 
 | 
    // 表单数据 
 | 
    let form = reactive({ 
 | 
        warehouseName: '', 
 | 
        warehouseId: '', 
 | 
        reason: '' 
 | 
    }) 
 | 
  
 | 
    // 报废清单 
 | 
    let list = ref<Array<any>>([]) 
 | 
    let warehouseShow = ref<boolean>(false) 
 | 
  
 | 
    let tempFactoryName = ref<string>() 
 | 
    let tempFactoryId = ref<string>() 
 | 
    let tempWarhouseName= ref<string>() 
 | 
    let tempWarhouseId = ref<string>() 
 | 
  
 | 
    let openCode = ref<boolean>(false) 
 | 
    // 提交 
 | 
    const onConfirm = async (value: any) => { 
 | 
  
 | 
         let res = await createSingle({ 
 | 
            type: 3, 
 | 
            factoryId: tempFactoryId.value, 
 | 
            tempFactoryName: tempFactoryName.value, 
 | 
            warehouseOutId: tempWarhouseId.value, 
 | 
            warehouseId: form.warehouseId, 
 | 
            content: form.reason, 
 | 
            applianceIdList: list.value.map((item, index, arr) => { return item.id }) 
 | 
        }) 
 | 
  
 | 
        if (res.code === 200) { 
 | 
          Toast.success({ message: '申请成功,等待审批!', duration: 2000, forbidClick: true }) 
 | 
          setTimeout(() => { 
 | 
            router.back() 
 | 
          }, 2000) 
 | 
        } else { 
 | 
          Toast.fail({ message: res.message }) 
 | 
        } 
 | 
    } 
 | 
  
 | 
    // 删除 
 | 
    const dele = (index: any) => { 
 | 
      if (list.value.length === 1) { 
 | 
     //   Toast('至少保留一条工装信息') 
 | 
        Toast('至少保留一条物流清单信息') 
 | 
        return 
 | 
      } 
 | 
      list.value.splice(index, 1) 
 | 
    } 
 | 
    // 关闭扫码框 
 | 
    const closePopup = (): void => { 
 | 
        openCode.value = false 
 | 
    } 
 | 
    // 扫码回调 
 | 
    const onDecode = async (data: string[]): Promise<void> => { 
 | 
        console.log(data) 
 | 
        openCode.value = false 
 | 
        let res = await getBarcodeContent({ 
 | 
            barcode: data[0] 
 | 
        }) 
 | 
        if (res.code === 200) { 
 | 
            if (res.data.barcodeType === QRCodeType.GZ) { 
 | 
                // 查看是否已有工装 
 | 
                for (let i = 0; i < list.value.length; i++) { 
 | 
                    if (list.value[i].id === res.data.id) { 
 | 
                        Toast.fail({ message: '不能扫描重复的工装' }) 
 | 
                        return 
 | 
                    } 
 | 
                } 
 | 
                // 获取工装详情 
 | 
                let lk = await getListByCondition({ id: res.data.id }) 
 | 
                if (lk.code === 200) { 
 | 
                    if (lk.data[0].qualityType === 2) { 
 | 
                        console.log(tempFactoryId.value, lk.data[0].pmodelOrgId) 
 | 
                        console.log(tempWarhouseId.value, lk.data[0].warehouseId) 
 | 
                        if (tempFactoryId.value === lk.data[0].pmodelOrgId &&  tempWarhouseId.value === lk.data[0].warehouseId) { 
 | 
                          list.value.push(lk.data[0]) 
 | 
                        } else { 
 | 
                          Toast.fail({ message: '请扫描相同仓库的工装' }) 
 | 
                        } 
 | 
                    } else { 
 | 
                        Toast.fail({ message: '请扫描质量属性为报废的工装', duration: 2000 }) 
 | 
                    } 
 | 
                } 
 | 
            } else { 
 | 
                Toast.fail({ message: '请扫描正确的工装码' }) 
 | 
            } 
 | 
        } 
 | 
  
 | 
    } 
 | 
    // 打开扫码 
 | 
    const open = (): void => { 
 | 
        openCode.value = true 
 | 
    } 
 | 
    // 关闭仓库选择弹框 
 | 
    const close = (): void => { 
 | 
      warehouseShow.value = false 
 | 
    } 
 | 
    // 选择仓库回调 
 | 
    const getValue = (item: any): void => { 
 | 
      console.log(item) 
 | 
      form.warehouseName = item.name 
 | 
      form.warehouseId = item.id 
 | 
      warehouseShow.value = false 
 | 
    } 
 | 
  
 | 
    const getLKInfo = async (id: string | number): Promise<void> => { 
 | 
        let res = await getListByCondition({ id }) 
 | 
        if (res.code === 200) { 
 | 
            if (res.data[0].qualityType === 2) { 
 | 
                list.value.push(res.data[0]) 
 | 
                tempFactoryName.value = res.data[0].dpmodelName 
 | 
                tempFactoryId.value = res.data[0].pmodelOrgId 
 | 
                tempWarhouseName.value = res.data[0].whmodelName 
 | 
                tempWarhouseId.value = res.data[0].warehouseId 
 | 
            } else { 
 | 
                Toast.fail({ message: '请扫描质量属性为报废的工装', duration: 2000 }) 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
  onMounted(() => { 
 | 
    // 获取工装信息 
 | 
    getLKInfo(route.query.id as string) 
 | 
  }) 
 | 
</script> 
 | 
  
 | 
<style lang="scss" scoped> 
 | 
    .rework { 
 | 
        width: 100%; 
 | 
        height: 100%; 
 | 
        position: absolute; 
 | 
        .rework_list { 
 | 
            display: flex; 
 | 
            flex-direction: column; 
 | 
            background: white; 
 | 
            margin-top: 20px; 
 | 
            .rework_list_item { 
 | 
                display: flex; 
 | 
                align-items: center; 
 | 
                justify-content: space-between; 
 | 
                height: 98px; 
 | 
                padding: 0 30px; 
 | 
                border-bottom: 1PX solid #E5E5E5; 
 | 
                &:last-child { 
 | 
                    border: none; 
 | 
                } 
 | 
                span { 
 | 
                    font-size: 30px; 
 | 
                    font-weight: 400; 
 | 
                    color: #222222; 
 | 
                    flex-shrink: 0; 
 | 
                } 
 | 
                .rework_list_item_right { 
 | 
                    display: flex; 
 | 
                    align-items: center; 
 | 
                    span { 
 | 
                        font-size: 28px; 
 | 
                        font-weight: 400; 
 | 
                        color: #999999; 
 | 
                    } 
 | 
                    .black { 
 | 
                        color: black !important; 
 | 
                    } 
 | 
                    input { 
 | 
                        width: 230px; 
 | 
                        font-size: 28px; 
 | 
                        border: none; 
 | 
                    } 
 | 
                    input::-webkit-input-placeholder { /* WebKit browsers */ 
 | 
                        font-size: 28px; 
 | 
                        font-weight: 400; 
 | 
                        color: #B2B2B2; 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
        .rework_qd { 
 | 
            margin-top: 40px; 
 | 
            .rework_qd_title { 
 | 
                display: flex; 
 | 
                align-items: center; 
 | 
                padding: 0 30px 30px 30px; 
 | 
                span { 
 | 
                    font-size: 32px; 
 | 
                    font-weight: 500; 
 | 
                    color: #222222; 
 | 
                } 
 | 
                .x { 
 | 
                    width: 8px; 
 | 
                    height: 30px; 
 | 
                    background: #4275FC; 
 | 
                    border-radius: 2px; 
 | 
                    margin-right: 12px; 
 | 
                } 
 | 
            } 
 | 
            .rework_qd_item { 
 | 
                background: #ffffff; 
 | 
                padding: 30px; 
 | 
                display: flex; 
 | 
                flex-direction: column; 
 | 
                margin-bottom: 30px; 
 | 
                &:last-child { 
 | 
                    margin-bottom: 0 !important; 
 | 
                } 
 | 
                .rework_qd_item_i { 
 | 
                    display: flex; 
 | 
                    align-items: center; 
 | 
                    margin-bottom: 30px; 
 | 
                    &:last-child { 
 | 
                        margin-bottom: 0!important; 
 | 
                    } 
 | 
                    .black { 
 | 
                        font-size: 30px!important; 
 | 
                        font-weight: 400!important; 
 | 
                        color: #222222!important; 
 | 
                    } 
 | 
                    span { 
 | 
                        &:first-child { 
 | 
                            font-size: 26px; 
 | 
                            font-weight: 400; 
 | 
                            color: #666666; 
 | 
                        } 
 | 
                        &:last-child { 
 | 
                            font-size: 26px; 
 | 
                            font-weight: 400; 
 | 
                            color: #333333; 
 | 
                        } 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
        .rework_zw { 
 | 
            height: 168px; 
 | 
        } 
 | 
        .rework_footer { 
 | 
            width: calc(100% - 60px); 
 | 
            position: fixed; 
 | 
            bottom: 0; 
 | 
            display: flex; 
 | 
            align-items: center; 
 | 
            justify-content: space-between; 
 | 
            padding: 0 30px 68px 30px; 
 | 
            .rework_footer_add { 
 | 
                flex: 1; 
 | 
                height: 88px; 
 | 
                font-size: 30px; 
 | 
                font-weight: 500; 
 | 
                color: $nav-color; 
 | 
                background: #FFFFFF; 
 | 
                box-shadow: 0 0 12px 0 rgba(0,0,0,0.0800); 
 | 
                border-radius: 8px; 
 | 
                display: flex; 
 | 
                align-items: center; 
 | 
                justify-content: center; 
 | 
            } 
 | 
            .rework_footer_submit { 
 | 
                flex: 1; 
 | 
                height: 88px; 
 | 
                font-size: 30px; 
 | 
                font-weight: 500; 
 | 
                color: #ffffff; 
 | 
                background: $nav-color; 
 | 
                box-shadow: 0 0 12px 0 rgba(0,0,0,0.0800); 
 | 
                border-radius: 8px; 
 | 
                display: flex; 
 | 
                align-items: center; 
 | 
                justify-content: center; 
 | 
                border: none; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
</style> 
 |