<template>
    <div class="XFpdding">
             <div class="numberinput lefttext">
         <el-form>
           <el-form-item label="优化算法：" :label-width="formLabelWidth1">
             <el-select v-model="youhua.algorithm" :suffix-icon="CaretBottom" placeholder="请选择">
               <el-option v-for="item in yslist" :key="item.value" :label="item.label" :value="item.value">
               </el-option>
             </el-select>
           </el-form-item>
           <el-form-item label="最大外迭代步数:" :label-width="formLabelWidth1">
             <el-input v-model="youhua.majoriterationslimit" :step="100" :min="0" :max="1000" controls-position="right" />
           </el-form-item>
           <el-form-item label="输出精度等级:" :label-width="formLabelWidth1">
             <el-input v-model="youhua.majorprintlevel" :step="100" :min="0" :max="1000" controls-position="right" />
           </el-form-item>
           <el-form-item label="线性约束容差:" :label-width="formLabelWidth1">
             <el-input v-model="youhua.linearfeasibilitytolerance" :step="100" :min="0" :max="1000" controls-position="right" />
           </el-form-item>
           <el-form-item label="非线性约束容差:" :label-width="formLabelWidth1">
             <el-input v-model="youhua.nonlinearfeasibilitytolerance" :step="100" :min="0" :max="1000" controls-position="right" />
           </el-form-item>
           <el-form-item label="最优性度量容差:" :label-width="formLabelWidth1">
             <el-input v-model="youhua.optimalitytolerance" :step="100" :min="0" :max="1000" controls-position="right" />
           </el-form-item>
           <el-form-item label="梯度验证级别:" :label-width="formLabelWidth1">
             <el-select v-model="youhua.verifylevel" :suffix-icon="CaretBottom" placeholder="请选择">
               <el-option v-for="item in tdlist" :key="item.value" :label="item.label" :value="item.value">
               </el-option>
             </el-select>
           </el-form-item>
         </el-form>
       </div>
           </div>
</template>
<script  setup>
import { ref, onMounted, reactive, provide, nextTick } from "vue";
import { ElMessage, ElButton, ElDialog, ElSelect } from 'element-plus'
import { Edit, CaretBottom, Checked } from '@element-plus/icons-vue'
import { request } from "@/utils/request";
let formLabelWidth3=ref(100)
let formLabelWidth1=ref(170)
let formLabelWidth200=ref(200)
let youhua = ref({
algorithm: 'SQP',
majoriterationslimit: 100,
majorprintlevel: 10,
linearfeasibilitytolerance: 1e-6,
nonlinearfeasibilitytolerance: 1e-6,
optimalitytolerance: 1e-4,
verifylevel: '-1'
})
let pid = ref();
let wid = ref();
let grid = ref();
let cstnum=ref('');
let yslist = ref([
{ label: 'SQP', value: 'SQP' },
])

let tdlist= ref([
{ label: '不验证', value: '-1' },
{ label: '简单验证', value: '0' },
{ label: '目标详细验证', value: '1' },
{ label: '约束详细验证', value: '2' },
{ label: '目标+约束详细验证', value: '3' },

])
const getToptimize = (id,nowid) => {
  pid.value = id;
  wid.value = nowid;
  const params = {
    transCode: 'MDO0033',
    pid: pid.value,
    wid: wid.value,
  }
  request(params).then((res) => {
    if (res.hasOwnProperty('grid')) {
      // grid.value = res.grid;
      // youhua.value.algorithm = res.algorithm;
      // youhua.value.majoriterationslimit = res.majoriterationslimit;
      // youhua.value.majorprintlevel = res.majorprintlevel;
      // youhua.value.linearfeasibilitytolerance = res.linearfeasibilitytolerance;
      // youhua.value.nonlinearfeasibilitytolerance = res.nonlinearfeasibilitytolerance;
      // youhua.value.optimalitytolerance = res.optimalitytolerance;
      // youhua.value.verifylevel = res.verifylevel;

      getToptimizeAssign(res);

    } else {
      
    }
  })
  .catch((err) => {
    ElMessage.error(err.returnMsg)
  })
}

const getToptimizeAssign = (data) => {
  // pid.value = data.pid;
  grid.value = data.grid;
  youhua.value.algorithm = data.algorithm;
  youhua.value.majoriterationslimit = data.majoriterationslimit;
  youhua.value.majorprintlevel = data.majorprintlevel;
  youhua.value.linearfeasibilitytolerance = data.linearfeasibilitytolerance;
  youhua.value.nonlinearfeasibilitytolerance = data.nonlinearfeasibilitytolerance;
  youhua.value.optimalitytolerance = data.optimalitytolerance;
  youhua.value.verifylevel = data.verifylevel;
}

//梯度优化器，添加保存
const getaddTsave = (id,nowid) => {
  if(nowid){
    wid.value = nowid
  }
  pid.value = id;
  const params = {
    transCode: 'MDO0034',
    pid: pid.value,
    wid: wid.value,
    grid: grid.value,
    algorithm: youhua.value.algorithm,
    majoriterationslimit: youhua.value.majoriterationslimit,
    majorprintlevel: youhua.value.majorprintlevel,
    linearfeasibilitytolerance: youhua.value.linearfeasibilitytolerance,
    nonlinearfeasibilitytolerance: youhua.value.nonlinearfeasibilitytolerance,
    optimalitytolerance: youhua.value.optimalitytolerance,
    verifylevel: youhua.value.verifylevel,
    checked:1
  }
  request(params).then((res) => {
    pid.value = res.pid;
    ElMessage({
      message: '保存成功',
      type: 'success'
    })
  })
  .catch((err) => {
    ElMessage.error('保存失败')
  })
}
defineExpose({
  getToptimize,
  getToptimizeAssign,
  getaddTsave
});
</script>


