<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px" class="search-form">
      <div class="search-form-left">
        <el-form-item label="工程名称" prop="engName"><el-input v-model="queryParams.engName" placeholder="请输入" clearable @keyup.enter="handleQuery" /></el-form-item>
        <el-form-item label="水库代码" prop="resCode"><el-input v-model="queryParams.resCode" placeholder="请输入" clearable /></el-form-item>
        <el-form-item>
          &nbsp;&nbsp;
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button><el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </div>
      <div class="search-form-right">
        <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
<!--        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate(null)">修改</el-button>-->
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete(null)">删除</el-button>
<!--        <el-button type="warning" plain icon="Download" @click="handleExport">导出</el-button>-->
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns" />
      </div>
    </el-form>
    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelect">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工程名称" prop="engName" align="center" :show-overflow-tooltip="true" v-if="columns.engName.visible" />
      <el-table-column label="水库代码" prop="resCode" align="center" v-if="columns.resCode.visible" />
      <el-table-column label="水库位置" prop="resLoc" align="center" v-if="columns.resLoc.visible" />
      <el-table-column label="工程等级" align="center" v-if="columns.engGrad.visible"><template #default="scope"><dict-tag :options="slaj_eng_grad_res" :value="scope.row.engGrad" /></template></el-table-column>
      <el-table-column label="工程规模" align="center" v-if="columns.engScal.visible"><template #default="scope"><dict-tag :options="slaj_eng_scal_res" :value="scope.row.engScal" /></template></el-table-column>
      <el-table-column label="坝型(材质)" align="center" v-if="columns.damTypeMat.visible"><template #default="scope"><dict-tag :options="slaj_dam_type_mat" :value="scope.row.damTypeMat" /></template></el-table-column>
      <el-table-column label="坝型(结构)" align="center" v-if="columns.damTypeStr.visible"><template #default="scope"><dict-tag :options="slaj_dam_type_str" :value="scope.row.damTypeStr" /></template></el-table-column>
      <el-table-column label="坝高(m)" prop="damSizeHig" align="center" v-if="columns.damSizeHig.visible" />
      <el-table-column label="坝长(m)" prop="damSizeLen" align="center" v-if="columns.damSizeLen.visible" />
      <el-table-column label="坝顶高程(m)" prop="damCreElv" align="center" v-if="columns.damCreElv.visible" />
      <el-table-column label="设计防洪标准(年)" prop="desFlStand" align="center" v-if="columns.desFlStand.visible" />
      <el-table-column label="汛限水位" prop="flLowLimLev" align="center" v-if="columns.flLowLimLev.visible" />
      <el-table-column label="汛限开始时间" prop="flLowLimLevStart" align="center" v-if="columns.flLowLimLevStart.visible" />
      <el-table-column label="汛限结束时间" prop="flLowLimLevEnd" align="center" v-if="columns.flLowLimLevEnd.visible" />
      <el-table-column label="设计洪水位" prop="desFlStag" align="center" v-if="columns.desFlStag.visible" />
      <el-table-column label="主要来水类型" align="center" v-if="columns.mainFlType.visible"><template #default="scope"><dict-tag :options="slaj_main_fl_type" :value="scope.row.mainFlType" /></template></el-table-column>
      <el-table-column label="死水位(m)" prop="deadLev" align="center" v-if="columns.deadLev.visible" />
      <el-table-column label="总库容(万m3)" prop="totCap" align="center" v-if="columns.totCap.visible" />
      <el-table-column label="死库容(万m3)" prop="deadCap" align="center" v-if="columns.deadCap.visible" />
      <el-table-column label="防洪库容(万m3)" prop="flcoCap" align="center" v-if="columns.flcoCap.visible" />
      <el-table-column label="备注" prop="note" align="center" :show-overflow-tooltip="true" v-if="columns.note.visible" />
      <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
        <template #default="scope"><el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button><el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button></template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    <el-dialog :title="title" v-model="open" width="750px" append-to-body>
      <el-form ref="formRef" :model="form" :rules="rules" label-width="140px">
        <el-divider content-position="left">基本信息</el-divider>
        <el-row><el-col :span="12"><el-form-item label="工程名称" prop="engName"><el-input v-model="form.engName" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="水库代码" prop="resCode"><el-input v-model="form.resCode" placeholder="请输入" /></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="水库位置" prop="resLoc"><el-input v-model="form.resLoc" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="重要程度" prop="impoGrad"><el-select v-model="form.impoGrad" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_impo_grad" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="批复投资(万元)" prop="apprBudg"><el-input v-model="form.apprBudg" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="工程状态" prop="engStat"><el-select v-model="form.engStat" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_eng_stat" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="启停状态" prop="stat"><el-select v-model="form.stat" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_stat" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="是否除险加固" prop="ifReinForce"><el-select v-model="form.ifReinForce" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_if_rein_force" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col></el-row>
        <el-divider content-position="left">水库参数</el-divider>
        <el-row><el-col :span="12"><el-form-item label="工程等级" prop="engGrad"><el-select v-model="form.engGrad" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_eng_grad_res" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="工程规模" prop="engScal"><el-select v-model="form.engScal" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_eng_scal_res" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="坝型(材质)" prop="damTypeMat"><el-select v-model="form.damTypeMat" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_dam_type_mat" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="坝型(结构)" prop="damTypeStr"><el-select v-model="form.damTypeStr" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_dam_type_str" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="坝高(m)" prop="damSizeHig"><el-input v-model="form.damSizeHig" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="坝长(m)" prop="damSizeLen"><el-input v-model="form.damSizeLen" placeholder="请输入" /></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="坝顶高程(m)" prop="damCreElv"><el-input v-model="form.damCreElv" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="设计防洪标准(年)" prop="desFlStand"><el-input v-model="form.desFlStand" placeholder="请输入" /></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="汛限水位" prop="flLowLimLev"><el-input v-model="form.flLowLimLev" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="主要来水类型" prop="mainFlType"><el-select v-model="form.mainFlType" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_main_fl_type" :key="d.value" :label="d.label" :value="d.value" /></el-select></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="设计洪水位" prop="desFlStag"><el-input v-model="form.desFlStag" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="死水位(m)" prop="deadLev"><el-input v-model="form.deadLev" placeholder="请输入" /></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="总库容(万m3)" prop="totCap"><el-input v-model="form.totCap" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="死库容(万m3)" prop="deadCap"><el-input v-model="form.deadCap" placeholder="请输入" /></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="防洪库容(万m3)" prop="flcoCap"><el-input v-model="form.flcoCap" placeholder="请输入" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="汛限开始时间" prop="flLowLimLevStart"><el-input v-model="form.flLowLimLevStart" placeholder="请输入" /></el-form-item></el-col></el-row>
        <el-row><el-col :span="12"><el-form-item label="汛限结束时间" prop="flLowLimLevEnd"><el-input v-model="form.flLowLimLevEnd" placeholder="请输入" /></el-form-item></el-col></el-row>
        <el-divider content-position="left">时间信息</el-divider>
        <el-row>
          <el-col :span="12"><el-form-item label="开工日期" prop="startDate"><el-date-picker v-model="form.startDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择" style="width:100%" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="完工日期" prop="compDate"><el-date-picker v-model="form.compDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择" style="width:100%" /></el-form-item></el-col>
        </el-row>
        <el-form-item label="备注" prop="note"><el-input v-model="form.note" type="textarea" :rows="2" placeholder="请输入" /></el-form-item>
      </el-form>
      <template #footer><el-button type="primary" @click="submit">确 定</el-button><el-button @click="open=false">取 消</el-button></template>
    </el-dialog>
  </div>
</template>
<script setup>
import { listAttEngRes, getAttEngRes, addAttEngRes, updateAttEngRes, delAttEngRes } from "@/api/slaj/eng"
const{proxy}=getCurrentInstance()
const { slaj_eng_grad_res, slaj_eng_scal_res, slaj_dam_type_mat, slaj_dam_type_str, slaj_main_fl_type, slaj_impo_grad, slaj_eng_stat, slaj_stat, slaj_if_rein_force } = proxy.useDict("slaj_eng_grad_res","slaj_eng_scal_res","slaj_dam_type_mat","slaj_dam_type_str","slaj_main_fl_type","slaj_impo_grad","slaj_eng_stat","slaj_stat","slaj_if_rein_force")
const dataList=ref([]),open=ref(false),loading=ref(true),showSearch=ref(true),ids=ref([]),single=ref(true),multiple=ref(true),total=ref(0),title=ref("")
const columns=ref({engName:{label:'工程名称',visible:true},resCode:{label:'水库代码',visible:true},resLoc:{label:'水库位置',visible:true},engGrad:{label:'工程等级',visible:true},engScal:{label:'工程规模',visible:true},damTypeMat:{label:'坝型(材质)',visible:true},damTypeStr:{label:'坝型(结构)',visible:true},damSizeHig:{label:'坝高(m)',visible:true},damSizeLen:{label:'坝长(m)',visible:true},damCreElv:{label:'坝顶高程(m)',visible:true},desFlStand:{label:'设计防洪标准(年)',visible:true},flLowLimLev:{label:'汛限水位',visible:true},flLowLimLevStart:{label:'汛限开始时间',visible:true},flLowLimLevEnd:{label:'汛限结束时间',visible:true},desFlStag:{label:'设计洪水位',visible:true},mainFlType:{label:'主要来水类型',visible:true},deadLev:{label:'死水位(m)',visible:true},totCap:{label:'总库容(万m3)',visible:true},deadCap:{label:'死库容(万m3)',visible:true},flcoCap:{label:'防洪库容(万m3)',visible:true},engStat:{label:'工程状态',visible:true},note:{label:'备注',visible:false}})
const data=reactive({form:{},queryParams:{pageNum:1,pageSize:10,engName:null,resCode:null},rules:{}})
const{form,queryParams,rules}=toRefs(data)
function getList(){loading.value=true;listAttEngRes(queryParams.value).then(r=>{dataList.value=r.rows;total.value=r.total;loading.value=false})}
function handleQuery(){queryParams.value.pageNum=1;getList()}
function resetQuery(){proxy.resetForm("queryRef");handleQuery()}
function handleSelect(s){ids.value=s.map(i=>i.guid);single.value=s.length!==1;multiple.value=!s.length}
const RES_FIELDS=['engName','resCode','resLoc','impoGrad','apprBudg','engStat','stat','ifReinForce','engGrad','engScal','damTypeMat','damTypeStr','damSizeHig','damSizeLen','damCreElv','desFlStand','flLowLimLev','mainFlType','desFlStag','deadLev','totCap','deadCap','flcoCap','flLowLimLevStart','flLowLimLevEnd','startDate','compDate','note']
function reset(){const f={};RES_FIELDS.forEach(k=>f[k]=null);f.engGuid=null;f.guid=null;form.value=f;proxy.resetForm("formRef")}
function handleAdd(){reset();open.value=true;title.value="添加水库工程"}
function handleUpdate(row){reset();const g=row?row.guid:ids.value[0];getAttEngRes(g).then(r=>{form.value=r.data;open.value=true;title.value="修改水库工程"})}
function submit(){proxy.$refs.formRef.validate(v=>{if(v){const fn=form.value.guid?updateAttEngRes:addAttEngRes;fn(form.value).then(()=>{proxy.$modal.msgSuccess("成功");open.value=false;getList()})}})}
function handleDelete(row){const g=row?row.guid:ids.value.join(",");proxy.$modal.confirm('确认删除？').then(()=>delAttEngRes(g)).then(()=>{getList();proxy.$modal.msgSuccess("删除成功")})}
function handleExport(){proxy.download(`/sins/attengres/export`,{...queryParams.value},`水库工程_${Date.now()}.xlsx`)}
getList()
</script>
<style scoped>
.search-form { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.search-form-left { display: flex; align-items: center; flex-wrap: wrap; flex: 1; }
.search-form-right { display: flex; align-items: center; gap: 6px; white-space: nowrap; flex-shrink: 0; }
</style>
