<template>
  <div class="app-container">
    <el-card shadow="never">
      <template #header>
        <div class="card-header">
          <el-space><el-button text @click="$router.back()">← 返回</el-button><span>WCO 泵站工程</span></el-space>
        </div>
      </template>
      <el-form :model="queryParams" :inline="true" size="small">
        <el-form-item label="泵站名称">
          <el-input v-model="queryParams.pustName" placeholder="请输入泵站名称" clearable @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="所在位置">
          <el-input v-model="queryParams.key" placeholder="请输入所在位置" clearable @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="泵站类型">
          <el-select v-model="queryParams.pustType" placeholder="请选择泵站类型" clearable @keyup.enter="handleQuery">
            <el-option label="排水泵站" value="1" /><el-option label="供水泵站" value="2" /><el-option label="供排结合泵站" value="3" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          <el-button type="info" icon="DataAnalysis" @click="handleStats">统计</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="list" stripe>
        <el-table-column prop="pustCode" label="编码" width="100" />
        <el-table-column prop="pustName" label="泵站名称" min-width="140" />
        <el-table-column prop="pustLoc" label="位置" width="140" />
        <el-table-column prop="pustType" label="类型" width="80">
          <template #default="s">{{ pustTypeMap[s.row.pustType] || s.row.pustType }}</template>
        </el-table-column>
        <el-table-column prop="insFlow" label="流量(m³/s)" width="110" />
        <el-table-column prop="engStat" label="状态" width="80">
          <template #default="s"><el-tag :type="s.row.engStat === '1' ? 'success' : 'warning'" size="small">{{ s.row.engStat === '1' ? '正常' : s.row.engStat === '0' ? '停用' : s.row.engStat }}</el-tag></template>
        </el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="s">
            <el-button type="primary" link icon="View" @click="handleDetail(s.row)">查看</el-button>
            <el-button type="danger" link icon="Delete" @click="handleDelete(s.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-card>

    <el-dialog :title="title" v-model="open" width="900px" append-to-body>
      <el-form :model="form" label-width="140px">
        <el-divider content-position="left">基本信息</el-divider>
        <el-row>
          <el-col :span="8"><el-form-item label="泵站名称"><el-input v-model="form.pustName" disabled /></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="泵站代码"><el-input v-model="form.pustCode" disabled /></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="泵站所在位置"><el-input v-model="form.pustLoc" disabled /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="8"><el-form-item label="泵站类型">
            <el-select v-model="form.pustType" disabled>
              <el-option label="排水泵站" value="1" /><el-option label="供水泵站" value="2" /><el-option label="供排结合泵站" value="3" />
            </el-select>
          </el-form-item></el-col>
          <el-col :span="8"><el-form-item label="工程等别">
            <el-select v-model="form.engGrad" disabled>
              <el-option label="Ⅰ" value="1" /><el-option label="Ⅱ" value="2" /><el-option label="Ⅲ" value="3" /><el-option label="Ⅳ" value="4" /><el-option label="Ⅴ" value="5" />
            </el-select>
          </el-form-item></el-col>
          <el-col :span="8"><el-form-item label="工程规模">
            <el-select v-model="form.engScal" disabled>
              <el-option label="大（1）型" value="1" /><el-option label="大（2）型" value="2" /><el-option label="中型" value="3" /><el-option label="小（1）型" value="4" /><el-option label="小（2）型" value="5" />
            </el-select>
          </el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="8"><el-form-item label="工程任务"><el-input v-model="form.engTask" disabled /></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="主要建筑物级别"><el-input v-model="form.mainBuildGrad" disabled /></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="设计扬程(m)"><el-input v-model="form.desHead" disabled /></el-form-item></el-col>
        </el-row>

        <el-divider content-position="left">经纬度信息</el-divider>
        <el-row>
          <el-col :span="8"><el-form-item label="泵站经度"><el-input v-model="form.pustLong" disabled /></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="泵站纬度"><el-input v-model="form.pustLat" disabled /></el-form-item></el-col>
        </el-row>

        <el-divider content-position="left">装机参数</el-divider>
        <el-row>
          <el-col :span="8"><el-form-item label="装机流量(m³/s)"><el-input v-model="form.insFlow" disabled /></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="装机功率(kW)"><el-input v-model="form.insPow" disabled /></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="水泵数量(台)"><el-input v-model="form.pumpNum" disabled /></el-form-item></el-col>
        </el-row>

        <el-divider content-position="left">建设与管理</el-divider>
        <el-row>
          <el-col :span="8"><el-form-item label="工程建设情况">
            <el-select v-model="form.engStat" disabled>
              <el-option label="未建" value="0" /><el-option label="在建" value="1" /><el-option label="已建" value="2" />
            </el-select>
          </el-form-item></el-col>
          <el-col :span="8"><el-form-item label="开工时间"><el-input v-model="form.startDate" disabled /></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="建成时间"><el-input v-model="form.compDate" disabled /></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="8"><el-form-item label="归口管理部门">
            <el-select v-model="form.admDep" disabled>
              <el-option label="水利部门" value="1" /><el-option label="电力部门" value="2" /><el-option label="农业部门" value="3" /><el-option label="林业部门" value="4" /><el-option label="城建部门" value="5" /><el-option label="航运部门" value="6" /><el-option label="环保部门" value="7" /><el-option label="其他部门" value="9" />
            </el-select>
          </el-form-item></el-col>
          <el-col :span="16"><el-form-item label="备注"><el-input v-model="form.note" disabled /></el-form-item></el-col>
        </el-row>
      </el-form>
      <template #footer><el-button @click="cancel">关 闭</el-button></template>
    </el-dialog>

    <el-dialog v-model="statsVisible" title="泵站类型分布统计" width="600px" append-to-body>
      <el-table :data="statsData" stripe v-loading="statsLoading">
        <el-table-column prop="name" label="类型" min-width="120" />
        <el-table-column prop="value" label="数量" width="100" />
      </el-table>
    </el-dialog>
  </div>
</template>

<script setup name="WcoPust">
import { getWcoPustList } from '@/api/slgc/wco/index'
import { getPust, delPust, getPustCountType } from '@/api/slgc/pust/index'
const { proxy } = getCurrentInstance()
const loading = ref(true); const total = ref(0); const open = ref(false); const title = ref('')
const list = ref([]); const form = ref({})
const queryParams = reactive({ pageNum: 1, pageSize: 10, pustName: undefined, key: undefined, pustType: undefined })
const pustTypeMap = { '1': '排水泵站', '2': '供水泵站', '3': '供排结合泵站' }
const statsVisible = ref(false); const statsLoading = ref(false); const statsData = ref([])
function getList() { loading.value = true; getWcoPustList(queryParams).then(res => { list.value = res.rows; total.value = res.total; loading.value = false }) }
function handleQuery() { queryParams.pageNum = 1; getList() }
function resetQuery() { queryParams.pustName = undefined; queryParams.key = undefined; queryParams.pustType = undefined; handleQuery() }
function handleDetail(row) { getPust(row.pustCode).then(res => { form.value = res.data; title.value = '详情'; open.value = true }) }
function handleDelete(row) { proxy.$modal.confirm('确认删除泵站"' + row.pustName + '"？').then(() => { delPust(row.pustCode).then(() => { proxy.$modal.msgSuccess('删除成功'); getList() }) }) }
function handleStats() { statsVisible.value = true; statsLoading.value = true; getPustCountType().then(res => { statsData.value = res.data || []; statsLoading.value = false }).catch(() => { statsLoading.value = false }) }
function cancel() { open.value = false }
onMounted(() => { getList() })
</script>
<style scoped>.card-header { font-weight: 600; font-size: 16px; }</style>
