liuhairui 1 жил өмнө
parent
commit
8613278923

+ 125 - 80
src/view/yunyin/shengchanguanli/components/addGongYi.vue

@@ -114,9 +114,9 @@
           :props="{children: 'children',label: 'label', value: 'value'}"
           style="border: 1px solid #ececec; padding: 10px;height: 400px;overflow: auto;"
           node-key="value"
-          :default-expanded-keys="['标准工艺']"
       >
       </el-tree>
+<!--         :default-expanded-keys="['标准工艺']"-->
     </el-dialog>
 
 <!--    工序损耗列表-->
@@ -152,11 +152,11 @@ const id = ref()
 const gxList = ref([])
 const yjList = ref()
 const cjList = ref([
-  {
-    label: '标准工艺',
-    value: '标准工艺',
-    children: []
-  }
+  // {
+  //   label: '标准工艺',
+  //   value: '标准工艺',
+  //   children: []
+  // }
 ])
 const gdzl_MachineList_address = ref()
 import { useUserStore } from '@/pinia/modules/user'
@@ -180,22 +180,31 @@ const add_gyzlent = async (event,id1,id2,id3) => {
     cjdisplay.value = true
   }
 
-  if (id2 === '车间名称' &&  event.key=== 'Enter') {
-    form['工艺名称'] = form['车间名称']
-    form['设备编号'] = []
-    //通过车间名称查询机台
-    const MachineList_jitai = await gdzl_MachineList({address:form['车间名称']});
-    gdzl_MachineList_address.value = MachineList_jitai.data;
-    form['shdh'] = ''
-    form['工序损耗名称'] = ''
-  }
-  if (id2 === '工序损耗' &&  event.key==='Tab' || id2 === '工序损耗' && event.key=== 'Enter') {
+  // if (id2 === '车间名称' &&  event.key=== 'Enter') {
+  //   form['设备编号'] = []
+  //   //通过车间名称查询机台
+  //   const MachineList_jitai = await gdzl_MachineList({address:form['车间名称']});
+  //   gdzl_MachineList_address.value = MachineList_jitai.data;
+  //   form['shdh'] = ''
+  //   form['工序损耗名称'] = ''
+  // }
+  if (id2 === '工序损耗' &&  event.key==='Tab') {
     if(form['车间名称']){
       await getGxshList();
-      if (gxshList.value[0].children.length > 1) {
-        gxshdisplay.value = true
-      }
+      // if (gxshList.value[0].children.length > 1) {
+      //   gxshdisplay.value = true
+      // }
+    }
+  }
+  if (id2 === '工序名称' &&  event.key==='Tab') {
+    console.log(213)
+    if(form['工艺名称'] === undefined){
+      form['工艺名称'] = '';
+    }
+    if(form['工序名称'] === undefined){
+      form['工序名称'] = '';
     }
+    form['工序损耗名称'] = `${form['工艺名称']} ${form['工序名称']}`;
   }
   if (event.keyCode === 13 || event.keyCode === 40) { // Enter 或向下箭头
     if(id3!=''){
@@ -222,22 +231,42 @@ const add_gyzlent = async (event,id1,id2,id3) => {
 }
 
 const open = async (gdbh, gxlist) => {
-  visible.value = true
+  Object.keys(form).forEach(key => {
+    form[key] = '';
+  });
 
+  visible.value = true
   id.value = gdbh
   const res = await PrintDetailList({workOrder: id.value})
-  const chejian = await getDepartName()
-  if (chejian && Array.isArray(chejian.data) && chejian.data.length === 0) {
-  } else {
-    cjList.value = [
-      {
-        label: '标准工艺',
-        value: '标准工艺',
-        children: []
-      }
-    ]
-    initChejian(chejian.data['标准工艺'])
+  const apiData = await getDepartName()
+  console.log(apiData)
+  function transformDataToTreeFormat(data) {
+    return Object.entries(data).map(([key, value]) => {
+      // key是车间名称,value是车间内的操作列表
+      const children = Object.entries(value).map(([workshop, operations]) => ({
+        label: workshop,
+        children: operations.map(operation => ({
+          label: operation,
+          value: operation // 可以根据需要添加更多属性
+        }))
+      }));
+      return { label: key, children };
+    });
   }
+  // 使用ref来管理转换后的数据
+  cjList.value = ref(transformDataToTreeFormat(apiData.data));
+
+  // if (chejian && Array.isArray(chejian.data) && chejian.data.length === 0) {
+  // } else {
+  //   cjList.value = [
+  //     {
+  //       label: '标准工艺',
+  //       value: '标准工艺',
+  //       children: []
+  //     }
+  //   ]
+  //   initChejian(chejian.data['标准工艺'])
+  // }
   yjList.value = res.data
   gxList.value = gxlist
 }
@@ -245,22 +274,30 @@ const open = async (gdbh, gxlist) => {
 //工序损耗列表
 const gxshList = ref([])
 const getGxshList = async ()=>{
-  const WastageList_data = await WastageList({search: form['车间名称']})
+  const WastageList_data = await WastageList({process: form.工艺名称})
   console.log(WastageList_data)
-  gxshList.value = [{
-    label: form['车间名称'],
-    value: form['车间名称'],
-    children: []
-  }]
-  if (WastageList_data.data.length === 0) return
-  if (WastageList_data.data.length > 1) {
-    gxshList.value[0].children = WastageList_data.data.map(item => {
-      return { label: `${item.编号} - ${item.名称}`, label2: item.名称, UniqId: item.UniqId, value: item.编号 }
+  if(WastageList_data.data === null || WastageList_data.data === ''){
+    form['shdh'] = '';
+    ElMessage({
+      type: 'warning',
+      message: '未获取到工序损耗'
     })
-  } else {
-    form['shdh'] = WastageList_data.data[0].编号;
-    form['工序损耗名称'] = WastageList_data.data[0].名称;
   }
+  form['shdh'] = WastageList_data.data
+  // gxshList.value = [{
+  //   label: form['车间名称'],
+  //   value: form['车间名称'],
+  //   children: []
+  // }]
+  // if (WastageList_data.data.length === 0) return
+  // if (WastageList_data.data.length > 1) {
+  //   gxshList.value[0].children = WastageList_data.data.map(item => {
+  //     return { label: `${item.编号} - ${item.名称}`, label2: item.名称, UniqId: item.UniqId, value: item.编号 }
+  //   })
+  // } else {
+  //   form['shdh'] = WastageList_data.data[0].编号;
+  //   form['工序损耗名称'] = WastageList_data.data[0].名称;
+  // }
 }
 //点击工序损耗列表数据
 const gxshselectHandle = async (node)=>{
@@ -271,54 +308,62 @@ const gxshselectHandle = async (node)=>{
   }
 }
 const selectHandle = async (node)=>{
-  if (node.children && node.children.length> 0) return
-  function findParentInTree(tree, targetValue) {
-    for (let node of tree) {
-      // 如果找到了目标值,返回当前节点作为上级
-      if (node.value === targetValue) {
-        return node;
-      }
-      // 如果当前节点有子节点,递归地在子节点中查找
-      if (node.children && node.children.length > 0) {
-        let parent = findParentInTree(node.children, targetValue);
-        if (parent) return parent
-      }
-    }
-    // 如果没有找到目标值或其上级,返回null
-    return null;
-  }
-  const _node = findParentInTree(cjList.value, node.value)
-  if(_node.parent){
-    form['车间名称'] = _node.parent
+  // if (node.children && node.children.length> 0) return
+  // function findParentInTree(tree, targetValue) {
+  //   for (let node of tree) {
+  //     // 如果找到了目标值,返回当前节点作为上级
+  //     if (node.value === targetValue) {
+  //       return node;
+  //     }
+  //     // 如果当前节点有子节点,递归地在子节点中查找
+  //     if (node.children && node.children.length > 0) {
+  //       let parent = findParentInTree(node.children, targetValue);
+  //       if (parent) return parent
+  //     }
+  //   }
+  //   // 如果没有找到目标值或其上级,返回null
+  //   return null;
+  // }
+  // const _node = findParentInTree(cjList.value, node.value)
+  // if(_node.parent){
+  //   form['车间名称'] = _node.parent
+  // }else{
+  //   form['车间名称'] = _node.label
+  // }
+  // form['工艺名称'] = _node.label
+
+  console.log(node)
+  if(node.value){
+    form['工艺名称'] = node.value
+    form['工序损耗名称'] = node.value
+    cjdisplay.value = false
   }else{
-    form['车间名称'] = _node.label
+    form['车间名称'] = node.label
   }
-  form['工艺名称'] = _node.label
   form['设备编号'] = []
   //通过车间名称查询机台
   const MachineList_jitai = await gdzl_MachineList({address:form['车间名称']});
   gdzl_MachineList_address.value = MachineList_jitai.data;
   form['shdh'] = ''
-  form['工序损耗名称'] = ''
   //通过车间名称查询工序损耗
   await getGxshList()
-  cjdisplay.value = false
-}
 
-const initChejian = (data) => {
-  Object.keys(data).map( (name, index)=>{
-    const tmp = {
-      label: name, value: name, children: []
-    }
-    data[name].map(item => {
-      tmp.children.push({
-        label: item, value: item,parent: name,
-      })
-    })
-    cjList.value[0].children.push(tmp)
-  })
 }
 
+// const initChejian = (data) => {
+//   Object.keys(data).map( (name, index)=>{
+//     const tmp = {
+//       label: name, value: name, children: []
+//     }
+//     data[name].map(item => {
+//       tmp.children.push({
+//         label: item, value: item,parent: name,
+//       })
+//     })
+//     cjList.value[0].children.push(tmp)
+//   })
+// }
+
 const changeHandle = (v) => {
   const no = '0' + v.no
   let list = gxList.value.map(item => {