<template>
  <el-card style="margin-top:12px" class="simulation-add-add-step2">
    <template #header>
      <div style="position: relative;width:100%;">
        模型列表
        <el-button style="position: absolute;right:10px;top:-4px;" type="primary" @click="doRefresh">刷新</el-button>
      </div>
    </template>
    <el-table v-loading="loading" :data="info.data" stripe @row-click="doRowClick">
      <el-table-column align="center" width="55" label="选择">
        <template #default="scope">
          <el-radio v-model="modelSelection" :label="scope.row.id + ''"
            @change="handleChange(scope.row)">&nbsp;</el-radio>
        </template>
      </el-table-column>
      <el-table-column label="模型名称" align="left" prop="model_name" />
      <el-table-column label="模型类型" align="left" prop="modelType" />
      <el-table-column label="模型说明" align="left" prop="model_desc" width="120" v-if="1 == 2" />

      <el-table-column label="版本" align="left" prop="connection_version" v-if="1 == 2" />
      <el-table-column label="互联名称" align="left" prop="connection_name" />
      <el-table-column label="互联说明" align="left" prop="connection_desc" />
      <el-table-column label="互联创建时间" width="180" align="left" prop="create_time" />

    </el-table>
    <pagination v-if="total > 0" v-model:total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="handleQuery" />
  </el-card>
</template>

<script setup>
import connApi from '@/api/connection'
const loading = ref(false);
const modelSelection = ref("")//单选id
const info = reactive({
  data: []
})
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  connection_name: ''
});
const total = ref(100); // 数据总数

const handleChange = (row) => {
  modelSelection.value = row.id + "";
}
const doRowClick = (row) => {
  modelSelection.value = row.id + "";
}
//刷新
function doRefresh(){
  handleQuery();
}
/** 查询 */
function handleQuery(a) {
  if (a) {
    queryParams.pageSize = a.limit;
    queryParams.pageNum = a.page;
  }
  //ElMessage.success("查询成功");
  loading.value = true;
  connApi.list(queryParams).then(d => {
    loading.value = false;
    info.data = (d.data?.data?.connection_list || []).map(it => {
      it.id = it.connection_id;
      it.modelType = it.modl_net_type;
      return it;
    });
    total.value = d.data?.data?.total || 0;
  });

}
const checkForm = () => {
  if (modelSelection.value) {
    let tmps = info.data.filter(d => d.id == modelSelection.value);
    return tmps.length > 0 ? tmps[0] : null;
  }
  return null;
};

const returnData=d=>{
  modelSelection.value=""+d.id;
}

onMounted(() => {
  handleQuery();
});

defineExpose({
  checkForm,
  returnData
})

</script>
<style lang='scss'></style>