wangfei
2024-11-08 3c4b340b58d0d0bdbc3db74b5721586dd964f86c
UI-Project/src/views/Returns/returns.vue
@@ -1,12 +1,14 @@
<script lang="ts" setup>
import {Search} from "@element-plus/icons-vue";
import {reactive} from "vue";
import {onBeforeUnmount, onMounted, onUnmounted, reactive, ref} from "vue";
import {useRouter} from "vue-router"
import {ElMessage} from 'element-plus'
import {useI18n} from 'vue-i18n'
import {host, WebSocketHost} from '@/utils/constants'
import request from "@/utils/request"
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
const router = useRouter()
import type { TableColumnCtx } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const {t} = useI18n()
const dialogFormVisible = ref(false)
const blind = ref(false)
const blinda = ref(false)
@@ -30,48 +32,39 @@
const number = ref('');
const canSelectProject = ref(true);
const canStartLoading = ref(false);
import { WebSocketHost ,host} from '@/utils/constants'
import request from "@/utils/request"
const ida = ref(null);
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
import { ref, onMounted, onUnmounted, onBeforeUnmount } from "vue";
const selectedProjectNo = ref(''); // 当前选中的工程号
const selectedProjectNoa = ref(''); // 当前选中的工程号
const selectedValue = ref(''); // 当前选中的宽
const selectedValuea = ref('');
const ida = ref(null);
const selectedProjectNo = ref('');
const selectedProjectNoa = ref('');
const selectedValue = ref('');
const selectedValuea = ref('');
const selectedValueb = ref('');
const selectedValuec = ref('');
// const upstatus = ref('上片机手动状态:'); // 假设这个用于显示自动/手动状态
const selectedValuec = ref('');
const upstatus = ref(t('basicData.machineaa'));
const cuttingMachine = ref(''); // 假设这个用于存储后端返回的状态值(0或1)
const cuttingMachine = ref('');
const cuttingMachineStatusColor = ref('#911005'); // 用于动态设置i标签的背景色 
const inKageWord = ref(0); // 用于存储要传递给接口的inKageWord值 
const options = ref<any[]>([]); // 下拉选项列表
const selectOptions = ref<Array<any>>([]); // 下拉选选项数组
const selectOptionsa = ref<Array<any>>([]); // 下拉选选项数组
const selectOptionsb = ref<Array<any>>([]); // 下拉选选项数组
const selectOptionsc = ref<Array<any>>([]); // 下拉选选项数组
  const tableDataa = ref([])
  const tableData = reactive([]);
  const fetchTableData = async () => {
const options = ref<any[]>([]);
const selectOptions = ref<Array<any>>([]);
const selectOptionsa = ref<Array<any>>([]);
const selectOptionsb = ref<Array<any>>([]);
const selectOptionsc = ref<Array<any>>([]);
const tableDataa = ref([])
const tableData = reactive([]);
const fetchTableData = async () => {
  try {
    const response = await request.get("/loadGlass/up-patten-usage/prioritylist");
    // 检查响应状态
    if (response.code === 200) {
      // 更新表格数据
      console.log('成功获取表格数据:', response.data);
      tableData.splice(0, tableData.length, ...response.data);
      // window.localStorage.setItem('engineeringId', response.data[0].engineeringId)
      // 获取唯一值
      const uniqueWidths = new Set(response.data.map(item => item.width));
      const uniqueHeights = new Set(response.data.map(item => item.height));
      const uniqueFilmsIds = new Set(response.data.map(item => item.filmsId));
      const uniqueWidths = new Set(response.data.map(item => item.width));
      const uniqueHeights = new Set(response.data.map(item => item.height));
      const uniqueFilmsIds = new Set(response.data.map(item => item.filmsId));
      const uniqueThicknesses = new Set(response.data.map(item => item.thickness));  
  
      selectOptions.value = Array.from(uniqueWidths).map(width => ({
      value: width, // 假设这是你想要作为value的属性
      label: width, // 假设这是你想要显示的label
    }));
      selectOptions.value = Array.from(uniqueWidths).map(width => ({
        value: width,
        label: width,
      }));
      selectOptionsa.value = Array.from(uniqueHeights).map(height => ({ 
      value: height, 
      label: height, 
@@ -93,12 +86,12 @@
  }
};
const handlezhiban = () => {
  dialoglea.value = true; // 打开绑定架子对话框
  dialoglea.value = true;
  fetchFlowCardId(); 
};
const selectproject = () => {
  dialogFormVisible.value = true;
  selectgong();
  dialogFormVisible.value = true;
  selectgong();
};
// 值班信息
const fetchFlowCardId = async () => {
@@ -110,14 +103,11 @@
    if (response.code == 200) {
      ElMessage.success(response.message);
      tableDatax.value = response.data;
      console.log(tableDatax.value);
      console
    } else {
      ElMessage.error(response.message);
    }
}
catch (error) {
    // 处理错误
    console.error(error);
  }
}
@@ -131,15 +121,15 @@
  }
};
onMounted(() => {
  list('');
  list('');
  fetchOptions('');
  socket = initializeWebSocket(socketUrl, handleMessage);
});
  onUnmounted(() => {
    if (socket) {
onUnmounted(() => {
  if (socket) {
    closeWebSocket(socket);
    }
    });
  }
});
const list = async () => {  
  try {  
    const response = await request.get('/loadGlass/LoadGlass/list');  
@@ -166,30 +156,6 @@
    console.error('Error fetching options:', error);  
  }  
}; 
// 假设这是您的响应处理函数
// request.get("/loadGlass/LoadGlass/list").then((res) => {
//       if (res.code == 200) {
//           tableDataa.value = res.data
//           if (tableDataa.value.length === 4) {
//           if (tableDataa.value[0].patternHeight > 0) {
//           flake.value = true;
//           }
//          if (tableDataa.value[1].patternHeight > 0) {
//           flakea.value = true;
//           }
//          if (tableDataa.value[2].patternHeight > 0) {
//           flakeb.value = true;
//           }
//          if (tableDataa.value[3].patternHeight > 0) {
//           flakec.value = true;
//           }
//            }
//           } else {
//           ElMessage.warning(res.message)
//           // router.push("/login")
//           }
//           });
//定义接收加载表头下拉数据
const titleSelectJson = ref({
  processType: [],
})
@@ -198,7 +164,6 @@
})
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/loadGlass/api/talk/loadGlass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  if(data.prioritylist!=null){
  tableData.splice(0, tableData.length, ...data.prioritylist[0]);
@@ -228,15 +193,11 @@
const requestData = {  
  state: 100  
};  
const selectgong = async (queryString: string) => {
  try  {
    const response = await request.post('/loadGlass/optimizeProject/listByState',{
      ...requestData,
      query: queryString
      ...requestData,
      projectNo: queryString
    })
    if (response.code == 200) {
      titleSelectJson.value.processType = response.data;
@@ -245,23 +206,20 @@
    }
}
catch (error) {
    // 处理错误
    console.error(error);
  }
}
const fetchOptions = async (queryString: string) => {
  try {
    // 发送请求到后端接口
    const response = await request.post('/loadGlass/optimizeProject/listByState', {
      ...requestData,
      query: queryString // 将查询字符串作为参数传递
    });
    if (response.code == 200) {
    // titleSelectJson.value.processType = response.data;
    console.log(response.data);
    } else {
      ElMessage.warning(response.data);
const fetchOptions = async (queryString: string) => {
  try {
    const response = await request.post('/loadGlass/optimizeProject/listByState', {
      ...requestData,
      query: queryString
    });
    if (response.code == 200) {
      // titleSelectJson.value.processType = response.data;
      console.log(response.data);
    } else {
      ElMessage.warning(response.data);
    }  
  } catch (error) {  
    console.error('Error fetching options:', error);  
@@ -271,8 +229,8 @@
const handleInputChange = async (value: string) => {  
  if (value) {  
    await fetchOptions(value);  
  } else {
    options.value = []; // 清空选项列表
  } else {
    options.value = [];
  }  
};  
  // 处理用户输入变化的方法  
@@ -288,38 +246,27 @@
});
// 添加
const handleBindRack = (row) => {
  workstationId.value = row.workstationId; // 假设rackNumber是架号字段的属性名
  workstationId.value = row.workstationId;
  ida.value = row.id;
  add.value = true; // 打开绑定架子对话框
  add.value = true;
};
// 添加
    const handleConfirm = async () => {
      // console.log('id.value:', id.value);
  if ((ida.value === 2 || ida.value === 4) && (parseInt(selectedValuea.value, 10) >= 2700 )) {
const handleConfirm = async () => {
  if ((ida.value === 2 || ida.value === 4) && (parseInt(selectedValuea.value, 10) >= 2700)) {
    try {
    const response = await request.post('/loadGlass/LoadGlass/updateGlassMessage', {
      id: workstationId.value,
      workstationId: workstationId.value,
      patternHeight: selectedValuea.value,
      patternWidth: selectedValue.value,
      filmsId: selectedValueb.value,
      patternThickness: selectedValuec.value,
      number: number.value
    });
      // window.localStorage.setItem('workstationId', workstationId.value)
      // window.localStorage.setItem('patternHeight', selectedValuea.value)
      // window.localStorage.setItem('patternWidth', selectedValue.value)
      // window.localStorage.setItem('number', number.value)
      const response = await request.post('/loadGlass/LoadGlass/updateGlassMessage', {
        id: workstationId.value,
        workstationId: workstationId.value,
        patternHeight: selectedValuea.value,
        patternWidth: selectedValue.value,
        filmsId: selectedValueb.value,
        patternThickness: selectedValuec.value,
        number: number.value
      });
    if (response.code == 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      // window.location.reload()
      add.value = false;
     tableDataa.value = response.data;
      // let workstationId = window.localStorage.getItem('workstationId')
      // let patternHeight = window.localStorage.getItem('patternHeight')
      // let patternWidth = window.localStorage.getItem('patternWidth')
      // let number = window.localStorage.getItem('number')
      if (selectedValuea.value !== '0' && selectedValue.value !== '0' && number.value !== '0' && workstationId.value === '1') {
      flake.value = true
    } else if (selectedValuea.value !== '0' && selectedValue.value !== '0' && number.value !== '0' && workstationId.value === '2'){
@@ -329,23 +276,13 @@
    }else if (selectedValuea.value !== '0' && selectedValue.value !== '0' && number.value !== '0' && workstationId.value === '4'){
      flakec.value = true
    }
    //   if (patternHeight !== '0' && patternWidth !== '0' && number !== '0' && workstationId === '1') {
    //   flake.value = true
    // } else if (patternHeight !== '0' && patternWidth !== '0' && number !== '0' && workstationId === '2'){
    //   flakea.value = true
    // }else if (patternHeight !== '0' && patternWidth !== '0' && number !== '0' && workstationId === '3'){
    //   flakeb.value = true
    // }else if (patternHeight !== '0' && patternWidth !== '0' && number !== '0' && workstationId === '4'){
    //   flakec.value = true
    // }
      selectedValuea.value = '';
      selectedValue.value = '';
      selectedValueb.value = '';
      selectedValuec.value = '';
      number.value = '';
        list()
      list()
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.message);
    }
  } catch (error) {  
@@ -364,9 +301,7 @@
      number: number.value
    }); 
    if (response.code == 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      // window.location.reload()
      add.value = false;
     tableDataa.value = response.data;
      if (selectedValuea.value !== '0' && selectedValue.value !== '0' && number.value !== '0' && workstationId.value === '1') {
@@ -411,28 +346,23 @@
      number: 0
    });
    if (response.code == 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      adda.value = false;
     tableDataa.value = response.data;
      // window.localStorage.setItem('workstationId', response.data.workstationId)
      // let workstationId = window.localStorage.getItem('workstationId')
      tableDataa.value = response.data;
      if (workstationId.value == '1') {
      flake.value = false
    } else if (workstationId.value == '2'){
      flakea.value = false
    }else if (workstationId.value == '3'){
      flakeb.value = false
    }else if (workstationId.value == '4'){
      flakec.value = false
    }
        list()
      } else {
      // 请求失败,显示错误消息
        flake.value = false
      } else if (workstationId.value == '2') {
        flakea.value = false
      } else if (workstationId.value == '3') {
        flakeb.value = false
      } else if (workstationId.value == '4') {
        flakec.value = false
      }
      list()
    } else {
      ElMessage.error(response.message);
    }
  } catch (error) {
    // 处理错误
    console.error(error);
  }
};
@@ -444,9 +374,7 @@
    })
      window.localStorage.setItem('engineeringId', selectedProjectNo.value)
    if (response.code == 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      // window.location.reload()
      dialogFormVisible.value = false;
      tableData.splice(0, tableData.length, ...response.data);
      selectedProjectNo.value = ''
@@ -473,13 +401,10 @@
      label: thickness,  
    })); 
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.message);
      // ElMessage.error(response.msg);
    }
}
catch (error) {
    // 处理错误
    console.error(error);
  }
}
@@ -493,18 +418,14 @@
    state: 1,
    })
    if (response.code == 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      // window.location.reload()
      blind.value = false;
      selectedProjectNoa.value = '';
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.message);
    }
}
catch (error) {
    // 处理错误
    console.error(error);
  }
    } else if (markingMachineStatus.value === '#911005' || cuttingMachineStatus.value === '#911005') {  
@@ -514,21 +435,20 @@
}
// 暂停
const handlea = async () => {
  try  {
  let engineeringId = window.localStorage.getItem('engineeringId')
console.log(engineeringId);
if (engineeringId !== '') {
  const response = await request.post('/loadGlass/engineering/engineering/pauseTask', {
      engineeringId: engineeringId,
      state: 0,
    })
    if (response.code == 200) {
      ElMessage.success(response.message);
      blinda.value = false;
      // tableData.splice([]);
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.message);
  try {
    let engineeringId = window.localStorage.getItem('engineeringId')
    console.log(engineeringId);
    if (engineeringId !== '') {
      const response = await request.post('/loadGlass/engineering/engineering/pauseTask', {
        engineeringId: engineeringId,
        state: 0,
      })
      if (response.code == 200) {
        ElMessage.success(response.message);
        blinda.value = false;
        // tableData.splice([]);
      } else {
        ElMessage.error(response.message);
    }
  }
    else  {
@@ -539,7 +459,6 @@
    }
}
catch (error) {
    // 处理错误
    console.error(error);
  }
}
@@ -554,13 +473,9 @@
      state: 0,
    })
    if (response.code == 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      // window.location.reload()
      blindb.value = false;
      tableData.splice([]);
      // 请求失败,显示错误消息
      ElMessage.error(response.message);
    }
  }
@@ -572,7 +487,6 @@
    }
}
catch (error) {
    // 处理错误
    console.error(error);
  }
}
@@ -603,7 +517,7 @@
}  
// 开始上片
const handleBind = (row) => {
  blind.value = true; // 打开绑定架子对话框
  blind.value = true;
};
// 暂停
const handleBinda = (row) => {
@@ -613,11 +527,10 @@
const handleBindb = (row) => {
  blindb.value = true; 
};
// 删除
const handleBindRacka = (row) => {
  workstationId.value = row.workstationId;
  adda.value = true;
  adda.value = true;
};
// 定义一个响应式引用,用于存储颜色状态  
const markingMachineStatus = ref('#911005');  
@@ -638,76 +551,34 @@
  const newState = row.state === 100 ? 0 : 100;  
  try {  
    // 发送请求到后端更新状态  
    const response = await request.post('/loadGlass/up-patten-usage/updateGlassState', { id: row.id, state: newState });
    if (response.code === 200) {
      ElMessage.success(response.message);
      row.state = newState;
    } else {
      ElMessage.error(response.message);
    }
  } catch (error) {
    const response = await request.post('/loadGlass/up-patten-usage/updateGlassState', { id: row.id, state: newState });
    if (response.code === 200) {
      ElMessage.success(response.message);
      row.state = newState;
    } else {
      ElMessage.error(response.message);
    }
  } catch (error) {
    // 处理请求错误  
    ElMessage.error(t('basicData.glassnull'));
  }
};
// 上片机联机状态
// const wsUrl = `ws://${WebSocketHost}:${host}/api/loadGlass/api/talk/loadGlass`;
// const ws = new WebSocket(wsUrl);
// ws.onopen = () => {
//   console.log('WebSocket连接已打开');
// };
// // 监听WebSocket的错误事件
// ws.onerror = (error) => {
//   console.error('WebSocket发生错误:', error);
// };
// // 监听WebSocket的关闭事件
// ws.onclose = (event) => {
//   if (event.wasClean) {
//     console.log('WebSocket连接已正常关闭');
//   } else {
//     console.error('WebSocket连接异常关闭');
//   }
// };
// // 监听WebSocket的消息事件
// ws.onmessage = (event) => {
//   try {
//     const data = JSON.parse(event.data.replace('<END>', '')); // 解析消息为JSON
//     if (data && Array.isArray(data.InkageStatus) && data.InkageStatus.length > 0) {
// if(data.InkageStatus!=null){
//       const status = data.InkageStatus[0];
//       cuttingMachine.value = status;
//             upstatus.value = status === '1' ? t('basicData.machine') : t('basicData.machineaa');
//       cuttingMachineStatusColor.value = status === '1' ? 'green' : '#911005';
//       inKageWord.value = status === '1' ? 0 : 1;
// }
//     } else {
//       // 处理错误情况或无效数据
//       // console.error('接收到的数据无效', data);
//     }
//   } catch (error) {
//     // console.error('解析WebSocket消息时发生错误', error);
//   }
// };
const confirmCutting = async () => {
  try {
    const response = await request.post('/loadGlass/LoadGlass/updateMesInkageLoad',
      inKageWord.value
  );
    if (response.code == 200) {
      const status = response.data.status;
    ElMessage.error(t('basicData.glassnull'));
  }
};
const confirmCutting = async () => {
  try {
    const response = await request.post('/loadGlass/LoadGlass/updateMesInkageLoad',
        inKageWord.value
    );
    if (response.code == 200) {
      const status = response.data.status;
      upstatus.value = status === '1' ? t('basicData.machine') : t('basicData.machineaa');
      cuttingMachineStatusColor.value = status === '1' ? 'green' : '#911005';
      // 显示成功消息
      ElMessage.success(response.message);
    } else {
      ElMessage.error(response.message || '请求失败');
    }
  } catch (error) {
    // 处理错误
    console.error('请求时发生错误', error);
    ElMessage.error('请求时发生错误');
      cuttingMachineStatusColor.value = status === '1' ? 'green' : '#911005';
      ElMessage.success(response.message);
    } else {
      ElMessage.error(response.message || '请求失败');
    }
  } catch (error) {
    console.error('请求时发生错误', error);
    ElMessage.error('请求时发生错误');
  }  
};
</script>
@@ -730,14 +601,13 @@
    <el-button style="margin-top: 5px;margin-left: 20px;"  id="searchButton" type="warning" @click="handleBinda">{{ $t('basicData.stop') }}</el-button>
    <el-button style="margin-top: 5px;margin-left: 20px;" id="searchButton" type="info" @click="handlezhiban">{{ $t('searchOrder.dutyinformation') }}</el-button>
    <!-- <el-button style="margin-top: 5px;margin-left: 20px;"  id="searchButton" type="danger" @click="handleBindb">停止任务</el-button> -->
    <el-card style="flex: 1;margin-left: 10px;margin-top: 15px;" v-loading="loading">
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;">
    <el-table
    height="350"
     ref="table"
     :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}"
      :data="tableData"
        height="350"
        ref="table"
        :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}"
        :data="tableData"
    >
      <el-table-column prop="layoutSequence" :label="$t('basicData.layoutSequence')" width="100" align="center"/>
      <el-table-column prop="engineeringId" :label="$t('basicData.projectnumber')" width="200" align="center"/>
@@ -790,7 +660,6 @@
      </div>
    </template>
  </el-dialog>
<el-dialog v-model="dialoglea" top="15vh" width="70%" :title="$t('searchOrder.dutyinformation')">
    <el-table  ref="table" style="margin-top: 20px;height: 300px;"
        :data="tableDatax" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
@@ -860,7 +729,6 @@
        </el-table-column>
        </el-table>
    </div>
  <el-dialog v-model="add" top="23vh" width="45%" :title="$t('basicData.addglass')" >
    <div style="margin-left: -50px;margin-top: 10px;margin-bottom: 10px;">
            <el-form  size="mini" label-width="150px">
@@ -991,23 +859,23 @@
  <el-dialog v-model="dialogFormVisible" top="24vh" width="30%" :title="$t('basicData.project')" >
    <div style="margin-left: 50px;margin-bottom: 10px;">
      <el-form-item :label="$t('basicData.projectnumber')" :required="true">
        <el-select
           v-model="selectedProjectNo"
           filterable
           clearable
           :placeholder="$t('basicData.plselectproject')"
           style="width: 220px"
           @input="handleInputChange"
         >
      <el-option
         v-for="item in titleSelectJson['processType']"
         :key="item.id"
         :label="item.projectNo"
         :value="item.projectNo"
      />
    </el-select>
              </el-form-item>
          </div>
        <el-select
            v-model="selectedProjectNo"
            filterable
            clearable
            :placeholder="$t('basicData.plselectproject')"
            style="width: 220px"
            @input="handleInputChange"
        >
          <el-option
              v-for="item in titleSelectJson['processType']"
              :key="item.id"
              :label="item.projectNo"
              :value="item.projectNo"
          />
        </el-select>
      </el-form-item>
    </div>
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="handleup">
@@ -1018,9 +886,7 @@
    </template>
  </el-dialog>
</template>
<style scoped>
#dt { display:block; float:left;line-height: 20px;margin-left: 100px;}
#dta { display:block; float:left;line-height: 20px;margin-left: 80%;}
#dialog-footer{
@@ -1075,5 +941,4 @@
  margin-top: -45px;
  margin-left: 703px;
}
</style>