gaoluyang
2025-07-02 aaea16d23b27d42394f1aa1f309a52d3d937abc8
src/views/calculator/index.vue
@@ -68,7 +68,8 @@
                  style="margin-bottom: 15px"
                >
                  <el-row :gutter="16">
                    <el-col :span="6">                      <el-form-item label="煤种类型">
                    <el-col :span="6">
                      <el-form-item label="煤种类型">
                        <el-select
                          v-model="item.type"
                          placeholder="请选择"
@@ -79,7 +80,8 @@
                          <el-option label="未知煤" value="未知煤" />
                        </el-select>
                      </el-form-item>
                    </el-col>                    <el-col :span="6">
                    </el-col>
                    <el-col :span="6">
                      <el-form-item :label="'煤种' + (index + 1)">
                        <div class="input-wrapper">
                          <el-input
@@ -88,14 +90,20 @@
                            placeholder="请输入"
                            style="width: 100%"
                          />
                          <el-select
                            v-model="item.name"
                            v-show="item.type === '已有煤'"
                            placeholder="请选择"
                            style="width: 100%"
                          >
                            <el-option label="已有煤" value="已有煤" />
                            <el-option label="未知煤" value="未知煤" />
                            <el-option
                              v-for="ele in coalInfoList"
                              :key="ele.key"
                              :label="ele.value"
                              :value="ele.key"
                            >{{ ele.value }}
                          </el-option>
                          </el-select>
                        </div>
                      </el-form-item>
@@ -397,8 +405,9 @@
</template>
<script setup>
import { reactive, toRefs, nextTick } from "vue";
import { reactive, toRefs, nextTick, onMounted } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { getCoalInfoList } from "@/api/procureMent"; // 假设有一个API获取煤种信息
const data = reactive({
  formInline: {
@@ -450,7 +459,22 @@
    error: null,
  },
});
const coalInfoList = ref([]);
// onMounted
onMounted(async () => {
  let result = await getCoalInfoList();
  if (result.code === 200) {
    result.data.forEach((item) => {
      let obj = {
        value: item.coal,
        key: item.id,
      };
      coalInfoList.value.push(obj);
    });
  } else {
    ElMessage.error("获取煤种信息失败,请稍后重试");
  }
});
// 线性规划求解函数
const solveBlend = (coals, constraints) => {
  // 数据验证
@@ -594,6 +618,7 @@
};
const submitForm = () => {
  console.log(coalForms.value)
  // 数据验证
  let validCoals = coalForms.value.filter(
    (coal) => coal.name && coal.cv && coal.price
@@ -724,13 +749,14 @@
      sulfur: "",
      ash: "",
      moisture: "",
    });  }
    });
  }
};
// 处理煤种类型变化
const handleCoalTypeChange = (index) => {
  // 当煤种类型改变时,清空煤种名称,避免数据混乱
  coalForms.value[index].name = '';
  coalForms.value[index].name = "";
};
</script>