廖井涛
96 分钟以前 f7a2fcdda7f1120498c5c5f75c5a99955fc54b43
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/Compute.vue
@@ -1,5 +1,5 @@
<script setup>
import {onMounted, reactive, ref, watch} from "vue";
import {onMounted, reactive, ref, watch, inject} from "vue";
import {useI18n} from "vue-i18n";
import {Platform, Search, SuccessFilled} from "@element-plus/icons-vue";
import useUserInfoStore from "@/stores/userInfo";
@@ -17,12 +17,15 @@
const props = defineProps({
  projectNo : String,
  project: null,
  state:null,
  data: {
    type: Array,
    default: () => []
  }
});
// 注入 projectNo
const injectedProjectNo = inject('projectNo', null);
const selectOptions = [
  {
@@ -44,7 +47,7 @@
const optionVal = ref(50)
// 定义装载率
const percentage1 = ref(80)
const percentage1 = ref(50)
const percentage2 = ref(50)
// 定义其他表单数据
@@ -59,10 +62,55 @@
// 定义响应式数据,用于绑定工程号输入框的值
let inputValue=ref(null)
if(props.project!==undefined){
  inputValue= ref(props.project.projectNumber);
  quantity.value=props.project.quantity
  inputValue = ref(props.project.projectNumber);
  quantity.value = props.project.quantity
} else if(props.projectNo) {
  inputValue.value = props.projectNo;
} else if(injectedProjectNo) {
  // 从 provide/inject 获取 projectNo
  inputValue.value = injectedProjectNo.value || injectedProjectNo;
}else {
  // 从 localStorage 获取
  const storedProjectNo = localStorage.getItem('currentProjectNo');
  if (storedProjectNo) {
    inputValue.value = storedProjectNo;
  }
}
// 添加 watch 监听注入的 projectNo
watch(() => injectedProjectNo, (newVal) => {
  if(newVal && !inputValue.value) {
    inputValue.value = newVal.value || newVal;
  }
}, { immediate: true });
const fetchSettings = async (username) => {
  try {
    const response = await request.post(`/glassOptimize/selectOptimizeParms/${username}`);
    if (response.code == 200) {
      if (!response.data) {
        console.error('响应数据为空');
        return;
      }
      const parsedData = JSON.parse(response.data);
      if (parsedData.tempering) {
        furnaceLength.value = parsedData.tempering.furnaceLength;
        furnaceWidth.value = parsedData.tempering.furnaceWidth;
        spacingWidth.value=parsedData.tempering.xAxisInterval;
        spacingLong.value=parsedData.tempering.yAxisInterval;
        heatingTime.value=parsedData.tempering.temperingTime;
      }
    } else {
      console.error('请求失败,状态码:', response.code);
    }
  } catch (error) {
    console.error('请求发生错误:', error);
  }
};
fetchSettings(username);
const gridOptions = reactive({
  height: '100%',
@@ -117,29 +165,20 @@
  await firstLoading()
})
const firstLoading = async() => {
    request.post(`/glassOptimize/getConfiguration/钢化`).then((res) => {
      if (res.code == "200") {
        const rawData = res.data.data;
        if (Array.isArray(rawData) && rawData.length > 0) {
          const formattedData = rawData.map(item => {
            const formattedItem = {};
            for (const key in item) {
              if (typeof item[key] === 'string') {
                //去除字符串属性值开头和结尾的双引号
                formattedItem[key] = item[key].replace(/^\"|\"$/g, '');
              } else {
                formattedItem[key] = item[key];
              }
            }
            return formattedItem;
          });
          furnaceWidth.value=formattedData[0].load_width
          furnaceLength.value=formattedData[0].load_length
          spacingLong.value=formattedData[0].x_space
          spacingWidth.value=formattedData[0].y_space
onMounted(async () => {
  if (props.project && props.project.projectNumber) {
    await fetchProjectData(props.project.projectNumber);
  }
});
        }
const firstLoading = async() => {
    request.post(`/glassOptimize/selectOptimizeParms/${username}`).then((res) => {
      if (res.code == "200") {
        const parsedData = JSON.parse(res.data);
          furnaceWidth.value=parsedData.tempering.furnaceWidth
          furnaceLength.value=parsedData.tempering.furnaceLength
          spacingLong.value=parsedData.tempering.xAxisInterval
          spacingWidth.value=parsedData.tempering.yAxisInterval
      } else {
        ElMessage.warning(res.msg)
      }
@@ -152,7 +191,6 @@
  if (newValue) {
    // 处理数据并更新表格
    const processData = newValue.data[0];
    console.log('Processed Data:', processData);
    const processedData = [
      {
        id: "1",
@@ -164,7 +202,6 @@
      }
    ];
    gridOptions.data = processedData;
    console.log(gridOptions.data)
  } else {
    console.error("数据格式不正确或为空");
    gridOptions.data = [];
@@ -172,42 +209,144 @@
})
// let emit = defineEmits(['fetch-data']);
let emit = defineEmits(['fetch-data', 'sendData'])
const inputValues = {
  project_no:inputValue,
    glass_thickness:"",
    glass_type:"",
    chaos_pct: optionVal.value*0.01,//混排等级
    cage_free:percentage2.value*0.01,//理片龙空闲度
    tempering_time:heatingTime.value,//钢化加热时间
    heat_mode: 0,//模式选择
    max_load_pct: percentage1.value*0.01,//最大装载率
    max_area: 0,//最大面积
    max_qty:0,//最大片数
    load_width:furnaceWidth,
    load_length: furnaceLength,
  x_space: spacingWidth,
  y_space: spacingLong,
const emit = defineEmits(['fetch-data', 'sendData', 'simulate-click']);
const inputValues =  reactive({
  project_no:inputValue.value,
  glass_thickness:"",
  glass_type:"",
  chaos_pct: optionVal.value*0.01,//混排等级
  cage_free:percentage2.value*0.01,//理片龙空闲度
  tempering_time:heatingTime.value,//钢化加热时间
  heat_mode: 0,//模式选择
  max_load_pct: percentage1.value*0.01,//最大装载率
  max_area: 0,//最大面积
  max_qty:0,//最大片数
  load_width:null,
  load_length: null,
  x_space: null,
  y_space: null,
  load_rate: null,
  furnaces_qty:"",
  rotate_mode:0,
  polys_allow_rotate: 0,
  process_cards:[]
});
const fetchProjectData = async (projectNumber) => {
  try {
    const res = await request.post(`/glassOptimize/getProjectByProjectNo/${projectNumber}`);
    if (Number(res.code) === 200 && res.data && res.data.data && res.data.data.length > 0) {
      const projectData = res.data.data[0];
      // 更新 inputValues
      inputValues.glass_thickness = projectData.glass_thickness || '';
      inputValues.glass_type = projectData.glass_type || '';
      console.log('更新后的 inputValues:', inputValues);
    } else {
      ElMessage.warning('未找到项目信息或数据格式不正确');
    }
  } catch (error) {
    console.error('请求失败:', error);
    ElMessage.error('获取项目信息失败');
  }
};
const handleSearchClick = () => {
  const projectNumber = inputValue.value;
  if (!projectNumber) {
    ElMessage.warning('请输入工程号');
    return;
  }
  // 通知父组件更新(可选)
  emit('fetch-data', projectNumber);
  // 子组件自己调用接口更新数据
  fetchProjectData(projectNumber);
};
const handleSimulationClick = async () => {
  try {
    const projectNumber = inputValue.value;
    if (!projectNumber) {
      ElMessage.warning('请输入工程号');
      return;
    }
    const res = await request.post(`/glassOptimize/getProjectState/${projectNumber}`);
    if (Number(res.code) === 200) {
      const projectData = res.data.data;
      // 检查 tempering_state 状态
      if (projectData.tempering_state === 1) {
        // 如果已完成模拟计算,提示用户并阻止继续执行
        ElMessage.warning('已完成模拟计算,不允许重复计算');
        return;
      }
    } else {
      ElMessage.warning(res.msg);
      return;
    }
  } catch (error) {
    ElMessage.error('检查工程状态失败,请稍后重试');
    console.error('检查工程状态失败:', error);
    return;
  }
  inputValues.project_no = inputValue.value;
  inputValues.chaos_pct = optionVal.value * 0.01; // 混排等级
  inputValues.cage_free = percentage2.value * 0.01; // 理片龙空闲度
  inputValues.heat_mode = 0; // 模式选择(默认值)
  inputValues.max_load_pct = percentage1.value * 0.01; // 最大装载率
  inputValues.max_area = 0; // 最大面积(默认值)
  inputValues.max_qty = 0; // 最大片数(默认值)
  inputValues.load_width = furnaceWidth.value;
  inputValues.load_length = furnaceLength.value;
  inputValues.x_space = spacingWidth.value;
  inputValues.y_space = spacingLong.value;
  inputValues.polys_allow_rotate = parseInt(rotateMode.value.value);
  inputValues.tempering_time = heatingTime.value || inputValues.tempering_time || 0;
  const sendData = {
    project_no: inputValues.project_no,
    glass_thickness: inputValues.glass_thickness,
    glass_type: inputValues.glass_type,
    chaos_pct: inputValues.chaos_pct, // 混排等级
    cage_free: inputValues.cage_free, // 理片龙空闲度
    tempering_time: inputValues.tempering_time,
    heat_mode: inputValues.heat_mode, // 模式选择
    max_load_pct: inputValues.max_load_pct, // 最大装载率
    max_area: inputValues.max_area, // 最大面积
    max_qty: inputValues.max_qty, // 最大片数
    load_width: inputValues.load_width,
    load_length: inputValues.load_length,
    x_space: inputValues.x_space,
    y_space: inputValues.y_space,
    load_rate: inputValues.load_rate, // 装载率(可能为空)
    furnaces_qty: inputValues.furnaces_qty, // 炉子数量(可能为空)
    rotate_mode: inputValues.rotate_mode, // 钢化旋转模式(可能为空)
    polys_allow_rotate: inputValues.polys_allow_rotate,
    process_cards: inputValues.process_cards || [] // 流程卡列表(默认空数组)
  };
  // 发送所有数据到父组件
  emit('sendData', sendData);
      inputValues.project_no = inputValue.value;
  emit('sendData', {
    ...inputValues
  });
const handleSearchClick = () => {
  // 通过 $emit 触发自定义事件,将工程号传递给父组件,由父组件去调用接口获取数据
  emit('fetch-data', inputValue.value);
};
const handleSimulationClick = () => {
  })
  // 触发父组件的 simulate-click 事件
  emit('simulate-click');
};
@@ -215,25 +354,48 @@
const handleSave = () => {
  if (props.data) {
  console.log('当前保存的数据:', props.data);
  if(props.state==3){
    let projectData = ref({
      projectdetail: props.data,
      userName : username,
      inputValues:inputValues
    })
    request.post(`/glassOptimize/simulationSave`, projectData.value).then((res) => {
      if (res.code == 200 && res.data === true) {
        ElMessage.success(t('basicData.msg.saveSuccess'))
      } else {
        ElMessage.warning(res.msg)
      }
    })
      let projectData = ref({
        inputValues:inputValues,
        userName : username,
        state:props.state
      })
      request.post(`/glassOptimize/simulationSave`, projectData.value).then((res) => {
        if (res.code == 200 && res.data === true) {
          ElMessage.success(t('basicData.msg.saveSuccess'))
        } else {
          ElMessage.warning(res.msg)
        }
      })
  }else{
    if (props.data) {
      let projectData = ref({
        projectdetail: props.data.data[0].glass_details,
        ratioResult: props.data.data[0].ratioResult,
        rackinfos: props.data.data[0].rackinfos,
        resultSum: props.data.data[0].resultSum,
        guidance: props.data.data[0].guidance,
        userName : username,
        inputValues:inputValues,
        state:props.state
      })
      request.post(`/glassOptimize/simulationSave`, projectData.value).then((res) => {
        if (res.code == 200 && res.data === true) {
          ElMessage.success(t('basicData.msg.saveSuccess'))
        } else {
          ElMessage.warning(res.msg)
        }
      })
    }
  }
}
@@ -327,31 +489,6 @@
    </div>
  </div>
<!--  <div class="demo-progress" style="margin-top: -10px">
    <div style="display: flex; align-items: center">
      <span>理片笼空闲度</span>
      &lt;!&ndash; 进度条设置 &ndash;&gt;
      <el-slider
          style="max-width: 400px; flex: 1; margin-left: 10px"
          v-model="percentage2"
          :min="0"
          :max="100"
          :step="1"/>
      <span style="margin-left: 20px ; width: 35px;">{{ percentage2 }}%</span>
      <span style="float: right ; margin-left: 150px;">
              加热时间(秒)<el-select style="width: 50px;height: 30px" v-model="rotateMode">
                            <el-option
                                v-for="item in selectOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
              长轴间隔 <vxe-input size="small" class="input" clearable v-model="spacingLong"></vxe-input>
              炉长(mm) <vxe-input size="small" class="input" clearable v-model="furnaceLength"></vxe-input>
      </span>
    </div>
  </div>-->
</div>
<div style="height: 50%">
  <vxe-grid