<template> 
 | 
  <div class="tl"> 
 | 
    <!--    工单详情信息    --> 
 | 
    <V-WorkOrderInfo :info="info"></V-WorkOrderInfo> 
 | 
    <div class="tl_title"> 
 | 
      <div class="tl_title_left"> 
 | 
        <div class="tl_title_left_x"></div> 
 | 
        <span>投料信息</span> 
 | 
        <span>{{total == 0 ? '' : total}}{{formList[formList.length - 1].dw ? formList[formList.length - 1].dw : ''}}</span> 
 | 
      </div> 
 | 
      <div class="tl_title_right" @click="add"> 
 | 
        <img src="@/assets/icon/gongdan_ic_shoudong@2x.png" alt="" /> 
 | 
        <span>增加投料</span> 
 | 
      </div> 
 | 
    </div> 
 | 
    <van-swipe-cell v-for="(item, index) in materialList" :key="index"> 
 | 
      <div class="tl_list"> 
 | 
        <div class="tl_list_item" @click="open1(index)"> 
 | 
          <div class="tl_list_item_label">选择物料</div> 
 | 
          <div class="tl_list_item_go" v-if="!item.materialName"> 
 | 
            <span :style="item.materialName ? 'color: #000000;' : ''"> 
 | 
              点击跳转到物料列表 
 | 
            </span> 
 | 
            <van-icon name="arrow" color="#999999" /> 
 | 
          </div> 
 | 
          <div class="tl_list_item_wl" v-else> 
 | 
            <div class="tl_list_item_wl_top"> 
 | 
              <span>{{ item.materialName }}</span> 
 | 
              <span> | {{ item.materialCode }}</span> 
 | 
            </div> 
 | 
            <div class="tl_list_item_wl_bottom"> 
 | 
              <span class="green" v-if="item.qualityType == 0">合格</span> 
 | 
              <span class="yellow" v-else-if="item.qualityType == 1">不良</span> 
 | 
              <span class="red" v-else-if="item.qualityType == 2">报废</span> 
 | 
              <span>{{ item.procedureName ? ` / ${item.procedureName}` : ' / -' }}</span> 
 | 
              <span>{{ item.locationName ? ` / ${item.locationName}` : ' / -' }}</span> 
 | 
              <span>{{ item.batch ? ` / ${item.batch}` : ' / -' }}</span> 
 | 
            </div> 
 | 
          </div> 
 | 
        </div> 
 | 
        <div class="tl_list_item"> 
 | 
          <div class="tl_list_item_label">投料数量{{ item.unitAttribute }}</div> 
 | 
          <div class="tl_list_item_go"> 
 | 
            <input type="text" @blur="changeNumber(item.num, index, item.unitAttribute)" v-model="item.num" /> 
 | 
          </div> 
 | 
        </div> 
 | 
      </div> 
 | 
      <template #right> 
 | 
        <van-button square style="height: 100%;" type="danger" text="删除" @click="dele(index)" /> 
 | 
      </template> 
 | 
    </van-swipe-cell> 
 | 
    <div class="tl_zw"></div> 
 | 
    <div class="tl_footer"> 
 | 
      <button class="tl_footer_submit" v-preventReClick @click="submit">提交</button> 
 | 
    </div> 
 | 
  </div> 
 | 
  <!--  入库物料  --> 
 | 
  <MaterialT :show="show" :workorderId="String(workorderId)" :deviceId="deviceId" @close="close" @value="getValue" /> 
 | 
  <!--  工装器具  --> 
 | 
  <!-- <Tooling :show="gzShow" :attribute="info.type === 2 ? `${Attribute.BL}` : `${Attribute.HG},${Attribute.HH}`" :classification="true" @close="close" @value="getValue" /> --> 
 | 
</template> 
 | 
  
 | 
<script setup lang="ts"> 
 | 
    import { ref, onMounted, watch } from 'vue' 
 | 
    import { useRoute, useRouter } from "vue-router" 
 | 
    import { queryById, createMaterial, createMaterialStandard } from '@/apis/WorkOrderAPI' 
 | 
    import { Toast } from 'vant' 
 | 
    import { REGULAR } from '@/utils/utils' 
 | 
    import { Attribute } from '@/enum' 
 | 
    // import Tooling from '@/components/common/Tooling.vue' 
 | 
    import VWorkOrderInfo from '@/components/common/WorkOrderInfo.vue' 
 | 
    // import Material from '@/components/common/Material.vue' 
 | 
    import MaterialT from '@/components/common/MaterialT.vue' 
 | 
  
 | 
    const route = useRoute() 
 | 
    const router = useRouter() 
 | 
  
 | 
    // 投料索引 
 | 
    let indexs = ref<number>() 
 | 
  
 | 
    let info: any = ref({}) 
 | 
    let total = ref<number>(0) 
 | 
    let workorderId = ref<string>('') 
 | 
    let deviceId = ref<string>('') 
 | 
    let gzShow = ref<boolean>(false) 
 | 
  
 | 
    let show = ref<boolean>(false) 
 | 
  
 | 
    // 投料信息 
 | 
    let materialList: any = ref([ 
 | 
      { 
 | 
        id: '', 
 | 
        materialName: '', 
 | 
        materialCode: '', 
 | 
        qualityType: '', 
 | 
        procedureName: '', 
 | 
        locationName: '', 
 | 
        batch: '', 
 | 
        num: '', 
 | 
        unitAttribute: '' 
 | 
      } 
 | 
    ]) 
 | 
  
 | 
    // 投料信息数组 
 | 
    let formList: any = ref([ 
 | 
      { 
 | 
        id: Date.now(), 
 | 
        toolingTypeId: '',    // 工装类型 
 | 
        toolingTypeName: '',// 工装类型名称 
 | 
        workClothesId: '',    // 工装 
 | 
        workClothesName: '',// 工装名称 
 | 
        num: '',              // 数量 
 | 
        attribute: '',         // 工装属性 
 | 
        attributeType: '',         // 工装属性类型 
 | 
        dw: '',         // 物料单位 
 | 
        unitAttribute: '' 
 | 
      } 
 | 
    ]) 
 | 
  
 | 
    const gzshow = ref<boolean>(false) 
 | 
  
 | 
    // 获取物料数据 
 | 
    const getValue = (item: any) => { 
 | 
      for (let i = 0; i < materialList.value.length; i++) { 
 | 
        if (item.id === materialList.value[i].id) { 
 | 
          Toast.fail({ message: '不能重复选择相同物料' }) 
 | 
          return 
 | 
        } 
 | 
      } 
 | 
      materialList.value[indexs.value as number].id = item.id 
 | 
      materialList.value[indexs.value as number].materialName = item.materialName 
 | 
      materialList.value[indexs.value as number].num = item.num 
 | 
      materialList.value[indexs.value as number].batch = item.batch 
 | 
      materialList.value[indexs.value as number].locationName = item.locationName 
 | 
      materialList.value[indexs.value as number].materialCode = item.materialCode 
 | 
      materialList.value[indexs.value as number].procedureName = item.procedureName 
 | 
      materialList.value[indexs.value as number].qualityType = item.qualityType 
 | 
      materialList.value[indexs.value as number].unitAttribute = item.unitAttribute 
 | 
      show.value = false 
 | 
      // return 
 | 
      //   if (!item.umodelName) { 
 | 
      //       Toast.fail({ message: '该工装暂无物料,不能进行投料' }) 
 | 
      //       return 
 | 
      //   } 
 | 
      //   formList.value[indexs.value as number].toolingTypeId = item.cmodel1BigName 
 | 
      //   formList.value[indexs.value as number].toolingTypeName = item.categoryId 
 | 
      //   formList.value[indexs.value as number].workClothesId = item.id 
 | 
      //   formList.value[indexs.value as number].workClothesName = item.code 
 | 
      //   formList.value[indexs.value as number].attribute = item.smodelCode 
 | 
      //   formList.value[indexs.value as number].attributeType = item.smodelLabel 
 | 
      //   formList.value[indexs.value as number].dw = item.umodelName 
 | 
      //   formList.value[indexs.value as number].num = item.num 
 | 
      //   gzShow.value = false 
 | 
    } 
 | 
  
 | 
    const close = () => { 
 | 
        show.value = false 
 | 
    } 
 | 
  
 | 
    // 失去焦点验证整数小数 
 | 
    const changeNumber = (num: any, index: number, unitAttribute: number): void => { 
 | 
      if (unitAttribute === 0 && num !== '') { 
 | 
        if(!REGULAR.positiveInteger.test(num)){ 
 | 
          Toast({ message: '只能输入正整数' }) 
 | 
          materialList.value[index].num = '' 
 | 
        } 
 | 
      } else if (unitAttribute === 1 && num !== '') { 
 | 
        if(!REGULAR.number.test(num)){ 
 | 
          Toast({ message: '只能输入正整数或小数(最多四位)' }) 
 | 
          materialList.value[index].num = '' 
 | 
        } 
 | 
      } 
 | 
      if (num <= 0) { 
 | 
        Toast({ message: '投料数量不能小于等于0' }) 
 | 
        materialList.value[index].num = '' 
 | 
      } 
 | 
    } 
 | 
  
 | 
    // 打开工装弹框 
 | 
    const open1 = (index: number): void => { 
 | 
      indexs.value = index 
 | 
      show.value = true 
 | 
    } 
 | 
  
 | 
    // 添加投料信息 
 | 
    const add = (): void => { 
 | 
      materialList.value.unshift({ 
 | 
        id: '', 
 | 
        materialName: '', 
 | 
        materialCode: '', 
 | 
        qualityType: '', 
 | 
        procedureName: '', 
 | 
        locationName: '', 
 | 
        batch: '', 
 | 
        num: '', 
 | 
        unitAttribute: '' 
 | 
      }) 
 | 
    } 
 | 
  
 | 
    // 删除投料信息 
 | 
    const dele = (index: number): void => { 
 | 
      if (materialList.value.length === 1) { 
 | 
        Toast('至少保留一条投料信息') 
 | 
        return 
 | 
      } 
 | 
      materialList.value.splice(index, 1) 
 | 
    } 
 | 
  
 | 
    // 提交手动投料 
 | 
    const submit = (): void => { 
 | 
      let isOpen: any = true 
 | 
      materialList.value.forEach((item: any, index: number) => { 
 | 
        if (!item.num) { 
 | 
          Toast({ message: `请先完善第${index + 1}条投料信息`, duration: 2000 }) 
 | 
          isOpen = false 
 | 
        } 
 | 
      }) 
 | 
      let total: number = 0 
 | 
      materialList.value.forEach((item: any, index: number) => { 
 | 
        if (item.num > 0) { 
 | 
          total += Number(item.num) 
 | 
        } 
 | 
      }) 
 | 
      if (info.value.bomType !== 1 && info.value.hasBom !== 1) { 
 | 
        if (total > info.value.planNum) { 
 | 
          Toast.fail({ message: '投料数量不能大于计划数量', duration: 2000 }) 
 | 
          return 
 | 
        } 
 | 
      } 
 | 
      if (isOpen) { 
 | 
        let recordList: any = [] 
 | 
        materialList.value.forEach((item: any) => { 
 | 
          recordList.push({ wstockId: item.id, num: item.num }) 
 | 
        }) 
 | 
        createMaterialStandard({ 
 | 
          id: route.query.id, 
 | 
          recordList: recordList 
 | 
        }).then(res => { 
 | 
          if (res.code === 200) { 
 | 
            Toast.success({ message: '投料成功', duration: 2000, forbidClick: true }) 
 | 
            setTimeout(() => { 
 | 
              router.go(-1) 
 | 
            }, 2000) 
 | 
          } 
 | 
        }) 
 | 
      } 
 | 
    } 
 | 
  
 | 
    // 获取详情数据 
 | 
    const queryByIds = (): void => { 
 | 
      queryById(route.query.id).then(res => { 
 | 
        if (res.code === 200) { 
 | 
          info.value = res.data 
 | 
          workorderId.value = route.query.id as string 
 | 
          deviceId.value = res.data.pgmodel.id 
 | 
        } 
 | 
      }) 
 | 
    } 
 | 
  
 | 
    // 根据id查询工装 
 | 
    // const getListByConditions = (id: any): void => { 
 | 
    //     getListByCondition({ 
 | 
    //         categoryId: id 
 | 
    //     }).then(res => { 
 | 
    //         if (res.code === 200) { 
 | 
    //             console.log(res) 
 | 
    //         } 
 | 
    //     }) 
 | 
    // } 
 | 
  
 | 
    watch(() => formList.value, (news) => { 
 | 
        total.value = 0 
 | 
        news.forEach((element: any) => { 
 | 
            total.value = total.value + Number(element.num) 
 | 
        }) 
 | 
    }, { deep: true }) 
 | 
  
 | 
    onMounted(() => { 
 | 
      queryByIds() 
 | 
    }) 
 | 
</script> 
 | 
  
 | 
<style lang="scss" scoped> 
 | 
  .tl { 
 | 
    width: 100%; 
 | 
    height: 100%; 
 | 
    position: absolute; 
 | 
    background: #F7F7F7; 
 | 
    .tl_title { 
 | 
      display: flex; 
 | 
      align-items: center; 
 | 
      justify-content: space-between; 
 | 
      padding: 30px; 
 | 
      .tl_title_left { 
 | 
        display: flex; 
 | 
        align-items: center; 
 | 
        .tl_title_left_x { 
 | 
          width: 8px; 
 | 
          height: 30px; 
 | 
          background: $nav-color; 
 | 
          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; 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
      .tl_title_right { 
 | 
        display: flex; 
 | 
        align-items: center; 
 | 
        img { 
 | 
          width: 28px; 
 | 
          height: 28px; 
 | 
          margin-right: 12px; 
 | 
        } 
 | 
        span { 
 | 
          font-size: 28px; 
 | 
          font-weight: 400; 
 | 
          color: $nav-color; 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    .tl_list { 
 | 
      display: flex; 
 | 
      flex-direction: column; 
 | 
      background: white; 
 | 
      padding: 0 30px; 
 | 
      margin-bottom: 20px; 
 | 
      .tl_list_item { 
 | 
        min-height: 98px; 
 | 
        // padding: 20px 0; 
 | 
        box-sizing: border-box; 
 | 
        display: flex; 
 | 
        align-items: center; 
 | 
        justify-content: space-between; 
 | 
        border-bottom: 1px solid #E5E5E5; 
 | 
        &:last-child { 
 | 
          border: none !important; 
 | 
        } 
 | 
        .tl_list_item_label { 
 | 
          font-size: 30px; 
 | 
          font-weight: 400; 
 | 
          color: #222222; 
 | 
        } 
 | 
        .tl_list_item_wl { 
 | 
          display: flex; 
 | 
          flex-direction: column; 
 | 
          align-items: end; 
 | 
          .tl_list_item_wl_top { 
 | 
            display: flex; 
 | 
            align-items: center; 
 | 
            span { 
 | 
              font-size: 28px; 
 | 
              color: #222222; 
 | 
            } 
 | 
          } 
 | 
          .tl_list_item_wl_bottom { 
 | 
            display: flex; 
 | 
            align-items: center; 
 | 
            span { 
 | 
              font-size: 28px; 
 | 
              color: #222222; 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
        .tl_list_item_go { 
 | 
          display: flex; 
 | 
          align-items: center; 
 | 
          input { 
 | 
            text-align: right; 
 | 
            width: 180px; 
 | 
            height: 60px; 
 | 
            border-radius: 8px; 
 | 
            border: 1PX solid #E5E5E5; 
 | 
            padding: 0 30px; 
 | 
            box-sizing: border-box; 
 | 
            font-size: 28px; 
 | 
            font-weight: 400; 
 | 
            color: #333333; 
 | 
          } 
 | 
          span { 
 | 
            font-size: 28px; 
 | 
            font-weight: 400; 
 | 
            color: #999999; 
 | 
            margin-right: 10px; 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    .tl_zw { 
 | 
      height: 160px; 
 | 
    } 
 | 
    .tl_footer { 
 | 
      width: 100%; 
 | 
      position: fixed; 
 | 
      bottom: 0; 
 | 
      left: 0; 
 | 
      padding: 0 30px 68px 30px; 
 | 
      box-sizing: border-box; 
 | 
      .tl_footer_submit { 
 | 
        width: 690px; 
 | 
        height: 88px; 
 | 
        border: none; 
 | 
        background: #4275FC; 
 | 
        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> 
 |