<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="irrCode"><el-input v-model="queryParams.irrCode" 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="irrCode" align="center" v-if="columns.irrCode.visible" />
      <el-table-column label="灌区位置" prop="irrLoc" align="center" v-if="columns.irrLoc.visible" />
      <el-table-column label="工程规模" align="center" v-if="columns.engScal.visible"><template #default="scope"><dict-tag :options="slaj_eng_scal_irr" :value="scope.row.engScal" /></template></el-table-column>
      <el-table-column label="总灌溉面积(亩)" prop="totIrrArea" align="center" v-if="columns.totIrrArea.visible" />
      <el-table-column label="有效灌溉面积(亩)" prop="effIrrArea" align="center" v-if="columns.effIrrArea.visible" />
      <el-table-column label="设计灌溉面积(亩)" prop="desIrrArea" align="center" v-if="columns.desIrrArea.visible" />
      <el-table-column label="渠道最高级别" align="center" v-if="columns.chanHignLeve.visible"><template #default="scope"><dict-tag :options="slaj_chan_lev" :value="scope.row.chanHignLeve" /></template></el-table-column>
      <el-table-column label="渠道数量(条)" prop="chanNum" align="center" v-if="columns.chanNum.visible" />
      <el-table-column label="渠道总长度(m)" prop="chanLenTot" align="center" v-if="columns.chanLenTot.visible" />
      <el-table-column label="渠道设计流量(m3/s)" prop="chanDesFlow" align="center" v-if="columns.chanDesFlow.visible" />
      <el-table-column label="水闸数量(座)" prop="chsyGateNum" align="center" v-if="columns.chsyGateNum.visible" />
      <el-table-column label="渡槽数量(座)" prop="chsyAquNum" align="center" v-if="columns.chsyAquNum.visible" />
      <el-table-column label="跌水数量(座)" prop="chsyDropNum" align="center" v-if="columns.chsyDropNum.visible" />
      <el-table-column label="倒虹吸数量(座)" prop="chsyInvSiphNum" align="center" v-if="columns.chsyInvSiphNum.visible" />
      <el-table-column label="隧洞数量(座)" prop="chsyTunNum" align="center" v-if="columns.chsyTunNum.visible" />
      <el-table-column label="涵洞数量(座)" prop="chsyCulNum" align="center" v-if="columns.chsyCulNum.visible" />
      <el-table-column label="农桥数量(座)" prop="chsyFarmBriNum" align="center" v-if="columns.chsyFarmBriNum.visible" />
      <el-table-column label="量水设施数量(座)" prop="chsyMeaNum" align="center" v-if="columns.chsyMeaNum.visible" />
      <el-table-column label="渠系排水泵站数量(座)" prop="chsyDitPustStNum" align="center" v-if="columns.chsyDitPustStNum.visible" />
      <el-table-column label="工程状态" align="center" v-if="columns.engStat.visible"><template #default="scope"><dict-tag :options="slaj_eng_stat" :value="scope.row.engStat" /></template></el-table-column>
      <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="irrCode"><el-input v-model="form.irrCode" placeholder="请输入" /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="灌区位置" prop="irrLoc"><el-input v-model="form.irrLoc" placeholder="请输入" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="中心经度(°)" prop="cenLong"><el-input v-model="form.cenLong" placeholder="请输入" /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="中心纬度(°)" prop="cenLat"><el-input v-model="form.cenLat" 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="engScal"><el-select v-model="form.engScal" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_eng_scal_irr" :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="totIrrArea"><el-input v-model="form.totIrrArea" placeholder="请输入" /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="有效灌溉面积(亩)" prop="effIrrArea"><el-input v-model="form.effIrrArea" placeholder="请输入" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="设计灌溉面积(亩)" prop="desIrrArea"><el-input v-model="form.desIrrArea" 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="chanHignLeve"><el-select v-model="form.chanHignLeve" placeholder="请选择" style="width:100%"><el-option v-for="d in slaj_chan_lev" :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="chanNum"><el-input v-model="form.chanNum" placeholder="请输入" /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="渠道总长度(m)" prop="chanLenTot"><el-input v-model="form.chanLenTot" placeholder="请输入" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="渠道设计流量(m3/s)" prop="chanDesFlow"><el-input v-model="form.chanDesFlow" 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="chsyGateNum"><el-input v-model="form.chsyGateNum" placeholder="请输入" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="渡槽数量(座)" prop="chsyAquNum"><el-input v-model="form.chsyAquNum" placeholder="请输入" /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="跌水数量(座)" prop="chsyDropNum"><el-input v-model="form.chsyDropNum" placeholder="请输入" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="倒虹吸数量(座)" prop="chsyInvSiphNum"><el-input v-model="form.chsyInvSiphNum" placeholder="请输入" /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="隧洞数量(座)" prop="chsyTunNum"><el-input v-model="form.chsyTunNum" placeholder="请输入" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="涵洞数量(座)" prop="chsyCulNum"><el-input v-model="form.chsyCulNum" placeholder="请输入" /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="农桥数量(座)" prop="chsyFarmBriNum"><el-input v-model="form.chsyFarmBriNum" placeholder="请输入" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="量水设施数量(座)" prop="chsyMeaNum"><el-input v-model="form.chsyMeaNum" placeholder="请输入" /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="渠系排水泵站数量(座)" prop="chsyDitPustStNum"><el-input v-model="form.chsyDitPustStNum" 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 { listAttEngIrr, getAttEngIrr, addAttEngIrr, updateAttEngIrr, delAttEngIrr } from "@/api/slaj/eng"
const{proxy}=getCurrentInstance()
const { slaj_impo_grad, slaj_eng_stat, slaj_stat, slaj_if_rein_force, slaj_eng_scal_irr, slaj_chan_lev } = proxy.useDict("slaj_impo_grad","slaj_eng_stat","slaj_stat","slaj_if_rein_force","slaj_eng_scal_irr","slaj_chan_lev")
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},irrCode:{label:'灌区代码',visible:true},irrLoc:{label:'灌区位置',visible:true},engScal:{label:'工程规模',visible:true},totIrrArea:{label:'总灌溉面积(亩)',visible:true},effIrrArea:{label:'有效灌溉面积(亩)',visible:true},desIrrArea:{label:'设计灌溉面积(亩)',visible:true},chanHignLeve:{label:'渠道最高级别',visible:true},chanNum:{label:'渠道数量(条)',visible:true},chanLenTot:{label:'渠道总长度(m)',visible:true},chanDesFlow:{label:'渠道设计流量(m3/s)',visible:true},chsyGateNum:{label:'水闸数量(座)',visible:true},chsyAquNum:{label:'渡槽数量(座)',visible:true},chsyDropNum:{label:'跌水数量(座)',visible:true},chsyInvSiphNum:{label:'倒虹吸数量(座)',visible:true},chsyTunNum:{label:'隧洞数量(座)',visible:true},chsyCulNum:{label:'涵洞数量(座)',visible:true},chsyFarmBriNum:{label:'农桥数量(座)',visible:true},chsyMeaNum:{label:'量水设施数量(座)',visible:true},chsyDitPustStNum:{label:'渠系排水泵站数量(座)',visible:true},engStat:{label:'工程状态',visible:true},note:{label:'备注',visible:false}})
const data=reactive({form:{},queryParams:{pageNum:1,pageSize:10,engName:null,irrCode:null},rules:{}})
const{form,queryParams,rules}=toRefs(data)
function getList(){loading.value=true;listAttEngIrr(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 IRR_FIELDS=['engName','irrCode','irrLoc','cenLong','cenLat','impoGrad','apprBudg','engStat','stat','ifReinForce','engScal','totIrrArea','effIrrArea','desIrrArea','chanHignLeve','chanNum','chanLenTot','chanDesFlow','chsyGateNum','chsyAquNum','chsyDropNum','chsyInvSiphNum','chsyTunNum','chsyCulNum','chsyFarmBriNum','chsyMeaNum','chsyDitPustStNum','startDate','compDate','note']
function reset(){const f={};IRR_FIELDS.forEach(k=>f[k]=null);f.stat="1";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];getAttEngIrr(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?updateAttEngIrr:addAttEngIrr;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(()=>delAttEngIrr(g)).then(()=>{getList();proxy.$modal.msgSuccess("删除成功")})}
function handleExport(){proxy.download(`/eng/attr/irr/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>
